Skip to content

Commit a8385a6

Browse files
committed
[refactor, WIP] Added more docs for code.
1 parent d1f46c3 commit a8385a6

12 files changed

Lines changed: 50 additions & 17 deletions

File tree

lib/Core/CodeEvent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ class CodeEvent {
5252

5353
} // namespace klee
5454

55-
#endif
55+
#endif // KLEE_CODE_EVENT_H

lib/Core/CodeEvents/AllocEvent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ struct AllocEvent : public CodeEvent {
4040

4141
} // namespace klee
4242

43-
#endif
43+
#endif // KLEE_ALLOC_EVENT_H

lib/Core/CodeEvents/BrEvent.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace klee {
1010

1111
class BrEvent : public CodeEvent {
1212
private:
13+
/// @brief Described chosen branch event: `true` if
14+
/// `then`-branch was chosen and `false` otherwise.
1315
bool chosenBranch = true;
1416

1517
public:
@@ -40,4 +42,4 @@ class BrEvent : public CodeEvent {
4042

4143
} // namespace klee
4244

43-
#endif
45+
#endif // KLEE_BR_EVENT_H

lib/Core/CodeEvents/CallEvent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ class CallEvent : public CodeEvent {
3535

3636
} // namespace klee
3737

38-
#endif
38+
#endif // KLEE_CALL_EVENT_H

lib/Core/CodeEvents/ErrorEvent.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ namespace klee {
1111

1212
struct ErrorEvent : public CodeEvent {
1313
public:
14+
/// @brief ID for this error.
1415
const StateTerminationType ruleID;
16+
17+
/// @brief Message describing this error.
1518
const std::string message;
1619

20+
/// @brief Event associated with this error
21+
/// which may be treated as a "source" of error
22+
/// (e.g. memory allocation for Out-Of-Bounds error).
1723
const std::optional<ref<CodeEvent>> source;
1824

1925
ErrorEvent(const ref<CodeEvent> &source, const ref<CodeLocation> &sink,
@@ -35,4 +41,4 @@ struct ErrorEvent : public CodeEvent {
3541

3642
} // namespace klee
3743

38-
#endif
44+
#endif // KLEE_ERROR_EVENT_H

lib/Core/CodeEvents/ReturnEvent.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace klee {
1111

1212
class ReturnEvent : public CodeEvent {
1313
private:
14+
/// @brief Function to which control flow returns.
1415
const KFunction *const caller;
1516

1617
public:
@@ -30,4 +31,4 @@ class ReturnEvent : public CodeEvent {
3031

3132
} // namespace klee
3233

33-
#endif
34+
#endif // KLEE_RETURN_EVENT_H

lib/Core/CodeLocation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ struct CodeLocation {
7373

7474
}; // namespace klee
7575

76-
#endif
76+
#endif // KLEE_CODE_LOCATION_H

lib/Core/EventRecorder.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "klee/Module/SarifReport.h"
88

99
#include <cassert>
10+
#include <optional>
1011
#include <utility>
1112

1213
using namespace klee;
@@ -59,12 +60,12 @@ EventRecorder EventRecorder::inRange(const Path::PathIndex &begin,
5960
return result;
6061
}
6162

62-
// TODO: not effective.
63-
/// FIXME:
6463
for (const auto &event : events) {
6564
const Path::PathIndex &eventPathIndex = event->location->pathIndex;
66-
if (!Path::PathIndexCompare{}(eventPathIndex, begin) &&
67-
!Path::PathIndexCompare{}(end, eventPathIndex)) {
65+
if (!Path::PathIndexCompare{}(eventPathIndex, begin)) {
66+
if (Path::PathIndexCompare{}(end, eventPathIndex)) {
67+
break;
68+
}
6869
result.record(event);
6970
}
7071
}

lib/Core/EventRecorder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class EventRecorder {
2525
~EventRecorder() = default;
2626

2727
/// @brief Remembers event.
28-
/// @param event event to record.
28+
/// @param event Event to record.
2929
void record(const ref<CodeEvent> &event);
3030

3131
/// @brief Appends all events from the given `EventRecorder`

lib/Module/Passes.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,38 @@ class ReturnSplitter : public llvm::FunctionPass {
221221
bool runOnFunction(llvm::Function &F) override;
222222
};
223223

224-
/// @brief
225-
/// FIXME: finish docs.
224+
/// @brief Pass able to find the actual location of
225+
/// `return` statements in source code.
226+
///
227+
/// @details For function with multiple `return` statements
228+
/// clang compiler generates LLVM IR with exactly one `ret`
229+
/// instruction. `return` statements transform to the:
230+
/// ```
231+
/// ret_reg = val
232+
/// br ret_block
233+
/// ...
234+
/// ret_block:
235+
/// ret_val = load ret_reg
236+
/// ret ret_val
237+
/// ```
238+
/// This pass finds such constructions and marks
239+
/// `br ret_block` with `md_ret` metadata.
226240
class ReturnLocationFinderPass : public llvm::FunctionPass {
227241
public:
228242
static char ID;
229243
ReturnLocationFinderPass() : llvm::FunctionPass(ID) {}
230244
bool runOnFunction(llvm::Function &) override;
231245
};
232246

247+
/// @brief Pass able to find line in source code with
248+
/// declaration of local variable.
249+
///
250+
/// @details "Construction" of local variable in LLVM IR
251+
/// is represented as allocation of memory in the beginning
252+
/// of each function and subsequent call of `llvm.dbg.declare`
253+
/// function on allocated memory. This pass moves `!dbg` infos
254+
/// from calls to mentioned functions to the corresponding `alloca`
255+
/// instructions.
233256
class LocalVarDeclarationFinderPass : public llvm::FunctionPass {
234257
public:
235258
static char ID;

0 commit comments

Comments
 (0)