Skip to content

Commit fdc3a09

Browse files
committed
Avoid the use of is_backwards_goto while unwinding
The method may in some cases (e.g. ite4 termination regression test) cause a segfault for unknown reasons. Flip the condition, check using incoming edges if an instruction is loop head rather than checking if a goto is loop exit. Signed-off-by: František Nečas <[email protected]>
1 parent 9b3eea0 commit fdc3a09

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/2ls/preprocessing_util.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,22 @@ bool twols_parse_optionst::unwind_goto_into_loop(
114114
loopst loops;
115115
Forall_goto_program_instructions(i_it, body)
116116
{
117-
if(i_it->is_backwards_goto())
117+
bool is_loop_head=false;
118+
goto_programt::targett loop_exit;
119+
for(auto edge : i_it->incoming_edges)
120+
{
121+
if(edge->location_number>i_it->location_number)
122+
{
123+
is_loop_head=true;
124+
loop_exit=edge;
125+
}
126+
}
127+
128+
if(is_loop_head)
118129
{
119-
goto_programt::targett loop_head=i_it->get_target();
120-
goto_programt::targett loop_exit=i_it;
121130
bool has_goto_into_loop=false;
122131

123-
goto_programt::targett it=loop_head;
132+
goto_programt::targett it=i_it;
124133
if(it!=loop_exit)
125134
it++;
126135
for(; it!=loop_exit; it++)
@@ -130,7 +139,7 @@ bool twols_parse_optionst::unwind_goto_into_loop(
130139
s_it!=it->incoming_edges.end(); ++s_it)
131140
{
132141
if((*s_it)->is_goto() &&
133-
(*s_it)->location_number<loop_head->location_number)
142+
(*s_it)->location_number<i_it->location_number)
134143
{
135144
has_goto_into_loop=true;
136145
result=true;
@@ -143,7 +152,7 @@ bool twols_parse_optionst::unwind_goto_into_loop(
143152
if(has_goto_into_loop)
144153
{
145154
status() << "Unwinding jump into loop" << eom;
146-
loops.push_back(loopst::value_type(++loop_exit, loop_head));
155+
loops.push_back(loopst::value_type(++loop_exit, i_it));
147156
}
148157
}
149158
}

0 commit comments

Comments
 (0)