1*9880d681SAndroid Build Coastguard Worker; RUN: opt -objc-arc -S < %s | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker; rdar://11229925 3*9880d681SAndroid Build Coastguard Worker 4*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" 5*9880d681SAndroid Build Coastguard Worker 6*9880d681SAndroid Build Coastguard Worker%struct.__block_byref_weakLogNTimes = type { i8*, %struct.__block_byref_weakLogNTimes*, i32, i32, i8*, i8*, void (...)* } 7*9880d681SAndroid Build Coastguard Worker%struct.__block_descriptor = type { i64, i64 } 8*9880d681SAndroid Build Coastguard Worker 9*9880d681SAndroid Build Coastguard Worker; Don't optimize away the retainBlock, because the object's address "escapes" 10*9880d681SAndroid Build Coastguard Worker; with the objc_storeWeak call. 11*9880d681SAndroid Build Coastguard Worker 12*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: define void @test0( 13*9880d681SAndroid Build Coastguard Worker; CHECK: %tmp7 = call i8* @objc_retainBlock(i8* %tmp6) [[NUW:#[0-9]+]], !clang.arc.copy_on_escape !0 14*9880d681SAndroid Build Coastguard Worker; CHECK: call void @objc_release(i8* %tmp7) [[NUW]], !clang.imprecise_release !0 15*9880d681SAndroid Build Coastguard Worker; CHECK: } 16*9880d681SAndroid Build Coastguard Workerdefine void @test0() nounwind { 17*9880d681SAndroid Build Coastguard Workerentry: 18*9880d681SAndroid Build Coastguard Worker %weakLogNTimes = alloca %struct.__block_byref_weakLogNTimes, align 8 19*9880d681SAndroid Build Coastguard Worker %block = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, align 8 20*9880d681SAndroid Build Coastguard Worker %byref.isa = getelementptr inbounds %struct.__block_byref_weakLogNTimes, %struct.__block_byref_weakLogNTimes* %weakLogNTimes, i64 0, i32 0 21*9880d681SAndroid Build Coastguard Worker store i8* null, i8** %byref.isa, align 8 22*9880d681SAndroid Build Coastguard Worker %byref.forwarding = getelementptr inbounds %struct.__block_byref_weakLogNTimes, %struct.__block_byref_weakLogNTimes* %weakLogNTimes, i64 0, i32 1 23*9880d681SAndroid Build Coastguard Worker store %struct.__block_byref_weakLogNTimes* %weakLogNTimes, %struct.__block_byref_weakLogNTimes** %byref.forwarding, align 8 24*9880d681SAndroid Build Coastguard Worker %byref.flags = getelementptr inbounds %struct.__block_byref_weakLogNTimes, %struct.__block_byref_weakLogNTimes* %weakLogNTimes, i64 0, i32 2 25*9880d681SAndroid Build Coastguard Worker store i32 33554432, i32* %byref.flags, align 8 26*9880d681SAndroid Build Coastguard Worker %byref.size = getelementptr inbounds %struct.__block_byref_weakLogNTimes, %struct.__block_byref_weakLogNTimes* %weakLogNTimes, i64 0, i32 3 27*9880d681SAndroid Build Coastguard Worker store i32 48, i32* %byref.size, align 4 28*9880d681SAndroid Build Coastguard Worker %tmp1 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, %struct.__block_byref_weakLogNTimes* %weakLogNTimes, i64 0, i32 4 29*9880d681SAndroid Build Coastguard Worker store i8* bitcast (void (i8*, i8*)* @__Block_byref_object_copy_ to i8*), i8** %tmp1, align 8 30*9880d681SAndroid Build Coastguard Worker %tmp2 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, %struct.__block_byref_weakLogNTimes* %weakLogNTimes, i64 0, i32 5 31*9880d681SAndroid Build Coastguard Worker store i8* bitcast (void (i8*)* @__Block_byref_object_dispose_ to i8*), i8** %tmp2, align 8 32*9880d681SAndroid Build Coastguard Worker %weakLogNTimes1 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, %struct.__block_byref_weakLogNTimes* %weakLogNTimes, i64 0, i32 6 33*9880d681SAndroid Build Coastguard Worker %tmp3 = bitcast void (...)** %weakLogNTimes1 to i8** 34*9880d681SAndroid Build Coastguard Worker %tmp4 = call i8* @objc_initWeak(i8** %tmp3, i8* null) nounwind 35*9880d681SAndroid Build Coastguard Worker %block.isa = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 0 36*9880d681SAndroid Build Coastguard Worker store i8* null, i8** %block.isa, align 8 37*9880d681SAndroid Build Coastguard Worker %block.flags = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 1 38*9880d681SAndroid Build Coastguard Worker store i32 1107296256, i32* %block.flags, align 8 39*9880d681SAndroid Build Coastguard Worker %block.reserved = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 2 40*9880d681SAndroid Build Coastguard Worker store i32 0, i32* %block.reserved, align 4 41*9880d681SAndroid Build Coastguard Worker %block.invoke = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 3 42*9880d681SAndroid Build Coastguard Worker store i8* bitcast (void (i8*, i32)* @__main_block_invoke_0 to i8*), i8** %block.invoke, align 8 43*9880d681SAndroid Build Coastguard Worker %block.descriptor = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 4 44*9880d681SAndroid Build Coastguard Worker store %struct.__block_descriptor* null, %struct.__block_descriptor** %block.descriptor, align 8 45*9880d681SAndroid Build Coastguard Worker %block.captured = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 5 46*9880d681SAndroid Build Coastguard Worker %tmp5 = bitcast %struct.__block_byref_weakLogNTimes* %weakLogNTimes to i8* 47*9880d681SAndroid Build Coastguard Worker store i8* %tmp5, i8** %block.captured, align 8 48*9880d681SAndroid Build Coastguard Worker %tmp6 = bitcast <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block to i8* 49*9880d681SAndroid Build Coastguard Worker %tmp7 = call i8* @objc_retainBlock(i8* %tmp6) nounwind, !clang.arc.copy_on_escape !0 50*9880d681SAndroid Build Coastguard Worker %tmp8 = load %struct.__block_byref_weakLogNTimes*, %struct.__block_byref_weakLogNTimes** %byref.forwarding, align 8 51*9880d681SAndroid Build Coastguard Worker %weakLogNTimes3 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, %struct.__block_byref_weakLogNTimes* %tmp8, i64 0, i32 6 52*9880d681SAndroid Build Coastguard Worker %tmp9 = bitcast void (...)** %weakLogNTimes3 to i8** 53*9880d681SAndroid Build Coastguard Worker %tmp10 = call i8* @objc_storeWeak(i8** %tmp9, i8* %tmp7) nounwind 54*9880d681SAndroid Build Coastguard Worker %tmp11 = getelementptr inbounds i8, i8* %tmp7, i64 16 55*9880d681SAndroid Build Coastguard Worker %tmp12 = bitcast i8* %tmp11 to i8** 56*9880d681SAndroid Build Coastguard Worker %tmp13 = load i8*, i8** %tmp12, align 8 57*9880d681SAndroid Build Coastguard Worker %tmp14 = bitcast i8* %tmp13 to void (i8*, i32)* 58*9880d681SAndroid Build Coastguard Worker call void %tmp14(i8* %tmp7, i32 10) nounwind, !clang.arc.no_objc_arc_exceptions !0 59*9880d681SAndroid Build Coastguard Worker call void @objc_release(i8* %tmp7) nounwind, !clang.imprecise_release !0 60*9880d681SAndroid Build Coastguard Worker call void @_Block_object_dispose(i8* %tmp5, i32 8) nounwind 61*9880d681SAndroid Build Coastguard Worker call void @objc_destroyWeak(i8** %tmp3) nounwind 62*9880d681SAndroid Build Coastguard Worker ret void 63*9880d681SAndroid Build Coastguard Worker} 64*9880d681SAndroid Build Coastguard Worker 65*9880d681SAndroid Build Coastguard Worker; Like test0, but it makes a regular call instead of a storeWeak call, 66*9880d681SAndroid Build Coastguard Worker; so the optimization is valid. 67*9880d681SAndroid Build Coastguard Worker 68*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: define void @test1( 69*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: @objc_retainBlock 70*9880d681SAndroid Build Coastguard Worker; CHECK: } 71*9880d681SAndroid Build Coastguard Workerdefine void @test1() nounwind { 72*9880d681SAndroid Build Coastguard Workerentry: 73*9880d681SAndroid Build Coastguard Worker %weakLogNTimes = alloca %struct.__block_byref_weakLogNTimes, align 8 74*9880d681SAndroid Build Coastguard Worker %block = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, align 8 75*9880d681SAndroid Build Coastguard Worker %byref.isa = getelementptr inbounds %struct.__block_byref_weakLogNTimes, %struct.__block_byref_weakLogNTimes* %weakLogNTimes, i64 0, i32 0 76*9880d681SAndroid Build Coastguard Worker store i8* null, i8** %byref.isa, align 8 77*9880d681SAndroid Build Coastguard Worker %byref.forwarding = getelementptr inbounds %struct.__block_byref_weakLogNTimes, %struct.__block_byref_weakLogNTimes* %weakLogNTimes, i64 0, i32 1 78*9880d681SAndroid Build Coastguard Worker store %struct.__block_byref_weakLogNTimes* %weakLogNTimes, %struct.__block_byref_weakLogNTimes** %byref.forwarding, align 8 79*9880d681SAndroid Build Coastguard Worker %byref.flags = getelementptr inbounds %struct.__block_byref_weakLogNTimes, %struct.__block_byref_weakLogNTimes* %weakLogNTimes, i64 0, i32 2 80*9880d681SAndroid Build Coastguard Worker store i32 33554432, i32* %byref.flags, align 8 81*9880d681SAndroid Build Coastguard Worker %byref.size = getelementptr inbounds %struct.__block_byref_weakLogNTimes, %struct.__block_byref_weakLogNTimes* %weakLogNTimes, i64 0, i32 3 82*9880d681SAndroid Build Coastguard Worker store i32 48, i32* %byref.size, align 4 83*9880d681SAndroid Build Coastguard Worker %tmp1 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, %struct.__block_byref_weakLogNTimes* %weakLogNTimes, i64 0, i32 4 84*9880d681SAndroid Build Coastguard Worker store i8* bitcast (void (i8*, i8*)* @__Block_byref_object_copy_ to i8*), i8** %tmp1, align 8 85*9880d681SAndroid Build Coastguard Worker %tmp2 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, %struct.__block_byref_weakLogNTimes* %weakLogNTimes, i64 0, i32 5 86*9880d681SAndroid Build Coastguard Worker store i8* bitcast (void (i8*)* @__Block_byref_object_dispose_ to i8*), i8** %tmp2, align 8 87*9880d681SAndroid Build Coastguard Worker %weakLogNTimes1 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, %struct.__block_byref_weakLogNTimes* %weakLogNTimes, i64 0, i32 6 88*9880d681SAndroid Build Coastguard Worker %tmp3 = bitcast void (...)** %weakLogNTimes1 to i8** 89*9880d681SAndroid Build Coastguard Worker %tmp4 = call i8* @objc_initWeak(i8** %tmp3, i8* null) nounwind 90*9880d681SAndroid Build Coastguard Worker %block.isa = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 0 91*9880d681SAndroid Build Coastguard Worker store i8* null, i8** %block.isa, align 8 92*9880d681SAndroid Build Coastguard Worker %block.flags = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 1 93*9880d681SAndroid Build Coastguard Worker store i32 1107296256, i32* %block.flags, align 8 94*9880d681SAndroid Build Coastguard Worker %block.reserved = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 2 95*9880d681SAndroid Build Coastguard Worker store i32 0, i32* %block.reserved, align 4 96*9880d681SAndroid Build Coastguard Worker %block.invoke = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 3 97*9880d681SAndroid Build Coastguard Worker store i8* bitcast (void (i8*, i32)* @__main_block_invoke_0 to i8*), i8** %block.invoke, align 8 98*9880d681SAndroid Build Coastguard Worker %block.descriptor = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 4 99*9880d681SAndroid Build Coastguard Worker store %struct.__block_descriptor* null, %struct.__block_descriptor** %block.descriptor, align 8 100*9880d681SAndroid Build Coastguard Worker %block.captured = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 5 101*9880d681SAndroid Build Coastguard Worker %tmp5 = bitcast %struct.__block_byref_weakLogNTimes* %weakLogNTimes to i8* 102*9880d681SAndroid Build Coastguard Worker store i8* %tmp5, i8** %block.captured, align 8 103*9880d681SAndroid Build Coastguard Worker %tmp6 = bitcast <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block to i8* 104*9880d681SAndroid Build Coastguard Worker %tmp7 = call i8* @objc_retainBlock(i8* %tmp6) nounwind, !clang.arc.copy_on_escape !0 105*9880d681SAndroid Build Coastguard Worker %tmp8 = load %struct.__block_byref_weakLogNTimes*, %struct.__block_byref_weakLogNTimes** %byref.forwarding, align 8 106*9880d681SAndroid Build Coastguard Worker %weakLogNTimes3 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, %struct.__block_byref_weakLogNTimes* %tmp8, i64 0, i32 6 107*9880d681SAndroid Build Coastguard Worker %tmp9 = bitcast void (...)** %weakLogNTimes3 to i8** 108*9880d681SAndroid Build Coastguard Worker %tmp10 = call i8* @not_really_objc_storeWeak(i8** %tmp9, i8* %tmp7) nounwind 109*9880d681SAndroid Build Coastguard Worker %tmp11 = getelementptr inbounds i8, i8* %tmp7, i64 16 110*9880d681SAndroid Build Coastguard Worker %tmp12 = bitcast i8* %tmp11 to i8** 111*9880d681SAndroid Build Coastguard Worker %tmp13 = load i8*, i8** %tmp12, align 8 112*9880d681SAndroid Build Coastguard Worker %tmp14 = bitcast i8* %tmp13 to void (i8*, i32)* 113*9880d681SAndroid Build Coastguard Worker call void %tmp14(i8* %tmp7, i32 10) nounwind, !clang.arc.no_objc_arc_exceptions !0 114*9880d681SAndroid Build Coastguard Worker call void @objc_release(i8* %tmp7) nounwind, !clang.imprecise_release !0 115*9880d681SAndroid Build Coastguard Worker call void @_Block_object_dispose(i8* %tmp5, i32 8) nounwind 116*9880d681SAndroid Build Coastguard Worker call void @objc_destroyWeak(i8** %tmp3) nounwind 117*9880d681SAndroid Build Coastguard Worker ret void 118*9880d681SAndroid Build Coastguard Worker} 119*9880d681SAndroid Build Coastguard Worker 120*9880d681SAndroid Build Coastguard Workerdeclare void @__Block_byref_object_copy_(i8*, i8*) nounwind 121*9880d681SAndroid Build Coastguard Workerdeclare void @__Block_byref_object_dispose_(i8*) nounwind 122*9880d681SAndroid Build Coastguard Workerdeclare void @objc_destroyWeak(i8**) 123*9880d681SAndroid Build Coastguard Workerdeclare i8* @objc_initWeak(i8**, i8*) 124*9880d681SAndroid Build Coastguard Workerdeclare void @__main_block_invoke_0(i8* nocapture, i32) nounwind ssp 125*9880d681SAndroid Build Coastguard Workerdeclare void @_Block_object_dispose(i8*, i32) 126*9880d681SAndroid Build Coastguard Workerdeclare i8* @objc_retainBlock(i8*) 127*9880d681SAndroid Build Coastguard Workerdeclare i8* @objc_storeWeak(i8**, i8*) 128*9880d681SAndroid Build Coastguard Workerdeclare i8* @not_really_objc_storeWeak(i8**, i8*) 129*9880d681SAndroid Build Coastguard Workerdeclare void @objc_release(i8*) 130*9880d681SAndroid Build Coastguard Worker 131*9880d681SAndroid Build Coastguard Worker!0 = !{} 132*9880d681SAndroid Build Coastguard Worker 133*9880d681SAndroid Build Coastguard Worker; CHECK: attributes [[NUW]] = { nounwind } 134*9880d681SAndroid Build Coastguard Worker; CHECK: attributes #1 = { nounwind ssp } 135