• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -S -objc-arc < %s | FileCheck %s
2
3target 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"
4%struct.__block_byref_x = type { i8*, %struct.__block_byref_x*, i32, i32, i32 }
5%struct.__block_descriptor = type { i64, i64 }
6@_NSConcreteStackBlock = external global i8*
7@__block_descriptor_tmp = external hidden constant { i64, i64, i8*, i8*, i8*, i8* }
8
9; The optimizer should make use of the !clang.arc.no_objc_arc_exceptions
10; metadata and eliminate the retainBlock+release pair here.
11; rdar://10803830.
12
13; CHECK: define void @test0(
14; CHECK-NOT: @objc
15; CHECK: }
16define void @test0() {
17entry:
18  %x = alloca %struct.__block_byref_x, align 8
19  %block = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, align 8
20  %byref.isa = getelementptr inbounds %struct.__block_byref_x* %x, i64 0, i32 0
21  store i8* null, i8** %byref.isa, align 8
22  %byref.forwarding = getelementptr inbounds %struct.__block_byref_x* %x, i64 0, i32 1
23  store %struct.__block_byref_x* %x, %struct.__block_byref_x** %byref.forwarding, align 8
24  %byref.flags = getelementptr inbounds %struct.__block_byref_x* %x, i64 0, i32 2
25  store i32 0, i32* %byref.flags, align 8
26  %byref.size = getelementptr inbounds %struct.__block_byref_x* %x, i64 0, i32 3
27  store i32 32, i32* %byref.size, align 4
28  %block.isa = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 0
29  store i8* bitcast (i8** @_NSConcreteStackBlock to i8*), i8** %block.isa, align 8
30  %block.flags = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 1
31  store i32 1107296256, i32* %block.flags, align 8
32  %block.reserved = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 2
33  store i32 0, i32* %block.reserved, align 4
34  %block.invoke = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 3
35  store i8* bitcast (void (i8*)* @__foo_block_invoke_0 to i8*), i8** %block.invoke, align 8
36  %block.descriptor = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 4
37  store %struct.__block_descriptor* bitcast ({ i64, i64, i8*, i8*, i8*, i8* }* @__block_descriptor_tmp to %struct.__block_descriptor*), %struct.__block_descriptor** %block.descriptor, align 8
38  %block.captured = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 5
39  %t1 = bitcast %struct.__block_byref_x* %x to i8*
40  store i8* %t1, i8** %block.captured, align 8
41  %t2 = bitcast <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block to i8*
42  %t3 = call i8* @objc_retainBlock(i8* %t2) nounwind, !clang.arc.copy_on_escape !4
43  %t4 = getelementptr inbounds i8* %t3, i64 16
44  %t5 = bitcast i8* %t4 to i8**
45  %t6 = load i8** %t5, align 8
46  %t7 = bitcast i8* %t6 to void (i8*)*
47  invoke void %t7(i8* %t3)
48          to label %invoke.cont unwind label %lpad, !clang.arc.no_objc_arc_exceptions !4
49
50invoke.cont:                                      ; preds = %entry
51  call void @objc_release(i8* %t3) nounwind, !clang.imprecise_release !4
52  call void @_Block_object_dispose(i8* %t1, i32 8)
53  ret void
54
55lpad:                                             ; preds = %entry
56  %t8 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__objc_personality_v0 to i8*)
57          cleanup
58  call void @_Block_object_dispose(i8* %t1, i32 8)
59  resume { i8*, i32 } %t8
60}
61
62; There is no !clang.arc.no_objc_arc_exceptions
63; metadata here, so the optimizer shouldn't eliminate anything.
64
65; CHECK: define void @test0_no_metadata(
66; CHECK: call i8* @objc_retainBlock(
67; CHECK: invoke
68; CHECK: call void @objc_release(
69; CHECK: }
70define void @test0_no_metadata() {
71entry:
72  %x = alloca %struct.__block_byref_x, align 8
73  %block = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>, align 8
74  %byref.isa = getelementptr inbounds %struct.__block_byref_x* %x, i64 0, i32 0
75  store i8* null, i8** %byref.isa, align 8
76  %byref.forwarding = getelementptr inbounds %struct.__block_byref_x* %x, i64 0, i32 1
77  store %struct.__block_byref_x* %x, %struct.__block_byref_x** %byref.forwarding, align 8
78  %byref.flags = getelementptr inbounds %struct.__block_byref_x* %x, i64 0, i32 2
79  store i32 0, i32* %byref.flags, align 8
80  %byref.size = getelementptr inbounds %struct.__block_byref_x* %x, i64 0, i32 3
81  store i32 32, i32* %byref.size, align 4
82  %block.isa = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 0
83  store i8* bitcast (i8** @_NSConcreteStackBlock to i8*), i8** %block.isa, align 8
84  %block.flags = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 1
85  store i32 1107296256, i32* %block.flags, align 8
86  %block.reserved = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 2
87  store i32 0, i32* %block.reserved, align 4
88  %block.invoke = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 3
89  store i8* bitcast (void (i8*)* @__foo_block_invoke_0 to i8*), i8** %block.invoke, align 8
90  %block.descriptor = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 4
91  store %struct.__block_descriptor* bitcast ({ i64, i64, i8*, i8*, i8*, i8* }* @__block_descriptor_tmp to %struct.__block_descriptor*), %struct.__block_descriptor** %block.descriptor, align 8
92  %block.captured = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block, i64 0, i32 5
93  %t1 = bitcast %struct.__block_byref_x* %x to i8*
94  store i8* %t1, i8** %block.captured, align 8
95  %t2 = bitcast <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }>* %block to i8*
96  %t3 = call i8* @objc_retainBlock(i8* %t2) nounwind, !clang.arc.copy_on_escape !4
97  %t4 = getelementptr inbounds i8* %t3, i64 16
98  %t5 = bitcast i8* %t4 to i8**
99  %t6 = load i8** %t5, align 8
100  %t7 = bitcast i8* %t6 to void (i8*)*
101  invoke void %t7(i8* %t3)
102          to label %invoke.cont unwind label %lpad
103
104invoke.cont:                                      ; preds = %entry
105  call void @objc_release(i8* %t3) nounwind, !clang.imprecise_release !4
106  call void @_Block_object_dispose(i8* %t1, i32 8)
107  ret void
108
109lpad:                                             ; preds = %entry
110  %t8 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__objc_personality_v0 to i8*)
111          cleanup
112  call void @_Block_object_dispose(i8* %t1, i32 8)
113  resume { i8*, i32 } %t8
114}
115
116declare i8* @objc_retainBlock(i8*)
117declare void @objc_release(i8*)
118declare void @_Block_object_dispose(i8*, i32)
119declare i32 @__objc_personality_v0(...)
120declare void @__foo_block_invoke_0(i8* nocapture) uwtable ssp
121
122!4 = metadata !{}
123