Skip to content

Commit f0d7ae5

Browse files
committed
Add test for constant- and value-set propagation out of a may-throw function
This is possible now that #return_value variables are not subject to special rules in phi_function, and the value-set is cleared when variables are marked dead, meaning that there is no chance a second function call which only sometimes defines #return_value might witness the previous call's results.
1 parent ba8c9bd commit f0d7ae5

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed
Binary file not shown.
Binary file not shown.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
public class Test {
2+
3+
public static Test f(boolean unknown) throws Exception {
4+
5+
if(unknown)
6+
throw new Exception();
7+
else
8+
return new Test();
9+
10+
}
11+
12+
public static void main(boolean unknown) {
13+
14+
Sub s = new Sub(); // Make sure Sub is loaded
15+
int x = 0;
16+
17+
// The routine below is repeated twice because historically symex could
18+
// behave differently the first and second times a may-throw function was
19+
// called.
20+
21+
try {
22+
Test t1 = f(unknown);
23+
t1.f();
24+
x += t1.g();
25+
}
26+
catch(Exception e) { }
27+
28+
try {
29+
Test t2 = f(unknown);
30+
t2.f();
31+
x += t2.g();
32+
}
33+
catch(Exception e) { }
34+
35+
assert x == 10;
36+
37+
}
38+
39+
public void f() { }
40+
public int g() { return 5; }
41+
42+
}
43+
44+
class Sub extends Test {
45+
46+
public void f() { }
47+
public int g() { return 0; }
48+
49+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CORE
2+
Test.class
3+
--function Test.main --show-vcc
4+
java::Test\.main:\(Z\)V::14::t1!0@1#\d+ = address_of\(symex_dynamic::dynamic_object\d+\)
5+
java::Test\.main:\(Z\)V::9::x!0@1#\d+ = 5 \+ java::Test\.main:\(Z\)V::9::x!0@1#\d+
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
9+
return_value!0#0
10+
java::Sub\.g:\(\)
11+
--
12+
This checks that when a function may throw, we can nontheless constant-propagate
13+
and populate the value-set for the normal-return path. In particular we don't
14+
expect to see any reference to a zero-generation return value (indicating
15+
reading the return-value when not defined), nor do we expect to see any code
16+
from the Sub class, which is not accessible and can only be reached when
17+
constant propagation has lost information to the point we're not sure which type
18+
virtual calls against Test may find.

0 commit comments

Comments
 (0)