diff options
| author | 2014-02-19 14:11:19 +0000 | |
|---|---|---|
| committer | 2014-02-21 15:35:00 +0000 | |
| commit | db40632b3d44f17be29ca100aeed1bcdcc39c827 (patch) | |
| tree | 50c3b4bc05044ad011b0f58d2cff639b0be44e1f | |
| parent | 7eef69400ae27fd67a9f6b6a79ffaf2d76979844 (diff) | |
Add tests for null check elimination by local value numbering.
Change-Id: I0c3355b3c38b8830fffe2233ede7f6a35488b6fe
| -rw-r--r-- | test/083-compiler-regressions/expected.txt | 2 | ||||
| -rw-r--r-- | test/083-compiler-regressions/src/Main.java | 50 |
2 files changed, 51 insertions, 1 deletions
diff --git a/test/083-compiler-regressions/expected.txt b/test/083-compiler-regressions/expected.txt index e2846dd796..57065ef01d 100644 --- a/test/083-compiler-regressions/expected.txt +++ b/test/083-compiler-regressions/expected.txt @@ -9,5 +9,7 @@ identityTest passes wideGetterSetterTest passes wideIdentityTest passes returnConstantTest passes +LVNTests.testNPE1 passes +LVNTests.testNPE2 passes longDivTest passes longModTest passes diff --git a/test/083-compiler-regressions/src/Main.java b/test/083-compiler-regressions/src/Main.java index 3307e50642..6829388d2a 100644 --- a/test/083-compiler-regressions/src/Main.java +++ b/test/083-compiler-regressions/src/Main.java @@ -40,6 +40,8 @@ public class Main { wideGetterSetterTest(); wideIdentityTest(); returnConstantTest(); + LVNTests.testNPE1(); + LVNTests.testNPE2(); ZeroTests.longDivTest(); ZeroTests.longModTest(); } @@ -8440,6 +8442,52 @@ class Foo { public long wideIdent5(int a6, int a5, int a4, int a3, int a2, long a1) { return a1; - } + } +} + +class LVNTests { + private LVNTests link = null; + private int value = 0; + + private void setLink(LVNTests l) { + link = l; + } + + private static void causeNPE1(LVNTests lhs, LVNTests rhs) { + LVNTests link1 = lhs.link; + rhs.link = null; + LVNTests link2 = lhs.link; + int value1 = link1.value; + int value2 = link2.value; + System.out.println("LVNTests.testNPE1 fails with " + value1 + " and " + value2); + } + + public static void testNPE1() { + LVNTests t = new LVNTests(); + t.link = new LVNTests(); + try { + causeNPE1(t, t); + } catch (NullPointerException e) { + System.out.println("LVNTests.testNPE1 passes"); + } + } + + private static void causeNPE2(LVNTests lhs, LVNTests rhs) { + LVNTests link1 = lhs.link; + rhs.setLink(null); + LVNTests link2 = lhs.link; + int value1 = link1.value; + int value2 = link2.value; + System.out.println("LVNTests.testNPE2 fails with " + value1 + " and " + value2); + } + public static void testNPE2() { + LVNTests t = new LVNTests(); + t.link = new LVNTests(); + try { + causeNPE2(t, t); + } catch (NullPointerException e) { + System.out.println("LVNTests.testNPE2 passes"); + } + } } |