forked from diffblue/cbmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable remove_skip to soundly remove skips with labels
Also add documentation to what is_skip actually does.
- Loading branch information
1 parent
3f34c1a
commit 15ce938
Showing
2 changed files
with
26 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,22 @@ Author: Daniel Kroening, [email protected] | |
#include "remove_skip.h" | ||
#include "goto_model.h" | ||
|
||
bool is_skip(const goto_programt &body, goto_programt::const_targett it) | ||
/// Determine whether the instruction is semantically equivalent to a skip | ||
/// (no-op). This includes a skip, but also if(false) goto ..., goto next; | ||
/// next: ..., and (void)0. | ||
/// \param body goto program containing the instruction | ||
/// \param it instruction iterator that is tested for being a skip (or | ||
/// equivalent) | ||
/// \param ignore_labels If the caller takes care of moving labels, then even | ||
/// skip statements carrying labels can be treated as skips (even though they | ||
/// may carry key information such as error labels). | ||
/// \return True, iff it is equivalent to a skip. | ||
bool is_skip( | ||
const goto_programt &body, | ||
goto_programt::const_targett it, | ||
bool ignore_labels) | ||
{ | ||
// we won't remove labelled statements | ||
// (think about error labels or the like) | ||
|
||
if(!it->labels.empty()) | ||
if(!ignore_labels && !it->labels.empty()) | ||
return false; | ||
|
||
if(it->is_skip()) | ||
|
@@ -100,12 +110,17 @@ void remove_skip( | |
// for collecting labels | ||
std::list<irep_idt> labels; | ||
|
||
while(is_skip(goto_program, it)) | ||
while(is_skip(goto_program, it, true)) | ||
{ | ||
// don't remove the last skip statement, | ||
// it could be a target | ||
if(it == std::prev(end)) | ||
if( | ||
it == std::prev(end) || | ||
(std::next(it)->is_end_function() && | ||
(!labels.empty() || !it->labels.empty()))) | ||
{ | ||
break; | ||
} | ||
|
||
// save labels | ||
labels.splice(labels.end(), it->labels); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,10 @@ Author: Daniel Kroening, [email protected] | |
class goto_functionst; | ||
class goto_modelt; | ||
|
||
bool is_skip(const goto_programt &, goto_programt::const_targett); | ||
bool is_skip( | ||
const goto_programt &, | ||
goto_programt::const_targett, | ||
bool ignore_labels = false); | ||
void remove_skip(goto_programt &); | ||
void remove_skip(goto_functionst &); | ||
void remove_skip(goto_modelt &); | ||
|