Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2016 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 
     19   public static void main(String args[]) {
     20     Element[] elements = new Element[51];
     21     testArraySetCheckCastNull(elements);
     22 
     23     System.out.println("passed");
     24   }
     25 
     26   /// CHECK-START: void Main.testArraySetCheckCastNull(Main$Element[]) builder (after)
     27   /// CHECK:         <<Array:l\d+>>         ParameterValue
     28   /// CHECK-DAG:     <<Index:i\d+>>         IntConstant 42
     29   /// CHECK-DAG:     <<Null:l\d+>>          NullConstant
     30   /// CHECK-DAG:     <<Class:l\d+>>         LoadClass
     31   /// CHECK-DAG:                            CheckCast [<<Null>>,<<Class>>]
     32   /// CHECK-DAG:     <<CheckedValue:l\d+>>  BoundType [<<Null>>] klass:Main$Element can_be_null:true
     33   /// CHECK-DAG:     <<CheckedArray:l\d+>>  NullCheck [<<Array>>]
     34   /// CHECK-DAG:     <<Length:i\d+>>        ArrayLength [<<CheckedArray>>]
     35   /// CHECK-DAG:     <<CheckedIndex:i\d+>>  BoundsCheck [<<Index>>,<<Length>>]
     36   /// CHECK-DAG:     <<ArraySet:v\d+>>      ArraySet [<<CheckedArray>>,<<CheckedIndex>>,<<CheckedValue>>] needs_type_check:true
     37 
     38   /// CHECK-START: void Main.testArraySetCheckCastNull(Main$Element[]) instruction_simplifier (after)
     39   /// CHECK-NOT:                            CheckCast
     40 
     41   /// CHECK-START: void Main.testArraySetCheckCastNull(Main$Element[]) prepare_for_register_allocation (before)
     42   /// CHECK:         <<Array:l\d+>>         ParameterValue
     43   /// CHECK-DAG:     <<Index:i\d+>>         IntConstant 42
     44   /// CHECK-DAG:     <<Null:l\d+>>          NullConstant
     45   /// CHECK-DAG:     <<Class:l\d+>>         LoadClass
     46   /// CHECK-DAG:     <<CheckedValue:l\d+>>  BoundType [<<Null>>]
     47   /// CHECK-DAG:     <<CheckedArray:l\d+>>  NullCheck [<<Array>>]
     48   /// CHECK-DAG:     <<Length:i\d+>>        ArrayLength [<<CheckedArray>>]
     49   /// CHECK-DAG:     <<CheckedIndex:i\d+>>  BoundsCheck [<<Index>>,<<Length>>]
     50   /// CHECK-DAG:     <<ArraySet:v\d+>>      ArraySet [<<CheckedArray>>,<<CheckedIndex>>,<<CheckedValue>>] needs_type_check:true
     51 
     52   /// CHECK-START: void Main.testArraySetCheckCastNull(Main$Element[]) prepare_for_register_allocation (after)
     53   /// CHECK:         <<Array:l\d+>>         ParameterValue
     54   /// CHECK-DAG:     <<Index:i\d+>>         IntConstant 42
     55   /// CHECK-DAG:     <<Null:l\d+>>          NullConstant
     56   /// CHECK-DAG:     <<Class:l\d+>>         LoadClass
     57   /// CHECK-DAG:     <<Length:i\d+>>        ArrayLength [<<Array>>]
     58   /// CHECK-DAG:     <<ArraySet:v\d+>>      ArraySet [<<Array>>,<<Index>>,<<Null>>] needs_type_check:false
     59 
     60   static void testArraySetCheckCastNull(Element[] elements) {
     61     Object object = null;
     62     Element element = (Element) object;
     63     elements[42] = element;
     64   }
     65 
     66   class Element {}
     67 
     68 }
     69