Skip to content

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

Merged
merged 2 commits into from
Dec 6, 2016

Conversation

danpoe
Copy link
Contributor

@danpoe danpoe commented Sep 27, 2016

Loop unwinding with:

  • partial loops, assume, assert, rest loops
  • unwindsets

@kroening kroening self-assigned this Sep 27, 2016
@danpoe danpoe force-pushed the goto-instrument-loop-unwinding branch from 5d3eea2 to 7612db8 Compare September 28, 2016 17:43
@danpoe
Copy link
Contributor Author

danpoe commented Sep 28, 2016

The Linux builds now also work with a new travis.yml file that provides a more recent version of libstdc++.

@kroening
Copy link
Member

May I ask for some reasonable squashing of commits, please?

@danpoe danpoe force-pushed the goto-instrument-loop-unwinding branch from 7612db8 to d948765 Compare October 31, 2016 10:54
@danpoe
Copy link
Contributor Author

danpoe commented Oct 31, 2016

Ok, done.


split_string(s, delim, result, strip);
if(result.size()!=2)
throw std::invalid_argument("number of parts != 2");
Copy link
Collaborator

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"
Copy link
Collaborator

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>"
Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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
Copy link
Collaborator

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)
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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());
Copy link
Collaborator

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);
Copy link
Collaborator

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());
}

Copy link
Collaborator

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

@danpoe danpoe force-pushed the goto-instrument-loop-unwinding branch from d7b0f33 to 39dd631 Compare November 17, 2016 16:39
@tautschnig
Copy link
Collaborator

tautschnig commented Nov 25, 2016 via email

@danpoe danpoe force-pushed the goto-instrument-loop-unwinding branch from dba29d6 to f13cff5 Compare November 26, 2016 20:42
@danpoe
Copy link
Contributor Author

danpoe commented Nov 26, 2016

Ok, I think I've addressed everything.

Copy link
Collaborator

@tautschnig tautschnig left a 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
Copy link
Collaborator

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.

Copy link
Contributor Author

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"));
Copy link
Collaborator

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?

Copy link
Contributor Author

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:
Copy link
Collaborator

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.)

Copy link
Contributor Author

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for clarifying!

@danpoe danpoe force-pushed the goto-instrument-loop-unwinding branch from f13cff5 to c8c7c29 Compare December 1, 2016 15:31
@tautschnig
Copy link
Collaborator

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
Copy link
Member

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--)
{
Copy link
Member

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?

Copy link
Contributor Author

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);
Copy link
Member

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.

@danpoe danpoe force-pushed the goto-instrument-loop-unwinding branch from c8c7c29 to 1157ad3 Compare December 2, 2016 12:11
@danpoe
Copy link
Contributor Author

danpoe commented Dec 2, 2016

This is now rebased and I've addressed the additional comments.

@kroening kroening merged commit a9ba37f into diffblue:master Dec 6, 2016
@danpoe danpoe deleted the goto-instrument-loop-unwinding branch January 17, 2017 17:47
peterschrammel added a commit that referenced this pull request May 10, 2017
smowton added a commit to smowton/cbmc that referenced this pull request May 9, 2018
SEC-41 : Integration of the 'full-slicer' into the pipe-line (tools-chain).
chrisr-diffblue added a commit to chrisr-diffblue/cbmc that referenced this pull request Aug 24, 2018
…s-with-sharing-merge

Fix reaching definitions with sharing merge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants