1# Copyright (C) 2017 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15.class public LSmaliTests; 16.super Ljava/lang/Object; 17 18## CHECK-START: char SmaliTests.stringCharAtCatch(java.lang.String, int) instruction_simplifier (before) 19## CHECK-DAG: <<Char:c\d+>> InvokeVirtual intrinsic:StringCharAt 20## CHECK-DAG: Return [<<Char>>] 21 22## CHECK-START: char SmaliTests.stringCharAtCatch(java.lang.String, int) instruction_simplifier (after) 23## CHECK-DAG: <<String:l\d+>> ParameterValue 24## CHECK-DAG: <<Pos:i\d+>> ParameterValue 25## CHECK-DAG: <<NullCk:l\d+>> NullCheck [<<String>>] 26## CHECK-DAG: <<Length:i\d+>> ArrayLength [<<NullCk>>] is_string_length:true 27## CHECK-DAG: <<Bounds:i\d+>> BoundsCheck [<<Pos>>,<<Length>>] is_string_char_at:true 28## CHECK-DAG: <<Char:c\d+>> ArrayGet [<<NullCk>>,<<Bounds>>] is_string_char_at:true 29## CHECK-DAG: Return [<<Char>>] 30 31## CHECK-START: char SmaliTests.stringCharAtCatch(java.lang.String, int) instruction_simplifier (after) 32## CHECK-NOT: InvokeVirtual intrinsic:StringCharAt 33.method public static stringCharAtCatch(Ljava/lang/String;I)C 34 .registers 4 35 .param p0, "s" # Ljava/lang/String; 36 .param p1, "pos" # I 37 38 .prologue 39 40 # if (doThrow) { throw new Error(); } 41 sget-boolean v1, LMain;->doThrow:Z 42 if-eqz v1, :doThrow_false 43 new-instance v1, Ljava/lang/Error; 44 invoke-direct {v1}, Ljava/lang/Error;-><init>()V 45 throw v1 46 47 :doThrow_false 48 :try_start 49 # tmp = s.charAt(pos) 50 invoke-virtual {p0, p1}, Ljava/lang/String;->charAt(I)C 51 :try_end 52 .catch Ljava/lang/StringIndexOutOfBoundsException; {:try_start .. :try_end} :catch 53 54 # return tmp 55 move-result v1 56 return v1 57 58 :catch 59 # return '\0' 60 move-exception v0 61 const/4 v1, 0x0 62 return v1 63.end method 64 65## CHECK-START: char SmaliTests.stringCharAtCatchPhiReturn(java.lang.String, int) instruction_simplifier (before) 66## CHECK-DAG: <<Int:i\d+>> IntConstant 0 67## CHECK-DAG: <<Char:c\d+>> InvokeVirtual intrinsic:StringCharAt 68## CHECK-DAG: <<Phi:i\d+>> Phi [<<Char>>,<<Int>>] 69## CHECK-DAG: Return [<<Phi>>] 70 71## CHECK-START: char SmaliTests.stringCharAtCatchPhiReturn(java.lang.String, int) instruction_simplifier (after) 72## CHECK-DAG: <<String:l\d+>> ParameterValue 73## CHECK-DAG: <<Pos:i\d+>> ParameterValue 74## CHECK-DAG: <<Int:i\d+>> IntConstant 0 75## CHECK-DAG: <<NullCk:l\d+>> NullCheck [<<String>>] 76## CHECK-DAG: <<Length:i\d+>> ArrayLength [<<NullCk>>] is_string_length:true 77## CHECK-DAG: <<Bounds:i\d+>> BoundsCheck [<<Pos>>,<<Length>>] is_string_char_at:true 78## CHECK-DAG: <<Char:c\d+>> ArrayGet [<<NullCk>>,<<Bounds>>] is_string_char_at:true 79## CHECK-DAG: <<Phi:i\d+>> Phi [<<Char>>,<<Int>>] 80## CHECK-DAG: Return [<<Phi>>] 81 82## CHECK-START: char SmaliTests.stringCharAtCatchPhiReturn(java.lang.String, int) instruction_simplifier (after) 83## CHECK-NOT: InvokeVirtual intrinsic:StringCharAt 84.method public static stringCharAtCatchPhiReturn(Ljava/lang/String;I)C 85 .registers 4 86 87 sget-boolean v1, LMain;->doThrow:Z 88 89 if-eqz v1, :cond_a 90 new-instance v1, Ljava/lang/Error; 91 invoke-direct {v1}, Ljava/lang/Error;-><init>()V 92 throw v1 93 94 :cond_a 95 :try_start_a 96 invoke-virtual {p0, p1}, Ljava/lang/String;->charAt(I)C 97 :try_end_d 98 .catch Ljava/lang/StringIndexOutOfBoundsException; {:try_start_a .. :try_end_d} :catch_f 99 100 move-result v1 101 102 :goto_e 103 return v1 104 105 :catch_f 106 move-exception v0 107 108 const/4 v1, 0x0 109 goto :goto_e 110.end method 111