@@ -69,7 +69,14 @@ bool is_skip(const goto_programt &body, goto_programt::const_targett it)
69
69
}
70
70
71
71
// / 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)
73
80
{
74
81
// This needs to be a fixed-point, as
75
82
// removing a skip can turn a goto into a skip.
@@ -86,9 +93,7 @@ void remove_skip(goto_programt &goto_program)
86
93
87
94
// remove skip statements
88
95
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;)
92
97
{
93
98
goto_programt::targett old_target=it;
94
99
@@ -99,7 +104,7 @@ void remove_skip(goto_programt &goto_program)
99
104
{
100
105
// don't remove the last skip statement,
101
106
// it could be a target
102
- if (it==--goto_program. instructions . end ( ))
107
+ if (it == std::prev (end ))
103
108
break ;
104
109
105
110
// save labels
@@ -121,41 +126,54 @@ void remove_skip(goto_programt &goto_program)
121
126
it++;
122
127
}
123
128
124
- // adjust gotos
125
-
126
- Forall_goto_program_instructions (i_it, goto_program)
127
- if (i_it-> is_goto () || i_it-> is_start_thread () || i_it-> is_catch ())
129
+ // adjust gotos across the full goto program body
130
+ for ( auto &ins : goto_program. instructions )
131
+ {
132
+ if (ins. is_goto () || ins. is_start_thread () || ins. is_catch ())
128
133
{
129
- for (goto_programt::instructiont::targetst::iterator
130
- t_it=i_it->targets .begin ();
131
- t_it!=i_it->targets .end ();
132
- t_it++)
134
+ for (auto &target : ins.targets )
133
135
{
134
- new_targetst::const_iterator
135
- result=new_targets.find (*t_it);
136
+ new_targetst::const_iterator result = new_targets.find (target);
136
137
137
138
if (result!=new_targets.end ())
138
- *t_it= result->second ;
139
+ target = result->second ;
139
140
}
140
141
}
142
+ }
143
+
144
+ while (new_targets.find (begin) != new_targets.end ())
145
+ ++begin;
141
146
142
147
// now delete the skips -- we do so after adjusting the
143
148
// gotos to avoid dangling targets
144
149
for (const auto &new_target : new_targets)
145
150
goto_program.instructions .erase (new_target.first );
146
151
147
152
// remove the last skip statement unless it's a target
148
- goto_program.compute_incoming_edges ();
153
+ goto_program.compute_target_numbers ();
154
+
155
+ if (begin != end)
156
+ {
157
+ goto_programt::targett last = std::prev (end);
158
+ if (begin == last)
159
+ ++begin;
149
160
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 ();
161
+ if (is_skip (goto_program, last) && !last->is_target ())
162
+ goto_program.instructions .erase (last);
163
+ }
155
164
}
156
165
while (goto_program.instructions .size ()<old_size);
157
166
}
158
167
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
+
159
177
// / remove unnecessary skip statements
160
178
void remove_skip (goto_functionst &goto_functions)
161
179
{
0 commit comments