Skip to content

Commit b10a38c

Browse files
committed
Make is_skip publicly available and use constant argument
1 parent d4300d0 commit b10a38c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/goto-programs/remove_skip.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Author: Daniel Kroening, [email protected]
1212
#include "remove_skip.h"
1313
#include "goto_model.h"
1414

15-
static bool is_skip(goto_programt::instructionst::iterator it)
15+
bool is_skip(const goto_programt &body, goto_programt::const_targett it)
1616
{
1717
// we won't remove labelled statements
1818
// (think about error labels or the like)
@@ -28,9 +28,12 @@ static bool is_skip(goto_programt::instructionst::iterator it)
2828
if(it->guard.is_false())
2929
return true;
3030

31-
goto_programt::instructionst::iterator next_it=it;
31+
goto_programt::const_targett next_it = it;
3232
next_it++;
3333

34+
if(next_it == body.instructions.end())
35+
return false;
36+
3437
// A branch to the next instruction is a skip
3538
// We also require the guard to be 'true'
3639
return it->guard.is_true() &&
@@ -92,7 +95,7 @@ void remove_skip(goto_programt &goto_program)
9295
// for collecting labels
9396
std::list<irep_idt> labels;
9497

95-
while(is_skip(it))
98+
while(is_skip(goto_program, it))
9699
{
97100
// don't remove the last skip statement,
98101
// it could be a target
@@ -144,9 +147,10 @@ void remove_skip(goto_programt &goto_program)
144147
// remove the last skip statement unless it's a target
145148
goto_program.compute_incoming_edges();
146149

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())
150154
goto_program.instructions.pop_back();
151155
}
152156
while(goto_program.instructions.size()<old_size);

src/goto-programs/remove_skip.h

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Daniel Kroening, [email protected]
1616

1717
class goto_modelt;
1818

19+
bool is_skip(const goto_programt &, goto_programt::const_targett);
1920
void remove_skip(goto_programt &);
2021
void remove_skip(goto_functionst &);
2122
void remove_skip(goto_modelt &);

0 commit comments

Comments
 (0)