invoke-super can also have implicit null checks.
Test: 724-invoke-super-npe
Bug: 147364466
Change-Id: I408e3bb5f84ee6b4d7a1cad149c8ccca8b35f1fa
diff --git a/runtime/common_throws.cc b/runtime/common_throws.cc
index fdd4f36..1c9cf18 100644
--- a/runtime/common_throws.cc
+++ b/runtime/common_throws.cc
@@ -475,6 +475,8 @@
case Instruction::INVOKE_INTERFACE_RANGE:
case Instruction::INVOKE_POLYMORPHIC:
case Instruction::INVOKE_POLYMORPHIC_RANGE:
+ case Instruction::INVOKE_SUPER:
+ case Instruction::INVOKE_SUPER_RANGE:
case Instruction::INVOKE_VIRTUAL_QUICK:
case Instruction::INVOKE_VIRTUAL_RANGE_QUICK: {
// Without inlining, we could just check that the offset is the class offset.
@@ -596,6 +598,12 @@
case Instruction::INVOKE_VIRTUAL_RANGE:
ThrowNullPointerExceptionForMethodAccess(instr.VRegB_3rc(), kVirtual);
break;
+ case Instruction::INVOKE_SUPER:
+ ThrowNullPointerExceptionForMethodAccess(instr.VRegB_35c(), kSuper);
+ break;
+ case Instruction::INVOKE_SUPER_RANGE:
+ ThrowNullPointerExceptionForMethodAccess(instr.VRegB_3rc(), kSuper);
+ break;
case Instruction::INVOKE_INTERFACE:
ThrowNullPointerExceptionForMethodAccess(instr.VRegB_35c(), kInterface);
break;
diff --git a/test/724-invoke-super-npe/expected.txt b/test/724-invoke-super-npe/expected.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/724-invoke-super-npe/expected.txt
diff --git a/test/724-invoke-super-npe/info.txt b/test/724-invoke-super-npe/info.txt
new file mode 100644
index 0000000..b85a214
--- /dev/null
+++ b/test/724-invoke-super-npe/info.txt
@@ -0,0 +1 @@
+Regression test for implict null checks on invoke-super and invoke-super-range.
diff --git a/test/724-invoke-super-npe/smali/TestCase.smali b/test/724-invoke-super-npe/smali/TestCase.smali
new file mode 100644
index 0000000..9b79a92
--- /dev/null
+++ b/test/724-invoke-super-npe/smali/TestCase.smali
@@ -0,0 +1,42 @@
+# Copyright (C) 2020 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.class LTestCase;
+.super LMain;
+
+.method public constructor <init>()V
+.registers 2
+ invoke-direct {v1}, LMain;-><init>()V
+ return-void
+.end method
+
+.method public testSuperRange(LTestCase;)I
+.registers 8
+ invoke-super/range {p1}, LMain;->toInt()I
+ move-result v0
+ return v0
+.end method
+
+.method public testSuper(LTestCase;)I
+.registers 8
+ invoke-super {p1}, LMain;->toInt()I
+ move-result v0
+ return v0
+.end method
+
+.method public toInt()I
+.registers 3
+ const v0, 777
+ return v0
+.end method
diff --git a/test/724-invoke-super-npe/src/Main.java b/test/724-invoke-super-npe/src/Main.java
new file mode 100644
index 0000000..5d5567e
--- /dev/null
+++ b/test/724-invoke-super-npe/src/Main.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+class Main {
+ public static void main(String[] args) throws Exception {
+ Class<?> cls = Class.forName("TestCase");
+ test("testSuper", cls);
+ test("testSuperRange", cls);
+ }
+
+ public static void test(String methodName, Class<?> cls) throws Exception {
+ Method m = cls.getDeclaredMethod(methodName, cls);
+ try {
+ m.invoke(cls.newInstance(), (Object)null);
+ throw new Error("Expected NullPointerException");
+ } catch (InvocationTargetException e) {
+ if (e.getCause().getClass() != NullPointerException.class) {
+ throw new Error("Expected NullPointerException, got " + e.getCause().getClass());
+ }
+ }
+ }
+
+ public int toInt() {
+ return 42;
+ }
+}