From 22c2d74f4c641feaf22a520d2a0538b31a82239d Mon Sep 17 00:00:00 2001 From: Calin Juravle Date: Tue, 7 Apr 2015 19:43:36 +0100 Subject: Quick: Fix crash on fall-through out of method code. Fix Quick crash when the last insn has a fall-through out of the method's code. Allow creation of an out-of-method block and at the end of MIRGraph::InlineMethod() check if that block is reachable. If it is, punt to interpreter. Add tests for unreachable if-lt and packed-switch as the last insn. Also fix MIRGraph::ProcessCanSwitch() to treat the offset to the data as signed. Jumping over the data with a goto and using it from a switch further down is valid. This was also crashing (presumably only on 64-bit dex2oat). Thanks to Stephen Kyle (stephenckyle@googlemail.com) for the bug report. Bug: 19988134 (cherry picked from commit 2bee20b5f0d783b43c1bbbe281f69a6f9b9e0a98) Change-Id: I8cff7105a66aeb79a91689c3adb216f61ab57e40 --- test/472-unreachable-if-regression/expected.txt | 3 ++ test/472-unreachable-if-regression/info.txt | 3 ++ .../472-unreachable-if-regression/smali/Test.smali | 46 ++++++++++++++++++++++ test/472-unreachable-if-regression/src/Main.java | 37 +++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 test/472-unreachable-if-regression/expected.txt create mode 100644 test/472-unreachable-if-regression/info.txt create mode 100644 test/472-unreachable-if-regression/smali/Test.smali create mode 100644 test/472-unreachable-if-regression/src/Main.java (limited to 'test/472-unreachable-if-regression') diff --git a/test/472-unreachable-if-regression/expected.txt b/test/472-unreachable-if-regression/expected.txt new file mode 100644 index 0000000000..9fc8bea9e2 --- /dev/null +++ b/test/472-unreachable-if-regression/expected.txt @@ -0,0 +1,3 @@ +Test started. +Successfully called UnreachableIf(). +Successfully called UnreachablePackedSwitch(). diff --git a/test/472-unreachable-if-regression/info.txt b/test/472-unreachable-if-regression/info.txt new file mode 100644 index 0000000000..d8b5a45411 --- /dev/null +++ b/test/472-unreachable-if-regression/info.txt @@ -0,0 +1,3 @@ +Regression test for crashes during compilation of methods which end +with an if-cc or switch, i.e. there's a fall-through out of method code. +Also tests a packed-switch with negative offset to its data. diff --git a/test/472-unreachable-if-regression/smali/Test.smali b/test/472-unreachable-if-regression/smali/Test.smali new file mode 100644 index 0000000000..c7107d19ee --- /dev/null +++ b/test/472-unreachable-if-regression/smali/Test.smali @@ -0,0 +1,46 @@ +# +# Copyright (C) 2015 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 public LTest; + +.super Ljava/lang/Object; + +.method public static UnreachableIf()V + .registers 1 + return-void + : unreachable + not-int v0, v0 + if-lt v0, v0, :unreachable + # fall-through out of code item +.end method + +.method public static UnreachablePackedSwitch()V + .registers 1 + return-void + : unreachable + goto :pswitch_2 + :pswitch_data + .packed-switch 1 + :pswitch_1 + :pswitch_2 + :pswitch_1 + :pswitch_2 + .end packed-switch + :pswitch_1 + not-int v0, v0 + :pswitch_2 + packed-switch v0, :pswitch_data + # fall-through out of code item +.end method diff --git a/test/472-unreachable-if-regression/src/Main.java b/test/472-unreachable-if-regression/src/Main.java new file mode 100644 index 0000000000..c9f9511834 --- /dev/null +++ b/test/472-unreachable-if-regression/src/Main.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2015 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.Method; + +public class Main { + + // Workaround for b/18051191. + class InnerClass {} + + public static void main(String args[]) throws Exception { + System.out.println("Test started."); + Class c = Class.forName("Test"); + + Method unreachableIf = c.getMethod("UnreachableIf", (Class[]) null); + unreachableIf.invoke(null, (Object[]) null); + System.out.println("Successfully called UnreachableIf()."); + + Method unreachablePackedSwitch = c.getMethod("UnreachablePackedSwitch", (Class[]) null); + unreachablePackedSwitch.invoke(null, (Object[]) null); + System.out.println("Successfully called UnreachablePackedSwitch()."); + } + +} -- cgit v1.2.3