12
12
#include " remove_skip.h"
13
13
#include " goto_model.h"
14
14
15
- static bool is_skip (goto_programt::instructionst::iterator it)
15
+ bool is_skip (const goto_programt &body, goto_programt::const_targett it)
16
16
{
17
17
// we won't remove labelled statements
18
18
// (think about error labels or the like)
@@ -28,9 +28,12 @@ static bool is_skip(goto_programt::instructionst::iterator it)
28
28
if (it->guard .is_false ())
29
29
return true ;
30
30
31
- goto_programt::instructionst::iterator next_it= it;
31
+ goto_programt::const_targett next_it = it;
32
32
next_it++;
33
33
34
+ if (next_it == body.instructions .end ())
35
+ return false ;
36
+
34
37
// A branch to the next instruction is a skip
35
38
// We also require the guard to be 'true'
36
39
return it->guard .is_true () &&
@@ -92,7 +95,7 @@ void remove_skip(goto_programt &goto_program)
92
95
// for collecting labels
93
96
std::list<irep_idt> labels;
94
97
95
- while (is_skip (it))
98
+ while (is_skip (goto_program, it))
96
99
{
97
100
// don't remove the last skip statement,
98
101
// it could be a target
@@ -144,9 +147,10 @@ void remove_skip(goto_programt &goto_program)
144
147
// remove the last skip statement unless it's a target
145
148
goto_program.compute_incoming_edges ();
146
149
147
- if (!goto_program.instructions .empty () &&
148
- is_skip (--goto_program.instructions .end ()) &&
149
- !goto_program.instructions .back ().is_target ())
150
+ if (
151
+ !goto_program.instructions .empty () &&
152
+ is_skip (goto_program, --goto_program.instructions .end ()) &&
153
+ !goto_program.instructions .back ().is_target ())
150
154
goto_program.instructions .pop_back ();
151
155
}
152
156
while (goto_program.instructions .size ()<old_size);
0 commit comments