Skip to content

Commit 964d30b

Browse files
author
martin
committed
Add utility function for remove_unreachable.
1 parent 1b22097 commit 964d30b

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

src/goto-analyzer/goto_analyzer_parse_options.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ void goto_analyzer_parse_optionst::get_command_line_options(optionst &options)
233233
options.set_option("show", true);
234234
}
235235

236+
// For development allow slicing to be disabled in the simplify task
237+
options.set_option("simplify-slicing", !(cmdline.isset("no-simplify-slicing")));
236238

237239
// Abstract interpreter choice
238240
options.set_option("flow-sensitive", false);

src/goto-analyzer/goto_analyzer_parse_options.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ class optionst;
3939
"(non-null)(show-non-null)" \
4040
"(constants)" \
4141
"(dependence-graph)" \
42-
"(show)(verify)(simplify):" \
43-
"(flow-sensitive)(concurrent)"
42+
"(show)(verify)(simplify):" \
43+
"(flow-sensitive)(concurrent)" \
44+
"(no-simplify-slicing)"
4445

4546
class goto_analyzer_parse_optionst:
4647
public parse_options_baset,

src/goto-analyzer/static_simplifier.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Author: Lucas Cordeiro, [email protected]
1919
#include <analyses/interval_domain.h>
2020
#include <analyses/constant_propagator.h>
2121

22+
#include <goto-programs/remove_skip.h>
23+
#include <goto-programs/remove_unreachable.h>
24+
2225
#include "static_simplifier.h"
2326

2427
template<class analyzerT>
@@ -74,6 +77,21 @@ bool static_simplifiert<analyzerT>::operator()(void)
7477
status() << "Simplifying program" << eom;
7578
simplify_program();
7679

80+
// Remove obviously unreachable things and (now) unconditional branches
81+
if (options.get_bool_option("simplify-slicing"))
82+
{
83+
status() << "Removing unreachable instructions" << eom;
84+
85+
remove_skip(goto_functions); // Removes goto false
86+
goto_functions.update();
87+
88+
remove_unreachable(goto_functions); // Convert unreachable to skips
89+
goto_functions.update();
90+
91+
remove_skip(goto_functions); // Remove all of the new skips
92+
goto_functions.update();
93+
}
94+
7795
status() << "Writing goto binary" << eom;
7896
return write_goto_binary(out, ns.get_symbol_table(), goto_functions);
7997
}

src/goto-programs/remove_unreachable.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,10 @@ void remove_unreachable(goto_programt &goto_program)
5757
it->make_skip();
5858
}
5959
}
60+
61+
void remove_unreachable(goto_functionst &goto_functions)
62+
{
63+
Forall_goto_functions(f_it, goto_functions)
64+
remove_unreachable(f_it->second.body);
65+
}
66+

src/goto-programs/remove_unreachable.h

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ Author: Daniel Kroening, [email protected]
1212
#include "goto_functions.h"
1313

1414
void remove_unreachable(goto_programt &goto_program);
15+
void remove_unreachable(goto_functionst &goto_functions);
1516

1617
#endif // CPROVER_GOTO_PROGRAMS_REMOVE_UNREACHABLE_H

0 commit comments

Comments
 (0)