1; RUN: opt -passes=objc-arc -S < %s | FileCheck %s 2; rdar://11229925 3 4target 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 6%struct.__block_byref_weakLogNTimes = type { ptr, ptr, i32, i32, ptr, ptr, ptr } 7%struct.__block_descriptor = type { i64, i64 } 8 9; Don't optimize away the retainBlock, because the object's address "escapes" 10; with the objc_storeWeak call. 11 12; CHECK-LABEL: define void @test0( 13; CHECK: %tmp7 = call ptr @llvm.objc.retainBlock(ptr %block) [[NUW:#[0-9]+]], !clang.arc.copy_on_escape !0 14; CHECK: call void @llvm.objc.release(ptr %tmp7) [[NUW]], !clang.imprecise_release !0 15; CHECK: } 16define void @test0() nounwind { 17entry: 18 %weakLogNTimes = alloca %struct.__block_byref_weakLogNTimes, align 8 19 %block = alloca <{ ptr, i32, i32, ptr, ptr, ptr }>, align 8 20 store ptr null, ptr %weakLogNTimes, align 8 21 %byref.forwarding = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 1 22 store ptr %weakLogNTimes, ptr %byref.forwarding, align 8 23 %byref.flags = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 2 24 store i32 33554432, ptr %byref.flags, align 8 25 %byref.size = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 3 26 store i32 48, ptr %byref.size, align 4 27 %tmp1 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 4 28 store ptr @__Block_byref_object_copy_, ptr %tmp1, align 8 29 %tmp2 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 5 30 store ptr @__Block_byref_object_dispose_, ptr %tmp2, align 8 31 %weakLogNTimes1 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 6 32 %tmp4 = call ptr @llvm.objc.initWeak(ptr %weakLogNTimes1, ptr null) nounwind 33 %block.isa = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 0 34 store ptr null, ptr %block.isa, align 8 35 %block.flags = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 1 36 store i32 1107296256, ptr %block.flags, align 8 37 %block.reserved = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 2 38 store i32 0, ptr %block.reserved, align 4 39 %block.invoke = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 3 40 store ptr @__main_block_invoke_0, ptr %block.invoke, align 8 41 %block.descriptor = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 4 42 store ptr null, ptr %block.descriptor, align 8 43 %block.captured = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 5 44 store ptr %weakLogNTimes, ptr %block.captured, align 8 45 %tmp7 = call ptr @llvm.objc.retainBlock(ptr %block) nounwind, !clang.arc.copy_on_escape !0 46 %tmp8 = load ptr, ptr %byref.forwarding, align 8 47 %weakLogNTimes3 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %tmp8, i64 0, i32 6 48 %tmp10 = call ptr @llvm.objc.storeWeak(ptr %weakLogNTimes3, ptr %tmp7) nounwind 49 %tmp11 = getelementptr inbounds i8, ptr %tmp7, i64 16 50 %tmp13 = load ptr, ptr %tmp11, align 8 51 call void %tmp13(ptr %tmp7, i32 10) nounwind, !clang.arc.no_objc_arc_exceptions !0 52 call void @llvm.objc.release(ptr %tmp7) nounwind, !clang.imprecise_release !0 53 call void @_Block_object_dispose(ptr %weakLogNTimes, i32 8) nounwind 54 call void @llvm.objc.destroyWeak(ptr %weakLogNTimes1) nounwind 55 ret void 56} 57 58; Like test0, but it makes a regular call instead of a storeWeak call, 59; so the optimization is valid. 60 61; CHECK-LABEL: define void @test1( 62; CHECK-NOT: @llvm.objc.retainBlock 63; CHECK: } 64define void @test1() nounwind { 65entry: 66 %weakLogNTimes = alloca %struct.__block_byref_weakLogNTimes, align 8 67 %block = alloca <{ ptr, i32, i32, ptr, ptr, ptr }>, align 8 68 store ptr null, ptr %weakLogNTimes, align 8 69 %byref.forwarding = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 1 70 store ptr %weakLogNTimes, ptr %byref.forwarding, align 8 71 %byref.flags = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 2 72 store i32 33554432, ptr %byref.flags, align 8 73 %byref.size = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 3 74 store i32 48, ptr %byref.size, align 4 75 %tmp1 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 4 76 store ptr @__Block_byref_object_copy_, ptr %tmp1, align 8 77 %tmp2 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 5 78 store ptr @__Block_byref_object_dispose_, ptr %tmp2, align 8 79 %weakLogNTimes1 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 6 80 %tmp4 = call ptr @llvm.objc.initWeak(ptr %weakLogNTimes1, ptr null) nounwind 81 %block.isa = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 0 82 store ptr null, ptr %block.isa, align 8 83 %block.flags = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 1 84 store i32 1107296256, ptr %block.flags, align 8 85 %block.reserved = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 2 86 store i32 0, ptr %block.reserved, align 4 87 %block.invoke = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 3 88 store ptr @__main_block_invoke_0, ptr %block.invoke, align 8 89 %block.descriptor = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 4 90 store ptr null, ptr %block.descriptor, align 8 91 %block.captured = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 5 92 store ptr %weakLogNTimes, ptr %block.captured, align 8 93 %tmp7 = call ptr @llvm.objc.retainBlock(ptr %block) nounwind, !clang.arc.copy_on_escape !0 94 %tmp8 = load ptr, ptr %byref.forwarding, align 8 95 %weakLogNTimes3 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %tmp8, i64 0, i32 6 96 %tmp10 = call ptr @not_really_objc_storeWeak(ptr %weakLogNTimes3, ptr %tmp7) nounwind 97 %tmp11 = getelementptr inbounds i8, ptr %tmp7, i64 16 98 %tmp13 = load ptr, ptr %tmp11, align 8 99 call void %tmp13(ptr %tmp7, i32 10) nounwind, !clang.arc.no_objc_arc_exceptions !0 100 call void @llvm.objc.release(ptr %tmp7) nounwind, !clang.imprecise_release !0 101 call void @_Block_object_dispose(ptr %weakLogNTimes, i32 8) nounwind 102 call void @llvm.objc.destroyWeak(ptr %weakLogNTimes1) nounwind 103 ret void 104} 105 106declare void @__Block_byref_object_copy_(ptr, ptr) nounwind 107declare void @__Block_byref_object_dispose_(ptr) nounwind 108declare void @llvm.objc.destroyWeak(ptr) 109declare ptr @llvm.objc.initWeak(ptr, ptr) 110declare void @__main_block_invoke_0(ptr nocapture, i32) nounwind ssp 111declare void @_Block_object_dispose(ptr, i32) 112declare ptr @llvm.objc.retainBlock(ptr) 113declare ptr @llvm.objc.storeWeak(ptr, ptr) 114declare ptr @not_really_objc_storeWeak(ptr, ptr) 115declare void @llvm.objc.release(ptr) 116 117!0 = !{} 118 119; CHECK: attributes [[NUW]] = { nounwind } 120; CHECK: attributes #1 = { nounwind ssp } 121