Skip to content

Commit 71c61fe

Browse files
committed
Don't phi-merge uninitialized objects
1 parent 41d7a45 commit 71c61fe

File tree

8 files changed

+62
-3
lines changed

8 files changed

+62
-3
lines changed
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
public class Main {
2+
3+
public int phiMerge(Boolean trigger) {
4+
5+
Ephemeral obj;
6+
if (trigger) {
7+
obj = new Ephemeral(42);
8+
} else {
9+
obj = new Temp(20);
10+
}
11+
12+
assert obj.val == 20;
13+
return obj.val;
14+
}
15+
16+
class Ephemeral {
17+
Ephemeral(int value) {
18+
val = value;
19+
}
20+
21+
int val;
22+
}
23+
24+
class Temp extends Ephemeral {
25+
Temp(int value) {
26+
super(value);
27+
}
28+
}
29+
}
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
Main.class
3+
--function Main.phiMerge --show-vcc
4+
activate-multi-line-match
5+
^.*dynamic_object2#2 == \{ \.@class_identifier="java::Main\$Temp",\s*\.@lock=false \}$
6+
^EXIT=0$
7+
^SIGNAL=0$

regression/test.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ ($$$$$$$$$)
174174
binmode $fh;
175175
my $whole_file = <$fh>;
176176
$whole_file =~ s/\r\n/\n/g;
177-
my $is_match = $whole_file =~ /$result/;
177+
my $is_match = $whole_file =~ /$result/m;
178178
$r = ($included ? !$is_match : $is_match);
179179
}
180180
else

src/goto-symex/goto_symex.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,19 @@ void goto_symext::do_simplify(exprt &expr)
2222
simplify(expr, ns);
2323
}
2424

25+
nondet_symbol_exprt goto_symext::build_symex_nondet(typet &type)
26+
{
27+
irep_idt identifier = "symex::nondet" + std::to_string(nondet_count++);
28+
nondet_symbol_exprt new_expr(identifier, type);
29+
return new_expr;
30+
}
31+
2532
void goto_symext::replace_nondet(exprt &expr)
2633
{
2734
if(expr.id()==ID_side_effect &&
2835
expr.get(ID_statement)==ID_nondet)
2936
{
30-
irep_idt identifier="symex::nondet"+std::to_string(nondet_count++);
31-
nondet_symbol_exprt new_expr(identifier, expr.type());
37+
nondet_symbol_exprt new_expr = build_symex_nondet(expr.type());
3238
new_expr.add_source_location()=expr.source_location();
3339
expr.swap(new_expr);
3440
}

src/goto-symex/goto_symex.h

+2
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ class goto_symext
376376
exprt &code,
377377
const irep_idt &identifier);
378378

379+
nondet_symbol_exprt build_symex_nondet(typet &type);
380+
379381
// exceptions
380382
void symex_throw(statet &);
381383
void symex_catch(statet &);

src/goto-symex/symex_builtin_functions.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ void goto_symext::symex_allocate(
184184
else
185185
throw "failed to zero initialize dynamic object";
186186
}
187+
else
188+
{
189+
exprt nondet = build_symex_nondet(object_type);
190+
code_assignt assignment(value_symbol.symbol_expr(), nondet);
191+
symex_assign(state, assignment);
192+
}
187193

188194
exprt rhs;
189195

src/goto-symex/symex_goto.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,14 @@ void goto_symext::phi_function(
429429
rhs=goto_state_rhs;
430430
else if(goto_state.guard.is_false())
431431
rhs=dest_state_rhs;
432+
else if(goto_state.level2_current_count(l1_identifier) == 0)
433+
{
434+
rhs = dest_state_rhs;
435+
}
436+
else if(dest_state.level2.current_count(l1_identifier) == 0)
437+
{
438+
rhs = goto_state_rhs;
439+
}
432440
else
433441
{
434442
rhs=if_exprt(diff_guard.as_expr(), goto_state_rhs, dest_state_rhs);

0 commit comments

Comments
 (0)