1*9880d681SAndroid Build Coastguard Worker; RUN: llc -verify-machineinstrs -disable-fp-elim < %s -mtriple=aarch64-apple-ios -disable-post-ra | FileCheck --check-prefix=CHECK-APPLE %s 2*9880d681SAndroid Build Coastguard Worker; RUN: llc -verify-machineinstrs -disable-fp-elim -O0 < %s -mtriple=aarch64-apple-ios -disable-post-ra | FileCheck --check-prefix=CHECK-O0 %s 3*9880d681SAndroid Build Coastguard Worker 4*9880d681SAndroid Build Coastguard Workerdeclare i8* @malloc(i64) 5*9880d681SAndroid Build Coastguard Workerdeclare void @free(i8*) 6*9880d681SAndroid Build Coastguard Worker%swift_error = type {i64, i8} 7*9880d681SAndroid Build Coastguard Worker 8*9880d681SAndroid Build Coastguard Worker; This tests the basic usage of a swifterror parameter. "foo" is the function 9*9880d681SAndroid Build Coastguard Worker; that takes a swifterror parameter and "caller" is the caller of "foo". 10*9880d681SAndroid Build Coastguard Workerdefine float @foo(%swift_error** swifterror %error_ptr_ref) { 11*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE-LABEL: foo: 12*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: orr w0, wzr, #0x10 13*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: malloc 14*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: orr [[ID:w[0-9]+]], wzr, #0x1 15*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: strb [[ID]], [x0, #8] 16*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov x19, x0 17*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE-NOT: x19 18*9880d681SAndroid Build Coastguard Worker 19*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: foo: 20*9880d681SAndroid Build Coastguard Worker; CHECK-O0: orr w{{.*}}, wzr, #0x10 21*9880d681SAndroid Build Coastguard Worker; CHECK-O0: malloc 22*9880d681SAndroid Build Coastguard Worker; CHECK-O0: mov [[ID2:x[0-9]+]], x0 23*9880d681SAndroid Build Coastguard Worker; CHECK-O0: orr [[ID:w[0-9]+]], wzr, #0x1 24*9880d681SAndroid Build Coastguard Worker; CHECK-O0: strb [[ID]], [x0, #8] 25*9880d681SAndroid Build Coastguard Worker; CHECK-O0: mov x19, [[ID2]] 26*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: x19 27*9880d681SAndroid Build Coastguard Workerentry: 28*9880d681SAndroid Build Coastguard Worker %call = call i8* @malloc(i64 16) 29*9880d681SAndroid Build Coastguard Worker %call.0 = bitcast i8* %call to %swift_error* 30*9880d681SAndroid Build Coastguard Worker store %swift_error* %call.0, %swift_error** %error_ptr_ref 31*9880d681SAndroid Build Coastguard Worker %tmp = getelementptr inbounds i8, i8* %call, i64 8 32*9880d681SAndroid Build Coastguard Worker store i8 1, i8* %tmp 33*9880d681SAndroid Build Coastguard Worker ret float 1.0 34*9880d681SAndroid Build Coastguard Worker} 35*9880d681SAndroid Build Coastguard Worker 36*9880d681SAndroid Build Coastguard Worker; "caller" calls "foo" that takes a swifterror parameter. 37*9880d681SAndroid Build Coastguard Workerdefine float @caller(i8* %error_ref) { 38*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE-LABEL: caller: 39*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov [[ID:x[0-9]+]], x0 40*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov x19, xzr 41*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: bl {{.*}}foo 42*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: cbnz x19 43*9880d681SAndroid Build Coastguard Worker; Access part of the error object and save it to error_ref 44*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: ldrb [[CODE:w[0-9]+]], [x19, #8] 45*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: strb [[CODE]], [{{.*}}[[ID]]] 46*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov x0, x19 47*9880d681SAndroid Build Coastguard Worker; CHECK_APPLE: bl {{.*}}free 48*9880d681SAndroid Build Coastguard Worker 49*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: caller: 50*9880d681SAndroid Build Coastguard Worker; CHECK-O0: mov x19 51*9880d681SAndroid Build Coastguard Worker; CHECK-O0: bl {{.*}}foo 52*9880d681SAndroid Build Coastguard Worker; CHECK-O0: mov [[ID:x[0-9]+]], x19 53*9880d681SAndroid Build Coastguard Worker; CHECK-O0: cbnz [[ID]] 54*9880d681SAndroid Build Coastguard Workerentry: 55*9880d681SAndroid Build Coastguard Worker %error_ptr_ref = alloca swifterror %swift_error* 56*9880d681SAndroid Build Coastguard Worker store %swift_error* null, %swift_error** %error_ptr_ref 57*9880d681SAndroid Build Coastguard Worker %call = call float @foo(%swift_error** swifterror %error_ptr_ref) 58*9880d681SAndroid Build Coastguard Worker %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref 59*9880d681SAndroid Build Coastguard Worker %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null 60*9880d681SAndroid Build Coastguard Worker %tmp = bitcast %swift_error* %error_from_foo to i8* 61*9880d681SAndroid Build Coastguard Worker br i1 %had_error_from_foo, label %handler, label %cont 62*9880d681SAndroid Build Coastguard Workercont: 63*9880d681SAndroid Build Coastguard Worker %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1 64*9880d681SAndroid Build Coastguard Worker %t = load i8, i8* %v1 65*9880d681SAndroid Build Coastguard Worker store i8 %t, i8* %error_ref 66*9880d681SAndroid Build Coastguard Worker br label %handler 67*9880d681SAndroid Build Coastguard Workerhandler: 68*9880d681SAndroid Build Coastguard Worker call void @free(i8* %tmp) 69*9880d681SAndroid Build Coastguard Worker ret float 1.0 70*9880d681SAndroid Build Coastguard Worker} 71*9880d681SAndroid Build Coastguard Worker 72*9880d681SAndroid Build Coastguard Worker; "caller2" is the caller of "foo", it calls "foo" inside a loop. 73*9880d681SAndroid Build Coastguard Workerdefine float @caller2(i8* %error_ref) { 74*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE-LABEL: caller2: 75*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov [[ID:x[0-9]+]], x0 76*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: fmov [[CMP:s[0-9]+]], #1.0 77*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov x19, xzr 78*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: bl {{.*}}foo 79*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: cbnz x19 80*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: fcmp s0, [[CMP]] 81*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: b.le 82*9880d681SAndroid Build Coastguard Worker; Access part of the error object and save it to error_ref 83*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: ldrb [[CODE:w[0-9]+]], [x19, #8] 84*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: strb [[CODE]], [{{.*}}[[ID]]] 85*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov x0, x19 86*9880d681SAndroid Build Coastguard Worker; CHECK_APPLE: bl {{.*}}free 87*9880d681SAndroid Build Coastguard Worker 88*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: caller2: 89*9880d681SAndroid Build Coastguard Worker; CHECK-O0: mov x19 90*9880d681SAndroid Build Coastguard Worker; CHECK-O0: bl {{.*}}foo 91*9880d681SAndroid Build Coastguard Worker; CHECK-O0: mov [[ID:x[0-9]+]], x19 92*9880d681SAndroid Build Coastguard Worker; CHECK-O0: cbnz [[ID]] 93*9880d681SAndroid Build Coastguard Workerentry: 94*9880d681SAndroid Build Coastguard Worker %error_ptr_ref = alloca swifterror %swift_error* 95*9880d681SAndroid Build Coastguard Worker br label %bb_loop 96*9880d681SAndroid Build Coastguard Workerbb_loop: 97*9880d681SAndroid Build Coastguard Worker store %swift_error* null, %swift_error** %error_ptr_ref 98*9880d681SAndroid Build Coastguard Worker %call = call float @foo(%swift_error** swifterror %error_ptr_ref) 99*9880d681SAndroid Build Coastguard Worker %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref 100*9880d681SAndroid Build Coastguard Worker %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null 101*9880d681SAndroid Build Coastguard Worker %tmp = bitcast %swift_error* %error_from_foo to i8* 102*9880d681SAndroid Build Coastguard Worker br i1 %had_error_from_foo, label %handler, label %cont 103*9880d681SAndroid Build Coastguard Workercont: 104*9880d681SAndroid Build Coastguard Worker %cmp = fcmp ogt float %call, 1.000000e+00 105*9880d681SAndroid Build Coastguard Worker br i1 %cmp, label %bb_end, label %bb_loop 106*9880d681SAndroid Build Coastguard Workerbb_end: 107*9880d681SAndroid Build Coastguard Worker %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1 108*9880d681SAndroid Build Coastguard Worker %t = load i8, i8* %v1 109*9880d681SAndroid Build Coastguard Worker store i8 %t, i8* %error_ref 110*9880d681SAndroid Build Coastguard Worker br label %handler 111*9880d681SAndroid Build Coastguard Workerhandler: 112*9880d681SAndroid Build Coastguard Worker call void @free(i8* %tmp) 113*9880d681SAndroid Build Coastguard Worker ret float 1.0 114*9880d681SAndroid Build Coastguard Worker} 115*9880d681SAndroid Build Coastguard Worker 116*9880d681SAndroid Build Coastguard Worker; "foo_if" is a function that takes a swifterror parameter, it sets swifterror 117*9880d681SAndroid Build Coastguard Worker; under a certain condition. 118*9880d681SAndroid Build Coastguard Workerdefine float @foo_if(%swift_error** swifterror %error_ptr_ref, i32 %cc) { 119*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE-LABEL: foo_if: 120*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: cbz w0 121*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: orr w0, wzr, #0x10 122*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: malloc 123*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: orr [[ID:w[0-9]+]], wzr, #0x1 124*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: strb [[ID]], [x0, #8] 125*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov x19, x0 126*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE-NOT: x19 127*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: ret 128*9880d681SAndroid Build Coastguard Worker 129*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: foo_if: 130*9880d681SAndroid Build Coastguard Worker; spill x19 131*9880d681SAndroid Build Coastguard Worker; CHECK-O0: str x19 132*9880d681SAndroid Build Coastguard Worker; CHECK-O0: cbz w0 133*9880d681SAndroid Build Coastguard Worker; CHECK-O0: orr w{{.*}}, wzr, #0x10 134*9880d681SAndroid Build Coastguard Worker; CHECK-O0: malloc 135*9880d681SAndroid Build Coastguard Worker; CHECK-O0: mov [[ID:x[0-9]+]], x0 136*9880d681SAndroid Build Coastguard Worker; CHECK-O0: orr [[ID2:w[0-9]+]], wzr, #0x1 137*9880d681SAndroid Build Coastguard Worker; CHECK-O0: strb [[ID2]], [x0, #8] 138*9880d681SAndroid Build Coastguard Worker; CHECK-O0: mov x19, [[ID]] 139*9880d681SAndroid Build Coastguard Worker; CHECK-O0: ret 140*9880d681SAndroid Build Coastguard Worker; reload from stack 141*9880d681SAndroid Build Coastguard Worker; CHECK-O0: ldr x19 142*9880d681SAndroid Build Coastguard Worker; CHECK-O0: ret 143*9880d681SAndroid Build Coastguard Workerentry: 144*9880d681SAndroid Build Coastguard Worker %cond = icmp ne i32 %cc, 0 145*9880d681SAndroid Build Coastguard Worker br i1 %cond, label %gen_error, label %normal 146*9880d681SAndroid Build Coastguard Worker 147*9880d681SAndroid Build Coastguard Workergen_error: 148*9880d681SAndroid Build Coastguard Worker %call = call i8* @malloc(i64 16) 149*9880d681SAndroid Build Coastguard Worker %call.0 = bitcast i8* %call to %swift_error* 150*9880d681SAndroid Build Coastguard Worker store %swift_error* %call.0, %swift_error** %error_ptr_ref 151*9880d681SAndroid Build Coastguard Worker %tmp = getelementptr inbounds i8, i8* %call, i64 8 152*9880d681SAndroid Build Coastguard Worker store i8 1, i8* %tmp 153*9880d681SAndroid Build Coastguard Worker ret float 1.0 154*9880d681SAndroid Build Coastguard Worker 155*9880d681SAndroid Build Coastguard Workernormal: 156*9880d681SAndroid Build Coastguard Worker ret float 0.0 157*9880d681SAndroid Build Coastguard Worker} 158*9880d681SAndroid Build Coastguard Worker 159*9880d681SAndroid Build Coastguard Worker; "foo_loop" is a function that takes a swifterror parameter, it sets swifterror 160*9880d681SAndroid Build Coastguard Worker; under a certain condition inside a loop. 161*9880d681SAndroid Build Coastguard Workerdefine float @foo_loop(%swift_error** swifterror %error_ptr_ref, i32 %cc, float %cc2) { 162*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE-LABEL: foo_loop: 163*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov x0, x19 164*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: cbz 165*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: orr w0, wzr, #0x10 166*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: malloc 167*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: strb w{{.*}}, [x0, #8] 168*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: fcmp 169*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: b.le 170*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov x19, x0 171*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: ret 172*9880d681SAndroid Build Coastguard Worker 173*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: foo_loop: 174*9880d681SAndroid Build Coastguard Worker; spill x19 175*9880d681SAndroid Build Coastguard Worker; CHECK-O0: str x19 176*9880d681SAndroid Build Coastguard Worker; CHECk-O0: cbz 177*9880d681SAndroid Build Coastguard Worker; CHECK-O0: orr w{{.*}}, wzr, #0x10 178*9880d681SAndroid Build Coastguard Worker; CHECK-O0: malloc 179*9880d681SAndroid Build Coastguard Worker; CHECK-O0: mov [[ID:x[0-9]+]], x0 180*9880d681SAndroid Build Coastguard Worker; CHECK-O0: strb w{{.*}}, [{{.*}}[[ID]], #8] 181*9880d681SAndroid Build Coastguard Worker; spill x0 182*9880d681SAndroid Build Coastguard Worker; CHECK-O0: str x0 183*9880d681SAndroid Build Coastguard Worker; CHECK-O0: fcmp 184*9880d681SAndroid Build Coastguard Worker; CHECK-O0: b.le 185*9880d681SAndroid Build Coastguard Worker; reload from stack 186*9880d681SAndroid Build Coastguard Worker; CHECK-O0: ldr x19 187*9880d681SAndroid Build Coastguard Worker; CHECK-O0: ret 188*9880d681SAndroid Build Coastguard Workerentry: 189*9880d681SAndroid Build Coastguard Worker br label %bb_loop 190*9880d681SAndroid Build Coastguard Worker 191*9880d681SAndroid Build Coastguard Workerbb_loop: 192*9880d681SAndroid Build Coastguard Worker %cond = icmp ne i32 %cc, 0 193*9880d681SAndroid Build Coastguard Worker br i1 %cond, label %gen_error, label %bb_cont 194*9880d681SAndroid Build Coastguard Worker 195*9880d681SAndroid Build Coastguard Workergen_error: 196*9880d681SAndroid Build Coastguard Worker %call = call i8* @malloc(i64 16) 197*9880d681SAndroid Build Coastguard Worker %call.0 = bitcast i8* %call to %swift_error* 198*9880d681SAndroid Build Coastguard Worker store %swift_error* %call.0, %swift_error** %error_ptr_ref 199*9880d681SAndroid Build Coastguard Worker %tmp = getelementptr inbounds i8, i8* %call, i64 8 200*9880d681SAndroid Build Coastguard Worker store i8 1, i8* %tmp 201*9880d681SAndroid Build Coastguard Worker br label %bb_cont 202*9880d681SAndroid Build Coastguard Worker 203*9880d681SAndroid Build Coastguard Workerbb_cont: 204*9880d681SAndroid Build Coastguard Worker %cmp = fcmp ogt float %cc2, 1.000000e+00 205*9880d681SAndroid Build Coastguard Worker br i1 %cmp, label %bb_end, label %bb_loop 206*9880d681SAndroid Build Coastguard Workerbb_end: 207*9880d681SAndroid Build Coastguard Worker ret float 0.0 208*9880d681SAndroid Build Coastguard Worker} 209*9880d681SAndroid Build Coastguard Worker 210*9880d681SAndroid Build Coastguard Worker%struct.S = type { i32, i32, i32, i32, i32, i32 } 211*9880d681SAndroid Build Coastguard Worker 212*9880d681SAndroid Build Coastguard Worker; "foo_sret" is a function that takes a swifterror parameter, it also has a sret 213*9880d681SAndroid Build Coastguard Worker; parameter. 214*9880d681SAndroid Build Coastguard Workerdefine void @foo_sret(%struct.S* sret %agg.result, i32 %val1, %swift_error** swifterror %error_ptr_ref) { 215*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE-LABEL: foo_sret: 216*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov [[SRET:x[0-9]+]], x8 217*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: orr w0, wzr, #0x10 218*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: malloc 219*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: orr [[ID:w[0-9]+]], wzr, #0x1 220*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: strb [[ID]], [x0, #8] 221*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: str w{{.*}}, [{{.*}}[[SRET]], #4] 222*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov x19, x0 223*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE-NOT: x19 224*9880d681SAndroid Build Coastguard Worker 225*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: foo_sret: 226*9880d681SAndroid Build Coastguard Worker; CHECK-O0: orr w{{.*}}, wzr, #0x10 227*9880d681SAndroid Build Coastguard Worker; spill x8 228*9880d681SAndroid Build Coastguard Worker; CHECK-O0-DAG: str x8 229*9880d681SAndroid Build Coastguard Worker; spill x19 230*9880d681SAndroid Build Coastguard Worker; CHECK-O0-DAG: str x19 231*9880d681SAndroid Build Coastguard Worker; CHECK-O0: malloc 232*9880d681SAndroid Build Coastguard Worker; CHECK-O0: orr [[ID:w[0-9]+]], wzr, #0x1 233*9880d681SAndroid Build Coastguard Worker; CHECK-O0: strb [[ID]], [x0, #8] 234*9880d681SAndroid Build Coastguard Worker; reload from stack 235*9880d681SAndroid Build Coastguard Worker; CHECK-O0: ldr [[SRET:x[0-9]+]] 236*9880d681SAndroid Build Coastguard Worker; CHECK-O0: str w{{.*}}, [{{.*}}[[SRET]], #4] 237*9880d681SAndroid Build Coastguard Worker; CHECK-O0: mov x19 238*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: x19 239*9880d681SAndroid Build Coastguard Workerentry: 240*9880d681SAndroid Build Coastguard Worker %call = call i8* @malloc(i64 16) 241*9880d681SAndroid Build Coastguard Worker %call.0 = bitcast i8* %call to %swift_error* 242*9880d681SAndroid Build Coastguard Worker store %swift_error* %call.0, %swift_error** %error_ptr_ref 243*9880d681SAndroid Build Coastguard Worker %tmp = getelementptr inbounds i8, i8* %call, i64 8 244*9880d681SAndroid Build Coastguard Worker store i8 1, i8* %tmp 245*9880d681SAndroid Build Coastguard Worker %v2 = getelementptr inbounds %struct.S, %struct.S* %agg.result, i32 0, i32 1 246*9880d681SAndroid Build Coastguard Worker store i32 %val1, i32* %v2 247*9880d681SAndroid Build Coastguard Worker ret void 248*9880d681SAndroid Build Coastguard Worker} 249*9880d681SAndroid Build Coastguard Worker 250*9880d681SAndroid Build Coastguard Worker; "caller3" calls "foo_sret" that takes a swifterror parameter. 251*9880d681SAndroid Build Coastguard Workerdefine float @caller3(i8* %error_ref) { 252*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE-LABEL: caller3: 253*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov [[ID:x[0-9]+]], x0 254*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov x19, xzr 255*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: bl {{.*}}foo_sret 256*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: cbnz x19 257*9880d681SAndroid Build Coastguard Worker; Access part of the error object and save it to error_ref 258*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: ldrb [[CODE:w[0-9]+]], [x19, #8] 259*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: strb [[CODE]], [{{.*}}[[ID]]] 260*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov x0, x19 261*9880d681SAndroid Build Coastguard Worker; CHECK_APPLE: bl {{.*}}free 262*9880d681SAndroid Build Coastguard Worker 263*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: caller3: 264*9880d681SAndroid Build Coastguard Worker; spill x0 265*9880d681SAndroid Build Coastguard Worker; CHECK-O0: str x0 266*9880d681SAndroid Build Coastguard Worker; CHECK-O0: mov x19 267*9880d681SAndroid Build Coastguard Worker; CHECK-O0: bl {{.*}}foo_sret 268*9880d681SAndroid Build Coastguard Worker; CHECK-O0: mov [[ID2:x[0-9]+]], x19 269*9880d681SAndroid Build Coastguard Worker; CHECK-O0: cbnz [[ID2]] 270*9880d681SAndroid Build Coastguard Worker; Access part of the error object and save it to error_ref 271*9880d681SAndroid Build Coastguard Worker; reload from stack 272*9880d681SAndroid Build Coastguard Worker; CHECK-O0: ldrb [[CODE:w[0-9]+]] 273*9880d681SAndroid Build Coastguard Worker; CHECK-O0: ldr [[ID:x[0-9]+]] 274*9880d681SAndroid Build Coastguard Worker; CHECK-O0: strb [[CODE]], [{{.*}}[[ID]]] 275*9880d681SAndroid Build Coastguard Worker; CHECK_O0: bl {{.*}}free 276*9880d681SAndroid Build Coastguard Workerentry: 277*9880d681SAndroid Build Coastguard Worker %s = alloca %struct.S, align 8 278*9880d681SAndroid Build Coastguard Worker %error_ptr_ref = alloca swifterror %swift_error* 279*9880d681SAndroid Build Coastguard Worker store %swift_error* null, %swift_error** %error_ptr_ref 280*9880d681SAndroid Build Coastguard Worker call void @foo_sret(%struct.S* sret %s, i32 1, %swift_error** swifterror %error_ptr_ref) 281*9880d681SAndroid Build Coastguard Worker %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref 282*9880d681SAndroid Build Coastguard Worker %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null 283*9880d681SAndroid Build Coastguard Worker %tmp = bitcast %swift_error* %error_from_foo to i8* 284*9880d681SAndroid Build Coastguard Worker br i1 %had_error_from_foo, label %handler, label %cont 285*9880d681SAndroid Build Coastguard Workercont: 286*9880d681SAndroid Build Coastguard Worker %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1 287*9880d681SAndroid Build Coastguard Worker %t = load i8, i8* %v1 288*9880d681SAndroid Build Coastguard Worker store i8 %t, i8* %error_ref 289*9880d681SAndroid Build Coastguard Worker br label %handler 290*9880d681SAndroid Build Coastguard Workerhandler: 291*9880d681SAndroid Build Coastguard Worker call void @free(i8* %tmp) 292*9880d681SAndroid Build Coastguard Worker ret float 1.0 293*9880d681SAndroid Build Coastguard Worker} 294*9880d681SAndroid Build Coastguard Worker 295*9880d681SAndroid Build Coastguard Worker; "foo_vararg" is a function that takes a swifterror parameter, it also has 296*9880d681SAndroid Build Coastguard Worker; variable number of arguments. 297*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.va_start(i8*) nounwind 298*9880d681SAndroid Build Coastguard Workerdefine float @foo_vararg(%swift_error** swifterror %error_ptr_ref, ...) { 299*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE-LABEL: foo_vararg: 300*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: orr w0, wzr, #0x10 301*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: malloc 302*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: orr [[ID:w[0-9]+]], wzr, #0x1 303*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: add [[ARGS:x[0-9]+]], [[TMP:x[0-9]+]], #16 304*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: strb [[ID]], [x0, #8] 305*9880d681SAndroid Build Coastguard Worker 306*9880d681SAndroid Build Coastguard Worker; First vararg 307*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE-DAG: orr {{x[0-9]+}}, [[ARGS]], #0x8 308*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE-DAG: ldr {{w[0-9]+}}, [{{.*}}[[TMP]], #16] 309*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: add {{x[0-9]+}}, {{x[0-9]+}}, #8 310*9880d681SAndroid Build Coastguard Worker; Second vararg 311*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: ldr {{w[0-9]+}}, [{{x[0-9]+}}] 312*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: add {{x[0-9]+}}, {{x[0-9]+}}, #8 313*9880d681SAndroid Build Coastguard Worker; Third vararg 314*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: ldr {{w[0-9]+}}, [{{x[0-9]+}}] 315*9880d681SAndroid Build Coastguard Worker 316*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov x19, x0 317*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE-NOT: x19 318*9880d681SAndroid Build Coastguard Workerentry: 319*9880d681SAndroid Build Coastguard Worker %call = call i8* @malloc(i64 16) 320*9880d681SAndroid Build Coastguard Worker %call.0 = bitcast i8* %call to %swift_error* 321*9880d681SAndroid Build Coastguard Worker store %swift_error* %call.0, %swift_error** %error_ptr_ref 322*9880d681SAndroid Build Coastguard Worker %tmp = getelementptr inbounds i8, i8* %call, i64 8 323*9880d681SAndroid Build Coastguard Worker store i8 1, i8* %tmp 324*9880d681SAndroid Build Coastguard Worker 325*9880d681SAndroid Build Coastguard Worker %args = alloca i8*, align 8 326*9880d681SAndroid Build Coastguard Worker %a10 = alloca i32, align 4 327*9880d681SAndroid Build Coastguard Worker %a11 = alloca i32, align 4 328*9880d681SAndroid Build Coastguard Worker %a12 = alloca i32, align 4 329*9880d681SAndroid Build Coastguard Worker %v10 = bitcast i8** %args to i8* 330*9880d681SAndroid Build Coastguard Worker call void @llvm.va_start(i8* %v10) 331*9880d681SAndroid Build Coastguard Worker %v11 = va_arg i8** %args, i32 332*9880d681SAndroid Build Coastguard Worker store i32 %v11, i32* %a10, align 4 333*9880d681SAndroid Build Coastguard Worker %v12 = va_arg i8** %args, i32 334*9880d681SAndroid Build Coastguard Worker store i32 %v12, i32* %a11, align 4 335*9880d681SAndroid Build Coastguard Worker %v13 = va_arg i8** %args, i32 336*9880d681SAndroid Build Coastguard Worker store i32 %v13, i32* %a12, align 4 337*9880d681SAndroid Build Coastguard Worker 338*9880d681SAndroid Build Coastguard Worker ret float 1.0 339*9880d681SAndroid Build Coastguard Worker} 340*9880d681SAndroid Build Coastguard Worker 341*9880d681SAndroid Build Coastguard Worker; "caller4" calls "foo_vararg" that takes a swifterror parameter. 342*9880d681SAndroid Build Coastguard Workerdefine float @caller4(i8* %error_ref) { 343*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE-LABEL: caller4: 344*9880d681SAndroid Build Coastguard Worker 345*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov [[ID:x[0-9]+]], x0 346*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: stp {{x[0-9]+}}, {{x[0-9]+}}, [sp, #8] 347*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: str {{x[0-9]+}}, [sp] 348*9880d681SAndroid Build Coastguard Worker 349*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov x19, xzr 350*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: bl {{.*}}foo_vararg 351*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: cbnz x19 352*9880d681SAndroid Build Coastguard Worker; Access part of the error object and save it to error_ref 353*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: ldrb [[CODE:w[0-9]+]], [x19, #8] 354*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: strb [[CODE]], [{{.*}}[[ID]]] 355*9880d681SAndroid Build Coastguard Worker; CHECK-APPLE: mov x0, x19 356*9880d681SAndroid Build Coastguard Worker; CHECK_APPLE: bl {{.*}}free 357*9880d681SAndroid Build Coastguard Workerentry: 358*9880d681SAndroid Build Coastguard Worker %error_ptr_ref = alloca swifterror %swift_error* 359*9880d681SAndroid Build Coastguard Worker store %swift_error* null, %swift_error** %error_ptr_ref 360*9880d681SAndroid Build Coastguard Worker 361*9880d681SAndroid Build Coastguard Worker %a10 = alloca i32, align 4 362*9880d681SAndroid Build Coastguard Worker %a11 = alloca i32, align 4 363*9880d681SAndroid Build Coastguard Worker %a12 = alloca i32, align 4 364*9880d681SAndroid Build Coastguard Worker store i32 10, i32* %a10, align 4 365*9880d681SAndroid Build Coastguard Worker store i32 11, i32* %a11, align 4 366*9880d681SAndroid Build Coastguard Worker store i32 12, i32* %a12, align 4 367*9880d681SAndroid Build Coastguard Worker %v10 = load i32, i32* %a10, align 4 368*9880d681SAndroid Build Coastguard Worker %v11 = load i32, i32* %a11, align 4 369*9880d681SAndroid Build Coastguard Worker %v12 = load i32, i32* %a12, align 4 370*9880d681SAndroid Build Coastguard Worker 371*9880d681SAndroid Build Coastguard Worker %call = call float (%swift_error**, ...) @foo_vararg(%swift_error** swifterror %error_ptr_ref, i32 %v10, i32 %v11, i32 %v12) 372*9880d681SAndroid Build Coastguard Worker %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref 373*9880d681SAndroid Build Coastguard Worker %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null 374*9880d681SAndroid Build Coastguard Worker %tmp = bitcast %swift_error* %error_from_foo to i8* 375*9880d681SAndroid Build Coastguard Worker br i1 %had_error_from_foo, label %handler, label %cont 376*9880d681SAndroid Build Coastguard Worker 377*9880d681SAndroid Build Coastguard Workercont: 378*9880d681SAndroid Build Coastguard Worker %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1 379*9880d681SAndroid Build Coastguard Worker %t = load i8, i8* %v1 380*9880d681SAndroid Build Coastguard Worker store i8 %t, i8* %error_ref 381*9880d681SAndroid Build Coastguard Worker br label %handler 382*9880d681SAndroid Build Coastguard Workerhandler: 383*9880d681SAndroid Build Coastguard Worker call void @free(i8* %tmp) 384*9880d681SAndroid Build Coastguard Worker ret float 1.0 385*9880d681SAndroid Build Coastguard Worker} 386