| 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | public class Main { |
| 18 | public static void main(String[] args) { |
| 19 | System.out.println(test()); |
| 20 | } |
| 21 | |
| 22 | public static long testField = 0; |
| 23 | public static long longField0 = 0; |
| 24 | public static long longField1 = 0; |
| 25 | public static long longField2 = 0; |
| 26 | public static long longField3 = 0; |
| 27 | public static long longField4 = 0; |
| 28 | public static long longField5 = 0; |
| 29 | public static long longField6 = 0; |
| 30 | public static long longField7 = 0; |
| 31 | |
| 32 | /// CHECK-START-ARM: int Main.test() register (after) |
| 33 | /// CHECK: TypeConversion locations:[#-8690466096623102344]->{{.*}} |
| 34 | public static int test() { |
| 35 | // To avoid constant folding TypeConversion(const), hide the constant in a field. Then, hide |
| 36 | // it even more inside a Select that can only be reduced after LSE+InstructionSelector. We |
| 37 | // don't run constant folding after that. |
| 38 | testField = 0x8765432112345678L; |
| 39 | long value = testField; |
| 40 | if (value + 1 == 0x8765432112345679L) { |
| 41 | value = testField; |
| 42 | } else { |
| 43 | value = 0; |
| 44 | } |
| 45 | // Now, the `value` is in a register because of the store but we need |
| 46 | // a constant location to trigger the bug, so load a bunch of other fields. |
| 47 | long l0 = longField0; |
| 48 | long l1 = longField1; |
| 49 | long l2 = longField2; |
| 50 | long l3 = longField3; |
| 51 | long l4 = longField4; |
| 52 | long l5 = longField5; |
| 53 | long l6 = longField6; |
| 54 | long l7 = longField7; |
| 55 | if (l0 != 0 || l1 != 0 || l2 != 0 || l3 != 0 || l4 != 0 || l5 != 0 || l6 != 0 || l7 != 0) { |
| 56 | throw new Error(); |
| 57 | } |
| 58 | // Do the conversion from constant location. |
| 59 | return (int) value; |
| 60 | } |
| 61 | } |