Skip to content

Commit a403fdd

Browse files
committed
Fix a bug in slice global inits where guard expressions were disregarded
1 parent 7e00a30 commit a403fdd

File tree

5 files changed

+50
-22
lines changed

5 files changed

+50
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
int x;
3+
int y;
4+
5+
int main()
6+
{
7+
if(x)
8+
{
9+
y = 1;
10+
}
11+
12+
return 0;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--slice-global-inits
4+
x = 0;$
5+
y = 0;$
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
9+
^warning: ignoring
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
int x;
3+
int y;
4+
5+
void func(int a, int b)
6+
{
7+
}
8+
9+
int main()
10+
{
11+
func(x, y);
12+
13+
return 0;
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--slice-global-inits
4+
x = 0;$
5+
y = 0;$
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
9+
^warning: ignoring

src/goto-programs/slice_global_inits.cpp

+5-22
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ Date: December 2016
1313

1414
#include "slice_global_inits.h"
1515

16-
#include <unordered_set>
17-
1816
#include <analyses/call_graph.h>
1917

18+
#include <util/find_symbols.h>
2019
#include <util/namespace.h>
2120
#include <util/std_expr.h>
2221
#include <util/cprover_prefix.h>
@@ -46,23 +45,7 @@ void slice_global_inits(goto_modelt &goto_model)
4645

4746
// gather all symbols used by reachable functions
4847

49-
class symbol_collectort:public const_expr_visitort
50-
{
51-
public:
52-
virtual void operator()(const exprt &expr)
53-
{
54-
if(expr.id()==ID_symbol)
55-
{
56-
const symbol_exprt &symbol_expr=to_symbol_expr(expr);
57-
const irep_idt id=symbol_expr.get_identifier();
58-
symbols.insert(id);
59-
}
60-
}
61-
62-
std::unordered_set<irep_idt, irep_id_hash> symbols;
63-
};
64-
65-
symbol_collectort visitor;
48+
find_symbols_sett symbols;
6649

6750
for(std::size_t node_idx = 0; node_idx < directed_graph.size(); ++node_idx)
6851
{
@@ -76,12 +59,12 @@ void slice_global_inits(goto_modelt &goto_model)
7659
forall_goto_program_instructions(i_it, goto_program)
7760
{
7861
const codet &code=i_it->code;
79-
code.visit(visitor);
62+
find_symbols(code, symbols, true, false);
63+
const exprt &expr = i_it->guard;
64+
find_symbols(expr, symbols, true, false);
8065
}
8166
}
8267

83-
const std::unordered_set<irep_idt, irep_id_hash> &symbols=visitor.symbols;
84-
8568
// now remove unnecessary initializations
8669

8770
goto_functionst::function_mapt::iterator f_it;

0 commit comments

Comments
 (0)