-
Notifications
You must be signed in to change notification settings - Fork 276
Trace loop heads #5381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trace loop heads #5381
Changes from all commits
38fd003
65c8fe2
4ee5f2d
20f964f
a8c5f57
657c1a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
CORE | ||
test.c | ||
--unwind 6 test.c --trace --json-ui --partial-loops --slice-formula | ||
activate-multi-line-match | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
\s*\{\n\s* .*\n\s* "sourceLocation": \{\n\s* .*,\n\s* .*,\n\s* "line": "5",\n\s* .*\n\s* \},\n\s* "stepType": "loop-head",\n\s* .*\n\s*\},\n\s*\{\n\s* .*\n\s* "sourceLocation": \{\n\s* .*,\n\s* .*,\n\s* "line": "5",\n\s* .*\n\s* \},\n\s* "stepType": "loop-head",\n\s* .*\n\s*\}, | ||
-- | ||
-- | ||
Ensure even with sliced formulas, we get a location only step for | ||
each iteration of the loop (called loop-heads) when using partial loops. | ||
|
||
This test is checking the following json:(deleting the new lines after each \n to obtain | ||
monster regex above). | ||
|
||
\s*\{\n | ||
\s* .*\n | ||
\s* "sourceLocation": \{\n | ||
\s* .*,\n | ||
\s* .*,\n | ||
\s* "line": "5",\n | ||
\s* .*\n | ||
\s* \},\n | ||
\s* "stepType": "loop-head",\n | ||
\s* .*\n | ||
\s*\},\n | ||
\s*\{\n | ||
\s* .*\n | ||
\s* "sourceLocation": \{\n | ||
\s* .*,\n | ||
\s* .*,\n | ||
\s* "line": "5",\n | ||
\s* .*\n | ||
\s* \},\n | ||
\s* "stepType": "loop-head",\n | ||
\s* .*\n | ||
\s*\}, |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
CORE | ||
test.c | ||
--unwind 6 test.c --trace --xml-ui --partial-loops --slice-formula | ||
activate-multi-line-match | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
\s*<loop-head .*>\n\s* <location .* line="5" .*/>\n\s*</loop-head>\n\s*<loop-head .*>\n\s* <location .* line="5".*/>\n\s*</loop-head>\n | ||
-- | ||
-- | ||
Ensure even with sliced formulas, we get a location only step for | ||
each iteration of the loop (called loop-heads) when using partial loops. | ||
|
||
This test is checking the following XML:(deleting the new lines | ||
after each \n to obtain the monster regex above). | ||
|
||
\s*<loop-head .*> | ||
\s* <location .* line="5" .*/> | ||
\s*</loop-head> | ||
\s*<loop-head .*> | ||
\s* <location .* line="5".*/> | ||
\s*</loop-head> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
void main(void) | ||
{ | ||
int i = 0; | ||
|
||
while(1) | ||
{ | ||
i = 1; | ||
} | ||
|
||
// invalid assertion | ||
assert(i == 0); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/*******************************************************************\ | ||
|
||
Author: Diffblue | ||
|
||
\*******************************************************************/ | ||
|
||
/// \file | ||
/// Utilities for printing location info steps in the trace in a format | ||
/// agnostic way | ||
|
||
#include "structured_trace_util.h" | ||
#include <algorithm> | ||
|
||
default_step_kindt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛏️ some new lines would be appreciated. |
||
default_step_kind(const goto_programt::instructiont &instruction) | ||
{ | ||
const bool is_loophead = std::any_of( | ||
instruction.incoming_edges.begin(), | ||
instruction.incoming_edges.end(), | ||
[](goto_programt::targett t) { return t->is_backwards_goto(); }); | ||
|
||
return is_loophead ? default_step_kindt::LOOP_HEAD | ||
: default_step_kindt::LOCATION_ONLY; | ||
} | ||
std::string default_step_name(const default_step_kindt &step_type) | ||
{ | ||
switch(step_type) | ||
{ | ||
case default_step_kindt::LOCATION_ONLY: | ||
return "location-only"; | ||
case default_step_kindt::LOOP_HEAD: | ||
return "loop-head"; | ||
} | ||
UNREACHABLE; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/*******************************************************************\ | ||
|
||
Author: Diffblue | ||
|
||
\*******************************************************************/ | ||
|
||
/// \file | ||
/// Utilities for printing location info steps in the trace in a format | ||
/// agnostic way | ||
|
||
#ifndef CPROVER_GOTO_PROGRAMS_STRUCTURED_TRACE_UTIL_H | ||
#define CPROVER_GOTO_PROGRAMS_STRUCTURED_TRACE_UTIL_H | ||
|
||
#include "goto_program.h" | ||
#include <string> | ||
|
||
/// There are two kinds of step for location markers - location-only and | ||
/// loop-head (for locations associated with the first step of a loop). | ||
enum class default_step_kindt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why "default"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nomenclature taken from the docs which call these default steps 🤷 |
||
{ | ||
LOCATION_ONLY, | ||
LOOP_HEAD | ||
}; | ||
|
||
/// Identify for a given instruction whether it is a loophead or just a location | ||
/// | ||
/// Loopheads are determined by whether there is backwards jump to them. This | ||
/// matches the loop detection used for loop IDs | ||
/// \param instruction: The instruction to inspect. | ||
/// \return LOOP_HEAD if this is a loop head, otherwise LOCATION_ONLY | ||
default_step_kindt | ||
default_step_kind(const goto_programt::instructiont &instruction); | ||
|
||
/// Turns a \ref default_step_kindt into a string that can be used in the trace | ||
/// \param step_type: The kind of step, deduced from \ref default_step_kind | ||
/// \return Either "loop-head" or "location-only" | ||
std::string default_step_name(const default_step_kindt &step_type); | ||
|
||
#endif // CPROVER_GOTO_PROGRAMS_STRUCTURED_TRACE_UTIL_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)