aboutsummaryrefslogtreecommitdiffstats
path: root/test/Transforms/ObjCARC/retain-block-alloca.ll
blob: 6b1578aea4297ab82089b45c8c02abea902f9f28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
; RUN: opt -S -objc-arc < %s | FileCheck %s
; rdar://10209613

%0 = type opaque
%struct.__block_descriptor = type { i64, i64 }

@_NSConcreteStackBlock = external global i8*
@__block_descriptor_tmp = external hidden constant { i64, i64, i8*, i8*, i8*, i8* }
@"\01L_OBJC_SELECTOR_REFERENCES_" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"

; CHECK-LABEL: define void @test(
; CHECK: %3 = call i8* @objc_retainBlock(i8* %2) [[NUW:#[0-9]+]]
; CHECK: @objc_msgSend
; CHECK-NEXT: @objc_release(i8* %3)
define void @test(%0* %array) uwtable {
entry:
  %block = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>, align 8
  %0 = bitcast %0* %array to i8*
  %1 = tail call i8* @objc_retain(i8* %0) nounwind
  %block.isa = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 0
  store i8* bitcast (i8** @_NSConcreteStackBlock to i8*), i8** %block.isa, align 8
  %block.flags = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 1
  store i32 1107296256, i32* %block.flags, align 8
  %block.reserved = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 2
  store i32 0, i32* %block.reserved, align 4
  %block.invoke = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 3
  store i8* bitcast (void (i8*)* @__test_block_invoke_0 to i8*), i8** %block.invoke, align 8
  %block.descriptor = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 4
  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
  %block.captured = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 5
  store %0* %array, %0** %block.captured, align 8
  %2 = bitcast <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block to i8*
  %3 = call i8* @objc_retainBlock(i8* %2) nounwind
  %tmp2 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
  call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i8*)*)(i8* %0, i8* %tmp2, i8* %3)
  call void @objc_release(i8* %3) nounwind
  %strongdestroy = load %0** %block.captured, align 8
  %4 = bitcast %0* %strongdestroy to i8*
  call void @objc_release(i8* %4) nounwind, !clang.imprecise_release !0
  ret void
}

; Same as test, but the objc_retainBlock has a clang.arc.copy_on_escape
; tag so it's safe to delete.

; CHECK-LABEL: define void @test_with_COE(
; CHECK-NOT: @objc_retainBlock
; CHECK: @objc_msgSend
; CHECK: @objc_release
; CHECK-NOT: @objc_release
; CHECK: }
define void @test_with_COE(%0* %array) uwtable {
entry:
  %block = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>, align 8
  %0 = bitcast %0* %array to i8*
  %1 = tail call i8* @objc_retain(i8* %0) nounwind
  %block.isa = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 0
  store i8* bitcast (i8** @_NSConcreteStackBlock to i8*), i8** %block.isa, align 8
  %block.flags = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 1
  store i32 1107296256, i32* %block.flags, align 8
  %block.reserved = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 2
  store i32 0, i32* %block.reserved, align 4
  %block.invoke = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 3
  store i8* bitcast (void (i8*)* @__test_block_invoke_0 to i8*), i8** %block.invoke, align 8
  %block.descriptor = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 4
  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
  %block.captured = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block, i64 0, i32 5
  store %0* %array, %0** %block.captured, align 8
  %2 = bitcast <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %block to i8*
  %3 = call i8* @objc_retainBlock(i8* %2) nounwind, !clang.arc.copy_on_escape !0
  %tmp2 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
  call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i8*)*)(i8* %0, i8* %tmp2, i8* %3)
  call void @objc_release(i8* %3) nounwind
  %strongdestroy = load %0** %block.captured, align 8
  %4 = bitcast %0* %strongdestroy to i8*
  call void @objc_release(i8* %4) nounwind, !clang.imprecise_release !0
  ret void
}

declare i8* @objc_retain(i8*)

declare void @__test_block_invoke_0(i8* nocapture) uwtable

declare i8* @objc_retainBlock(i8*)

declare i8* @objc_msgSend(i8*, i8*, ...) nonlazybind

declare void @objc_release(i8*)

; CHECK: attributes #0 = { uwtable }
; CHECK: attributes #1 = { nonlazybind }
; CHECK: attributes [[NUW]] = { nounwind }

!0 = metadata !{}