Skip to content

Commit 1060c57

Browse files
authored
Merge pull request #3562 from smowton/smowton/feature/simplify-truncating-cast
Simplifier: transform ((struct A)x).field1 into x.a.b.field2
2 parents 69f54ca + d47a07c commit 1060c57

File tree

12 files changed

+156
-0
lines changed

12 files changed

+156
-0
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
interface Intf {
2+
3+
public int f();
4+
5+
}
Binary file not shown.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
public class Test {
3+
4+
public static void main() {
5+
6+
// The following line is only needed so that multiple possible callees
7+
// for the interface Intf are found, and so a dispatch table
8+
// (if i->@class_identfier == "Impl1" then ...) is generated.
9+
Impl2 unused = new Impl2();
10+
11+
// This should be easily verified, as long as symex can determine that *i
12+
// certainly refers to an instance of Impl1, and so i.f() is certainly a
13+
// call to Impl1.f. This requires it to simplify the expression
14+
// "((struct Intf)some_impl1_instance)[email protected].@class_identifier".
15+
Intf i = new Impl1();
16+
int got = i.f();
17+
assert got == 1;
18+
19+
}
20+
21+
public static void main_derived_class() {
22+
23+
// This is just like the "main" method, except a class with a superclass
24+
// is used, to check that the cast to struct Intf can be simplified even
25+
// when the object doesn't directly have such a member (instead it has a
26+
// member "@Impl1", which itself has a "@java.lang.Object").
27+
28+
Impl2 unused = new Impl2();
29+
30+
Intf i = new Impl1Sub();
31+
int got = i.f();
32+
assert got == 1;
33+
34+
}
35+
36+
}
37+
38+
class Impl1 implements Intf {
39+
40+
// This field is important-- without it, the structures of Impl1 and Intf
41+
// are the same (both being simply { java.lang.Object @java.lang.Object }),
42+
// which allows the expression simplifier to take an easier route than the one
43+
// we intend to test.
44+
public int x;
45+
46+
public int f() {
47+
return 1;
48+
}
49+
50+
}
51+
52+
class Impl1Sub extends Impl1 {
53+
54+
public int z;
55+
56+
}
57+
58+
class Impl2 implements Intf {
59+
60+
public int f() {
61+
return 2;
62+
}
63+
64+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CORE
2+
Test.class
3+
--function Test.main
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^Passing problem to
9+
^warning: ignoring
10+
--
11+
The "Passing problem to..." line is a sign that symex couldn't prove the
12+
assertion is valid by itself, which in turn probably indicates a weakness of the
13+
expression simplifier. The companion test_no_simplify.desc checks that the
14+
"Passing problem to" line is indeed present when we indeed resort to the SAT
15+
solver.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CORE
2+
Test.class
3+
--function Test.main_derived_class
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^Passing problem to
9+
^warning: ignoring
10+
--
11+
The "Passing problem to..." line is a sign that symex couldn't prove the
12+
assertion is valid by itself, which in turn probably indicates a weakness of the
13+
expression simplifier. The companion test_no_propagation.desc checks that the
14+
"Passing problem to" line is indeed present when we indeed resort to the SAT
15+
solver.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CORE
2+
Test.class
3+
--function Test.main --no-simplify --unwind 10
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
^Passing problem to
8+
--
9+
^warning: ignoring
10+
--
11+
This is just to check the "Passing problem to" line is printed when the solver
12+
is invoked -- the real test (test.desc) depends on that to check that its test
13+
code was analysed entirely by goto-symex. If the output format changes this test
14+
should notice that.

0 commit comments

Comments
 (0)