Handle potential <clinit>() correctly in LVN.
Bug: 16177324
Change-Id: I727ab6ce9aa9a608fe570cf391a6b732a12a8655
diff --git a/test/083-compiler-regressions/src/Main.java b/test/083-compiler-regressions/src/Main.java
index 6a12ca9..0f7527c 100644
--- a/test/083-compiler-regressions/src/Main.java
+++ b/test/083-compiler-regressions/src/Main.java
@@ -35,6 +35,7 @@
b2487514Test();
b5884080Test();
b13679511Test();
+ b16177324TestWrapper();
largeFrameTest();
largeFrameTestFloat();
mulBy1Test();
@@ -908,6 +909,24 @@
System.out.println("b13679511Test finishing");
}
+ static void b16177324TestWrapper() {
+ try {
+ b16177324Test();
+ } catch (NullPointerException expected) {
+ System.out.println("b16177324TestWrapper caught NPE as expected.");
+ }
+ }
+
+ static void b16177324Test() {
+ // We need this to be a single BasicBlock. Putting it into a try block would cause it to
+ // be split at each insn that can throw. So we do the try-catch in a wrapper function.
+ int v1 = B16177324Values.values[0]; // Null-check on array element access.
+ int v2 = B16177324ValuesKiller.values[0]; // clinit<>() sets B16177324Values.values to null.
+ int v3 = B16177324Values.values[0]; // Should throw NPE.
+ // If the null-check for v3 was eliminated we should fail with SIGSEGV.
+ System.out.println("Unexpectedly retrieved all values: " + v1 + ", " + v2 + ", " + v3);
+ }
+
static double TooManyArgs(
long l00,
long l01,
@@ -9743,3 +9762,14 @@
}
}
}
+
+class B16177324Values {
+ public static int values[] = { 42 };
+}
+
+class B16177324ValuesKiller {
+ public static int values[] = { 1234 };
+ static {
+ B16177324Values.values = null;
+ }
+}