121 lines · plain
1; RUN: opt -passes=objc-arc -S < %s | FileCheck %s2; rdar://112299253 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 !014; CHECK: call void @llvm.objc.release(ptr %tmp7) [[NUW]], !clang.imprecise_release !015; CHECK: }16define void @test0() nounwind {17entry:18 %weakLogNTimes = alloca %struct.__block_byref_weakLogNTimes, align 819 %block = alloca <{ ptr, i32, i32, ptr, ptr, ptr }>, align 820 store ptr null, ptr %weakLogNTimes, align 821 %byref.forwarding = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 122 store ptr %weakLogNTimes, ptr %byref.forwarding, align 823 %byref.flags = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 224 store i32 33554432, ptr %byref.flags, align 825 %byref.size = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 326 store i32 48, ptr %byref.size, align 427 %tmp1 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 428 store ptr @__Block_byref_object_copy_, ptr %tmp1, align 829 %tmp2 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 530 store ptr @__Block_byref_object_dispose_, ptr %tmp2, align 831 %weakLogNTimes1 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 632 %tmp4 = call ptr @llvm.objc.initWeak(ptr %weakLogNTimes1, ptr null) nounwind33 %block.isa = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 034 store ptr null, ptr %block.isa, align 835 %block.flags = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 136 store i32 1107296256, ptr %block.flags, align 837 %block.reserved = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 238 store i32 0, ptr %block.reserved, align 439 %block.invoke = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 340 store ptr @__main_block_invoke_0, ptr %block.invoke, align 841 %block.descriptor = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 442 store ptr null, ptr %block.descriptor, align 843 %block.captured = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 544 store ptr %weakLogNTimes, ptr %block.captured, align 845 %tmp7 = call ptr @llvm.objc.retainBlock(ptr %block) nounwind, !clang.arc.copy_on_escape !046 %tmp8 = load ptr, ptr %byref.forwarding, align 847 %weakLogNTimes3 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %tmp8, i64 0, i32 648 %tmp10 = call ptr @llvm.objc.storeWeak(ptr %weakLogNTimes3, ptr %tmp7) nounwind49 %tmp11 = getelementptr inbounds i8, ptr %tmp7, i64 1650 %tmp13 = load ptr, ptr %tmp11, align 851 call void %tmp13(ptr %tmp7, i32 10) nounwind, !clang.arc.no_objc_arc_exceptions !052 call void @llvm.objc.release(ptr %tmp7) nounwind, !clang.imprecise_release !053 call void @_Block_object_dispose(ptr %weakLogNTimes, i32 8) nounwind54 call void @llvm.objc.destroyWeak(ptr %weakLogNTimes1) nounwind55 ret void56}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.retainBlock63; CHECK: }64define void @test1() nounwind {65entry:66 %weakLogNTimes = alloca %struct.__block_byref_weakLogNTimes, align 867 %block = alloca <{ ptr, i32, i32, ptr, ptr, ptr }>, align 868 store ptr null, ptr %weakLogNTimes, align 869 %byref.forwarding = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 170 store ptr %weakLogNTimes, ptr %byref.forwarding, align 871 %byref.flags = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 272 store i32 33554432, ptr %byref.flags, align 873 %byref.size = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 374 store i32 48, ptr %byref.size, align 475 %tmp1 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 476 store ptr @__Block_byref_object_copy_, ptr %tmp1, align 877 %tmp2 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 578 store ptr @__Block_byref_object_dispose_, ptr %tmp2, align 879 %weakLogNTimes1 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %weakLogNTimes, i64 0, i32 680 %tmp4 = call ptr @llvm.objc.initWeak(ptr %weakLogNTimes1, ptr null) nounwind81 %block.isa = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 082 store ptr null, ptr %block.isa, align 883 %block.flags = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 184 store i32 1107296256, ptr %block.flags, align 885 %block.reserved = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 286 store i32 0, ptr %block.reserved, align 487 %block.invoke = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 388 store ptr @__main_block_invoke_0, ptr %block.invoke, align 889 %block.descriptor = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 490 store ptr null, ptr %block.descriptor, align 891 %block.captured = getelementptr inbounds <{ ptr, i32, i32, ptr, ptr, ptr }>, ptr %block, i64 0, i32 592 store ptr %weakLogNTimes, ptr %block.captured, align 893 %tmp7 = call ptr @llvm.objc.retainBlock(ptr %block) nounwind, !clang.arc.copy_on_escape !094 %tmp8 = load ptr, ptr %byref.forwarding, align 895 %weakLogNTimes3 = getelementptr inbounds %struct.__block_byref_weakLogNTimes, ptr %tmp8, i64 0, i32 696 %tmp10 = call ptr @not_really_objc_storeWeak(ptr %weakLogNTimes3, ptr %tmp7) nounwind97 %tmp11 = getelementptr inbounds i8, ptr %tmp7, i64 1698 %tmp13 = load ptr, ptr %tmp11, align 899 call void %tmp13(ptr %tmp7, i32 10) nounwind, !clang.arc.no_objc_arc_exceptions !0100 call void @llvm.objc.release(ptr %tmp7) nounwind, !clang.imprecise_release !0101 call void @_Block_object_dispose(ptr %weakLogNTimes, i32 8) nounwind102 call void @llvm.objc.destroyWeak(ptr %weakLogNTimes1) nounwind103 ret void104}105 106declare void @__Block_byref_object_copy_(ptr, ptr) nounwind107declare void @__Block_byref_object_dispose_(ptr) nounwind108declare void @llvm.objc.destroyWeak(ptr)109declare ptr @llvm.objc.initWeak(ptr, ptr)110declare void @__main_block_invoke_0(ptr nocapture, i32) nounwind ssp111declare 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