Skip to content

Commit 38b4c48

Browse files
committed
dump-c: respect local translation bounds in resolving switch/case
1 parent a9dca20 commit 38b4c48

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/goto-instrument/goto_program2code.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ goto_programt::const_targett goto_program2codet::convert_goto(
565565
else if(!target->guard.is_true())
566566
return convert_goto_switch(target, upper_bound, dest);
567567
else if(!loop_last_stack.empty())
568-
return convert_goto_break_continue(target, dest);
568+
return convert_goto_break_continue(target, upper_bound, dest);
569569
else
570570
return convert_goto_goto(target, dest);
571571
}
@@ -803,7 +803,14 @@ bool goto_program2codet::set_block_end_points(
803803

804804
// ignore dead instructions for the following checks
805805
if(n.dominators.empty())
806+
{
807+
// simplification may have figured out that a case is unreachable
808+
// this is possibly getting too weird, abort to be safe
809+
if(case_end==it->case_start)
810+
return true;
811+
806812
continue;
813+
}
807814

808815
// find the last instruction dominated by the case start
809816
if(n.dominators.find(it->case_start)==n.dominators.end())
@@ -1107,7 +1114,7 @@ goto_programt::const_targett goto_program2codet::convert_goto_if(
11071114
upper_bound->location_number < end_if->location_number))
11081115
{
11091116
if(!loop_last_stack.empty())
1110-
return convert_goto_break_continue(target, dest);
1117+
return convert_goto_break_continue(target, upper_bound, dest);
11111118
else
11121119
return convert_goto_goto(target, dest);
11131120
}
@@ -1140,6 +1147,7 @@ goto_programt::const_targett goto_program2codet::convert_goto_if(
11401147

11411148
goto_programt::const_targett goto_program2codet::convert_goto_break_continue(
11421149
goto_programt::const_targett target,
1150+
goto_programt::const_targett upper_bound,
11431151
codet &dest)
11441152
{
11451153
assert(!loop_last_stack.empty());
@@ -1149,7 +1157,7 @@ goto_programt::const_targett goto_program2codet::convert_goto_break_continue(
11491157
// 1: ...
11501158
goto_programt::const_targett next=target;
11511159
for(++next;
1152-
next!=goto_program.instructions.end();
1160+
next!=upper_bound && next!=goto_program.instructions.end();
11531161
++next)
11541162
{
11551163
cfg_dominatorst::cfgt::entry_mapt::const_iterator i_entry=

src/goto-instrument/goto_program2code.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ class goto_program2codet
199199

200200
goto_programt::const_targett convert_goto_break_continue(
201201
goto_programt::const_targett target,
202+
goto_programt::const_targett upper_bound,
202203
codet &dest);
203204

204205
goto_programt::const_targett convert_goto_goto(

0 commit comments

Comments
 (0)