Skip to content

Commit 972be89

Browse files
committed
remove_skip implementation restricted to a range of instructions
1 parent d203371 commit 972be89

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

src/goto-programs/remove_skip.cpp

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,14 @@ bool is_skip(const goto_programt &body, goto_programt::const_targett it)
6969
}
7070

7171
/// remove unnecessary skip statements
72-
void remove_skip(goto_programt &goto_program)
72+
/// \param goto_program goto program containing the instructions to be cleaned
73+
/// in the range [begin, end)
74+
/// \param begin iterator pointing to first instruction to be considered
75+
/// \param end iterator pointing beyond last instruction to be considered
76+
void remove_skip(
77+
goto_programt &goto_program,
78+
goto_programt::targett begin,
79+
goto_programt::targett end)
7380
{
7481
// This needs to be a fixed-point, as
7582
// removing a skip can turn a goto into a skip.
@@ -86,9 +93,7 @@ void remove_skip(goto_programt &goto_program)
8693

8794
// remove skip statements
8895

89-
for(goto_programt::instructionst::iterator
90-
it=goto_program.instructions.begin();
91-
it!=goto_program.instructions.end();)
96+
for(goto_programt::instructionst::iterator it = begin; it != end;)
9297
{
9398
goto_programt::targett old_target=it;
9499

@@ -99,7 +104,7 @@ void remove_skip(goto_programt &goto_program)
99104
{
100105
// don't remove the last skip statement,
101106
// it could be a target
102-
if(it==--goto_program.instructions.end())
107+
if(it == std::prev(end))
103108
break;
104109

105110
// save labels
@@ -123,7 +128,8 @@ void remove_skip(goto_programt &goto_program)
123128

124129
// adjust gotos
125130

126-
Forall_goto_program_instructions(i_it, goto_program)
131+
for(goto_programt::instructionst::iterator i_it = begin; it != end; ++i_it)
132+
{
127133
if(i_it->is_goto() || i_it->is_start_thread() || i_it->is_catch())
128134
{
129135
for(goto_programt::instructiont::targetst::iterator
@@ -138,6 +144,7 @@ void remove_skip(goto_programt &goto_program)
138144
*t_it=result->second;
139145
}
140146
}
147+
}
141148

142149
// now delete the skips -- we do so after adjusting the
143150
// gotos to avoid dangling targets
@@ -147,15 +154,26 @@ void remove_skip(goto_programt &goto_program)
147154
// remove the last skip statement unless it's a target
148155
goto_program.compute_incoming_edges();
149156

150-
if(
151-
!goto_program.instructions.empty() &&
152-
is_skip(goto_program, --goto_program.instructions.end()) &&
153-
!goto_program.instructions.back().is_target())
154-
goto_program.instructions.pop_back();
157+
if(!goto_program.instructions.empty())
158+
{
159+
goto_programt::targett last = std::prev(end);
160+
161+
if(is_skip(goto_program, last) && !last->is_target)
162+
goto_program.instructions.erase(last);
163+
}
155164
}
156165
while(goto_program.instructions.size()<old_size);
157166
}
158167

168+
/// remove unnecessary skip statements
169+
void remove_skip(goto_programt &goto_program)
170+
{
171+
remove_skip(
172+
goto_program,
173+
goto_program.instructions.begin(),
174+
goto_program.instructions.end());
175+
}
176+
159177
/// remove unnecessary skip statements
160178
void remove_skip(goto_functionst &goto_functions)
161179
{

src/goto-programs/remove_skip.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ void remove_skip(goto_programt &);
2121
void remove_skip(goto_functionst &);
2222
void remove_skip(goto_modelt &);
2323

24+
void remove_skip(
25+
goto_programt &goto_program,
26+
goto_programt::targett begin,
27+
goto_programt::targett end)
28+
2429
#endif // CPROVER_GOTO_PROGRAMS_REMOVE_SKIP_H

0 commit comments

Comments
 (0)