-
Notifications
You must be signed in to change notification settings - Fork 273
Goto instrument loop unwinding #241
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
Goto instrument loop unwinding #241
Conversation
5d3eea2
to
7612db8
Compare
The Linux builds now also work with a new travis.yml file that provides a more recent version of libstdc++. |
May I ask for some reasonable squashing of commits, please? |
7612db8
to
d948765
Compare
Ok, done. |
|
||
split_string(s, delim, result, strip); | ||
if(result.size()!=2) | ||
throw std::invalid_argument("number of parts != 2"); |
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.
As in other places just strings are thrown (and then also caught) I would suggest to use
throw "split string did not generate exactly 2 parts";
(and drop #include <stdexcept>
)
@@ -0,0 +1,7 @@ | |||
CORE | |||
main.c | |||
"--unwind 10 --unwinding-assertions" |
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.
I was surprised to see the quotes, see below for a suggestion on how to get rid of them.
@@ -6,22 +6,18 @@ goto_instrument=$src/goto-instrument/goto-instrument | |||
cbmc=$src/cbmc/cbmc | |||
|
|||
function usage() { | |||
echo "Usage: chain unwind-num test_file.c" | |||
echo "Usage: chain <options> <testfile>" |
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.
If the testfile were required to be the first (instead of the last) argument then the code could be simplified and all the quotes would become unnecessary. More below.
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.
Doesn't test.pl always pass the testfile as the last argument?
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.
So maybe test.pl should be tweaked to simplify such scripts? Else there could be a brief options parser in this code to extract the last argument from $@.
echo $unwind_num | ||
echo $name | ||
else | ||
if [ $# -ne 2 ]; then |
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.
Use [ -z $# ] if moving the file argument into the first position and add || [ ! -s $1 ] to ensure it's a valid file(name).
fi | ||
|
||
name=$(echo $2 | cut -d. -f1) |
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.
To address both the argument swapping and add support for path names containing "." use:
name=$(echo $1 | sed 's/\.[^\.]*$//')
shift
{ | ||
std::vector<goto_programt::targett> exit_points; | ||
unwind(goto_program, loop_head, loop_exit, k, exit_points); | ||
assert(k>=0); |
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.
k is unsigned, this is trivially true.
assert(k!=0); | ||
|
||
iteration_points.resize(k); | ||
assert(k>=0); |
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.
k is unsigned
// not needed if there is an unconditional goto before loop_exit. | ||
// rest program after unwound part | ||
goto_programt rest_program; | ||
assert(rest_program.instructions.empty()); |
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.
That's a fresh goto_programt, should be trivially true?!
} | ||
else | ||
{ | ||
assert(k==0); |
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.
If I read the code correctly, this is the else case of k!=0 - should be trivially true.
{ | ||
return instructions.insert(target, instructiont()); | ||
} | ||
|
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.
Nit: just one blank line
d7b0f33
to
39dd631
Compare
danpoe commented on this pull request.
> @@ -1324,6 +1360,10 @@ void goto_instrument_parse_optionst::help()
"Semantic transformations:\n"
" --nondet-volatile makes reads from volatile variables non-deterministic\n"
" --unwind <n> unwinds the loops <n> times\n"
+ " --unwindset L:B,... unwind loop L with a bound of B\n"
+ " --partial-loops permit paths with partial loops\n"
+ " --unwinding-assertions generate unwinding assertions\n"
+ " --rest-loops add loop for remaining iterations after unwound part\n"
How about "--continuation-loops"? It's not perfect either but at least gives some idea about what it does.
I do like this suggestion if it weren't for "continuation" to have a
well-defined meaning in programming languages already. Maybe
"--continue-as-loops" ?
Best,
Michael
|
dba29d6
to
f13cff5
Compare
Ok, I think I've addressed everything. |
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.
I've added some nice-to-have notes.
|
||
\*******************************************************************/ | ||
|
||
// unit tests |
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.
I would suggest to place this in the unit/ top-level folder.
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.
Ok, I've added this to the unit tests folder.
goto_functions.update(); | ||
goto_functions.compute_loop_numbers(); | ||
if(unwind) | ||
k=stoi(cmdline.get_value("unwind")); |
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.
I'm a bit surprised this works without std::, but it has done before. Maybe use safe_string2int so that we can later put in std::stoi across the codebase?
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.
I've changed this to safe_string2int().
@@ -1,22 +1,43 @@ | |||
language: cpp | |||
|
|||
os: |
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.
Did you intentionally add .travis.yml changes to this pull request? (I am in favour of those changes, just asking.)
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.
I'm using some new versions of methods of, e.g., std::set that were added in C++11. This didn't compile with the old travis file as the STL version it used for the Linux builds was too old.
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.
Ok, thanks for clarifying!
f13cff5
to
c8c7c29
Compare
Unless anyone else voices concerns, it should just be a rebase that's blocking a merge. |
return ""; | ||
|
||
// find last non-space char | ||
long j; // need signed type here |
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.
should that be ssize_t?
// find last non-space char | ||
long j; // need signed type here | ||
for(j=n-1; j>=0; j--) | ||
{ |
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.
Or use some reverse iterator?
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.
I've used a reverse iterator for this now.
{ | ||
std::string us; | ||
std::string fn=cmdline.get_value("unwindset-file"); | ||
std::ifstream file(fn); |
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.
This unfortunately needs to include widen() on WIN32, or Unicode filenames won't work.
c8c7c29
to
1157ad3
Compare
This is now rebased and I've addressed the additional comments. |
Fix issue #241 - Conversion from int
SEC-41 : Integration of the 'full-slicer' into the pipe-line (tools-chain).
…s-with-sharing-merge Fix reaching definitions with sharing merge
Loop unwinding with: