Skip to content

Fix adjustment of goto targets in the loop unwinder #511

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 1 commit into from
Feb 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions regression/goto-instrument/unwind-zero-unwind3/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

int main()
{
do {

} while (0);

return 0;
}
9 changes: 9 additions & 0 deletions regression/goto-instrument/unwind-zero-unwind3/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
--unwind 0
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
ASSUME FALSE
^warning: ignoring
29 changes: 26 additions & 3 deletions src/goto-instrument/unwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Author: Daniel Kroening, [email protected]

\*******************************************************************/

//#define DEBUG

#ifdef DEBUG
#include <iostream>
#endif

#include <util/std_expr.h>
#include <util/string_utils.h>
#include <goto-programs/goto_functions.h>
Expand Down Expand Up @@ -312,7 +318,7 @@ void goto_unwindt::unwind(

goto_programt::const_targett t=i_it->get_target();

if(t->location_number>=loop_head->location_number ||
if(t->location_number>=loop_head->location_number &&
t->location_number<loop_exit->location_number)
{
i_it->set_target(t_skip);
Expand Down Expand Up @@ -385,10 +391,21 @@ void goto_unwindt::unwind(
{
assert(k>=-1);

forall_goto_program_instructions(i_it, goto_program)
for(goto_programt::const_targett i_it=goto_program.instructions.begin();
i_it!=goto_program.instructions.end();)
{
#ifdef DEBUG
symbol_tablet st;
namespacet ns(st);
std::cout << "Instruction:\n";
goto_program.output_instruction(ns, "", std::cout, i_it);
#endif

if(!i_it->is_backwards_goto())
{
i_it++;
continue;
}

const irep_idt func=i_it->function;
assert(!func.empty());
Expand All @@ -398,7 +415,10 @@ void goto_unwindt::unwind(
int final_k=get_k(func, loop_number, k, unwind_set);

if(final_k==-1)
{
i_it++;
continue;
}

goto_programt::const_targett loop_head=i_it->get_target();
goto_programt::const_targett loop_exit=i_it;
Expand All @@ -409,7 +429,6 @@ void goto_unwindt::unwind(

// necessary as we change the goto program in the previous line
i_it=loop_exit;
i_it--; // as for loop first increments
}
}

Expand Down Expand Up @@ -440,6 +459,10 @@ void goto_unwindt::operator()(
if(!goto_function.body_available())
continue;

#ifdef DEBUG
std::cout << "Function: " << it->first << std::endl;
#endif

goto_programt &goto_program=goto_function.body;

unwind(goto_program, unwind_set, k, unwind_strategy);
Expand Down