From db40632b3d44f17be29ca100aeed1bcdcc39c827 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Wed, 19 Feb 2014 14:11:19 +0000 Subject: Add tests for null check elimination by local value numbering. Change-Id: I0c3355b3c38b8830fffe2233ede7f6a35488b6fe --- test/083-compiler-regressions/src/Main.java | 50 ++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'test/083-compiler-regressions/src/Main.java') 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"); + } + } } -- cgit v1.2.3-59-g8ed1b