aboutsummaryrefslogtreecommitdiffstats
path: root/test/Transforms/ObjCARC
diff options
context:
space:
mode:
Diffstat (limited to 'test/Transforms/ObjCARC')
-rw-r--r--test/Transforms/ObjCARC/basic.ll141
-rw-r--r--test/Transforms/ObjCARC/cfg-hazards.ll329
-rw-r--r--test/Transforms/ObjCARC/contract-storestrong.ll4
-rw-r--r--test/Transforms/ObjCARC/empty-block.ll59
-rw-r--r--test/Transforms/ObjCARC/invoke.ll6
-rw-r--r--test/Transforms/ObjCARC/nested.ll620
-rw-r--r--test/Transforms/ObjCARC/retain-block-alloca.ll90
-rw-r--r--test/Transforms/ObjCARC/retain-block-side-effects.ll39
-rw-r--r--test/Transforms/ObjCARC/retain-not-declared.ll54
-rw-r--r--test/Transforms/ObjCARC/rv.ll11
10 files changed, 1334 insertions, 19 deletions
diff --git a/test/Transforms/ObjCARC/basic.ll b/test/Transforms/ObjCARC/basic.ll
index a6bbf86..861173b 100644
--- a/test/Transforms/ObjCARC/basic.ll
+++ b/test/Transforms/ObjCARC/basic.ll
@@ -86,6 +86,37 @@ alt_return:
ret void
}
+; Don't do partial elimination into two different CFG diamonds.
+
+; CHECK: define void @test1b(
+; CHECK: entry:
+; CHECK: tail call i8* @objc_retain(i8* %x) nounwind
+; CHECK-NOT: @objc_
+; CHECK: if.end5:
+; CHECK: tail call void @objc_release(i8* %x) nounwind, !clang.imprecise_release !0
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test1b(i8* %x, i1 %p, i1 %q) {
+entry:
+ tail call i8* @objc_retain(i8* %x) nounwind
+ br i1 %p, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ tail call void @callee()
+ br label %if.end
+
+if.end: ; preds = %if.then, %entry
+ br i1 %q, label %if.then3, label %if.end5
+
+if.then3: ; preds = %if.end
+ tail call void @use_pointer(i8* %x)
+ br label %if.end5
+
+if.end5: ; preds = %if.then3, %if.end
+ tail call void @objc_release(i8* %x) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
; Like test0 but the pointer is passed to an intervening call,
; so the optimization is not safe.
@@ -353,13 +384,14 @@ entry:
; CHECK: define void @test10(
; CHECK: @objc_retain(i8* %x)
+; CHECK: @callee
; CHECK: @use_pointer
; CHECK: @objc_release
; CHECK: }
define void @test10(i8* %x) nounwind {
entry:
%0 = call i8* @objc_retain(i8* %x) nounwind
- call void @use_pointer(i8* %x)
+ call void @callee()
call void @use_pointer(i8* %x)
call void @objc_release(i8* %0) nounwind
ret void
@@ -697,6 +729,8 @@ invoke.cont23: ; preds = %if.then12
lpad20: ; preds = %invoke.cont23, %if.then12
%tmp502 = phi double* [ undef, %invoke.cont23 ], [ %self, %if.then12 ]
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
unreachable
if.end: ; preds = %invoke.cont23
@@ -768,7 +802,7 @@ entry:
define void @test23b(i8* %p) {
entry:
%0 = call i8* @objc_retainBlock(i8* %p) nounwind
- call void @use_pointer(i8* %p)
+ call void @callee()
call void @use_pointer(i8* %p)
call void @objc_release(i8* %p) nounwind
ret void
@@ -1569,6 +1603,107 @@ if.end: ; preds = %entry, %if.then
ret void
}
+; When there are adjacent retain+release pairs, the first one is
+; known unnecessary because the presence of the second one means that
+; the first one won't be deleting the object.
+
+; CHECK: define void @test57(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %x) nounwind
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: call void @objc_release(i8* %x) nounwind
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test57(i8* %x) nounwind {
+entry:
+ call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ call void @use_pointer(i8* %x)
+ call void @objc_release(i8* %x) nounwind
+ call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ call void @use_pointer(i8* %x)
+ call void @objc_release(i8* %x) nounwind
+ ret void
+}
+
+; An adjacent retain+release pair is sufficient even if it will be
+; removed itself.
+
+; CHECK: define void @test58(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test58(i8* %x) nounwind {
+entry:
+ call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ call void @use_pointer(i8* %x)
+ call void @objc_release(i8* %x) nounwind
+ call i8* @objc_retain(i8* %x) nounwind
+ call void @objc_release(i8* %x) nounwind
+ ret void
+}
+
+; Don't delete the second retain+release pair in an adjacent set.
+
+; CHECK: define void @test59(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %x) nounwind
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: call void @use_pointer(i8* %x)
+; CHECK-NEXT: call void @objc_release(i8* %x) nounwind
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test59(i8* %x) nounwind {
+entry:
+ %a = call i8* @objc_retain(i8* %x) nounwind
+ call void @objc_release(i8* %x) nounwind
+ %b = call i8* @objc_retain(i8* %x) nounwind
+ call void @use_pointer(i8* %x)
+ call void @use_pointer(i8* %x)
+ call void @objc_release(i8* %x) nounwind
+ ret void
+}
+
+; Constant pointers to objects don't need reference counting.
+
+@constptr = external constant i8*
+@something = external global i8*
+
+; CHECK: define void @test60(
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test60() {
+ %t = load i8** @constptr
+ %s = load i8** @something
+ call i8* @objc_retain(i8* %s)
+ call void @callee()
+ call void @use_pointer(i8* %t)
+ call void @objc_release(i8* %s)
+ ret void
+}
+
+; Constant pointers to objects don't need to be considered related to other
+; pointers.
+
+; CHECK: define void @test61(
+; CHECK-NOT: @objc_
+; CHECK: }
+define void @test61() {
+ %t = load i8** @constptr
+ call i8* @objc_retain(i8* %t)
+ call void @callee()
+ call void @use_pointer(i8* %t)
+ call void @objc_release(i8* %t)
+ ret void
+}
+
declare void @bar(i32 ()*)
; A few real-world testcases.
@@ -1896,3 +2031,5 @@ end: ; preds = %if.end125, %if.end1
}
!0 = metadata !{}
+
+declare i32 @__gxx_personality_v0(...)
diff --git a/test/Transforms/ObjCARC/cfg-hazards.ll b/test/Transforms/ObjCARC/cfg-hazards.ll
index e3624df..1519423 100644
--- a/test/Transforms/ObjCARC/cfg-hazards.ll
+++ b/test/Transforms/ObjCARC/cfg-hazards.ll
@@ -7,6 +7,7 @@
declare void @use_pointer(i8*)
declare i8* @objc_retain(i8*)
declare void @objc_release(i8*)
+declare void @callee()
; CHECK: define void @test0(
; CHECK: call i8* @objc_retain(
@@ -18,18 +19,18 @@ declare void @objc_release(i8*)
define void @test0(i8* %digits) {
entry:
%tmp1 = call i8* @objc_retain(i8* %digits) nounwind
- call void @use_pointer(i8* %tmp1)
+ call void @use_pointer(i8* %digits)
br label %for.body
for.body: ; preds = %for.body, %entry
%upcDigitIndex.01 = phi i64 [ 2, %entry ], [ %inc, %for.body ]
- call void @use_pointer(i8* %tmp1)
+ call void @use_pointer(i8* %digits)
%inc = add i64 %upcDigitIndex.01, 1
%cmp = icmp ult i64 %inc, 12
br i1 %cmp, label %for.body, label %for.end
for.end: ; preds = %for.body
- call void @objc_release(i8* %tmp1) nounwind, !clang.imprecise_release !0
+ call void @objc_release(i8* %digits) nounwind, !clang.imprecise_release !0
ret void
}
@@ -47,14 +48,14 @@ entry:
for.body: ; preds = %for.body, %entry
%upcDigitIndex.01 = phi i64 [ 2, %entry ], [ %inc, %for.body ]
- call void @use_pointer(i8* %tmp1)
- call void @use_pointer(i8* %tmp1)
+ call void @use_pointer(i8* %digits)
+ call void @use_pointer(i8* %digits)
%inc = add i64 %upcDigitIndex.01, 1
%cmp = icmp ult i64 %inc, 12
br i1 %cmp, label %for.body, label %for.end
for.end: ; preds = %for.body
- call void @objc_release(i8* %tmp1) nounwind, !clang.imprecise_release !0
+ call void @objc_release(i8* %digits) nounwind, !clang.imprecise_release !0
ret void
}
@@ -72,14 +73,324 @@ entry:
for.body: ; preds = %for.body, %entry
%upcDigitIndex.01 = phi i64 [ 2, %entry ], [ %inc, %for.body ]
- call void @use_pointer(i8* %tmp1)
+ call void @use_pointer(i8* %digits)
%inc = add i64 %upcDigitIndex.01, 1
%cmp = icmp ult i64 %inc, 12
br i1 %cmp, label %for.body, label %for.end
for.end: ; preds = %for.body
- call void @use_pointer(i8* %tmp1)
- call void @objc_release(i8* %tmp1) nounwind, !clang.imprecise_release !0
+ call void @use_pointer(i8* %digits)
+ call void @objc_release(i8* %digits) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete nested retain+release pairs around loops.
+
+; CHECK: define void @test3(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: tail call i8* @objc_retain(i8* %a) nounwind
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: call void @objc_release(i8* %a)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test3(i8* %a) nounwind {
+entry:
+ %outer = call i8* @objc_retain(i8* %a) nounwind
+ %inner = call i8* @objc_retain(i8* %a) nounwind
+ br label %loop
+
+loop:
+ call void @callee()
+ store i8 0, i8* %a
+ br i1 undef, label %loop, label %exit
+
+exit:
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test4(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: tail call i8* @objc_retain(i8* %a) nounwind
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: call void @objc_release(i8* %a)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test4(i8* %a) nounwind {
+entry:
+ %outer = call i8* @objc_retain(i8* %a) nounwind
+ %inner = call i8* @objc_retain(i8* %a) nounwind
+ br label %loop
+
+loop:
+ br label %more
+
+more:
+ call void @callee()
+ call void @callee()
+ store i8 0, i8* %a
+ br i1 undef, label %loop, label %exit
+
+exit:
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test5(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: tail call i8* @objc_retain(i8* %a) nounwind
+; CHECK-NEXT: call void @callee()
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: call void @use_pointer(i8* %a)
+; CHECK-NEXT: call void @objc_release(i8* %a)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test5(i8* %a) nounwind {
+entry:
+ %outer = tail call i8* @objc_retain(i8* %a) nounwind
+ %inner = tail call i8* @objc_retain(i8* %a) nounwind
+ call void @callee()
+ br label %loop
+
+loop:
+ br i1 undef, label %true, label %more
+
+true:
+ br label %more
+
+more:
+ br i1 undef, label %exit, label %loop
+
+exit:
+ call void @use_pointer(i8* %a)
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test6(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: tail call i8* @objc_retain(i8* %a) nounwind
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: call void @use_pointer(i8* %a)
+; CHECK-NEXT: call void @objc_release(i8* %a)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test6(i8* %a) nounwind {
+entry:
+ %outer = tail call i8* @objc_retain(i8* %a) nounwind
+ %inner = tail call i8* @objc_retain(i8* %a) nounwind
+ br label %loop
+
+loop:
+ br i1 undef, label %true, label %more
+
+true:
+ call void @callee()
+ br label %more
+
+more:
+ br i1 undef, label %exit, label %loop
+
+exit:
+ call void @use_pointer(i8* %a)
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test7(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: tail call i8* @objc_retain(i8* %a) nounwind
+; CHECK-NEXT: call void @callee()
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: call void @objc_release(i8* %a)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test7(i8* %a) nounwind {
+entry:
+ %outer = tail call i8* @objc_retain(i8* %a) nounwind
+ %inner = tail call i8* @objc_retain(i8* %a) nounwind
+ call void @callee()
+ br label %loop
+
+loop:
+ br i1 undef, label %true, label %more
+
+true:
+ call void @use_pointer(i8* %a)
+ br label %more
+
+more:
+ br i1 undef, label %exit, label %loop
+
+exit:
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test8(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: tail call i8* @objc_retain(i8* %a) nounwind
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: call void @objc_release(i8* %a)
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test8(i8* %a) nounwind {
+entry:
+ %outer = tail call i8* @objc_retain(i8* %a) nounwind
+ %inner = tail call i8* @objc_retain(i8* %a) nounwind
+ br label %loop
+
+loop:
+ br i1 undef, label %true, label %more
+
+true:
+ call void @callee()
+ call void @use_pointer(i8* %a)
+ br label %more
+
+more:
+ br i1 undef, label %exit, label %loop
+
+exit:
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test9(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test9(i8* %a) nounwind {
+entry:
+ %outer = tail call i8* @objc_retain(i8* %a) nounwind
+ %inner = tail call i8* @objc_retain(i8* %a) nounwind
+ br label %loop
+
+loop:
+ br i1 undef, label %true, label %more
+
+true:
+ call void @use_pointer(i8* %a)
+ br label %more
+
+more:
+ br i1 undef, label %exit, label %loop
+
+exit:
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test10(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test10(i8* %a) nounwind {
+entry:
+ %outer = tail call i8* @objc_retain(i8* %a) nounwind
+ %inner = tail call i8* @objc_retain(i8* %a) nounwind
+ br label %loop
+
+loop:
+ br i1 undef, label %true, label %more
+
+true:
+ call void @callee()
+ br label %more
+
+more:
+ br i1 undef, label %exit, label %loop
+
+exit:
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; CHECK: define void @test11(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test11(i8* %a) nounwind {
+entry:
+ %outer = tail call i8* @objc_retain(i8* %a) nounwind
+ %inner = tail call i8* @objc_retain(i8* %a) nounwind
+ br label %loop
+
+loop:
+ br i1 undef, label %true, label %more
+
+true:
+ br label %more
+
+more:
+ br i1 undef, label %exit, label %loop
+
+exit:
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Don't delete anything if they're not balanced.
+
+; CHECK: define void @test12(i8* %a) nounwind {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %outer = tail call i8* @objc_retain(i8* %a) nounwind
+; CHECK-NEXT: %inner = tail call i8* @objc_retain(i8* %a) nounwind
+; CHECK-NEXT: br label %loop
+; CHECK-NOT: @objc_
+; CHECK: exit:
+; CHECK-NEXT: call void @objc_release(i8* %a) nounwind
+; CHECK-NEXT: call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test12(i8* %a) nounwind {
+entry:
+ %outer = tail call i8* @objc_retain(i8* %a) nounwind
+ %inner = tail call i8* @objc_retain(i8* %a) nounwind
+ br label %loop
+
+loop:
+ br i1 undef, label %true, label %more
+
+true:
+ ret void
+
+more:
+ br i1 undef, label %exit, label %loop
+
+exit:
+ call void @objc_release(i8* %a) nounwind
+ call void @objc_release(i8* %a) nounwind, !clang.imprecise_release !0
ret void
}
diff --git a/test/Transforms/ObjCARC/contract-storestrong.ll b/test/Transforms/ObjCARC/contract-storestrong.ll
index 50ed260..25c93f4 100644
--- a/test/Transforms/ObjCARC/contract-storestrong.ll
+++ b/test/Transforms/ObjCARC/contract-storestrong.ll
@@ -25,7 +25,7 @@ entry:
; CHECK: define void @test1(i8* %p) {
; CHECK-NEXT: entry:
; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %p) nounwind
-; CHECK-NEXT: %tmp = volatile load i8** @x, align 8
+; CHECK-NEXT: %tmp = load volatile i8** @x, align 8
; CHECK-NEXT: store i8* %0, i8** @x, align 8
; CHECK-NEXT: tail call void @objc_release(i8* %tmp) nounwind
; CHECK-NEXT: ret void
@@ -45,7 +45,7 @@ entry:
; CHECK-NEXT: entry:
; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %p) nounwind
; CHECK-NEXT: %tmp = load i8** @x, align 8
-; CHECK-NEXT: volatile store i8* %0, i8** @x, align 8
+; CHECK-NEXT: store volatile i8* %0, i8** @x, align 8
; CHECK-NEXT: tail call void @objc_release(i8* %tmp) nounwind
; CHECK-NEXT: ret void
; CHECK-NEXT: }
diff --git a/test/Transforms/ObjCARC/empty-block.ll b/test/Transforms/ObjCARC/empty-block.ll
new file mode 100644
index 0000000..ca55413
--- /dev/null
+++ b/test/Transforms/ObjCARC/empty-block.ll
@@ -0,0 +1,59 @@
+; RUN: opt -S -objc-arc < %s | FileCheck %s
+; rdar://10210274
+
+%0 = type opaque
+
+declare i8* @objc_retain(i8*)
+
+declare void @objc_release(i8*)
+
+declare i8* @objc_autoreleaseReturnValue(i8*)
+
+; Don't delete the autorelease.
+
+; CHECK: define %0* @test0(
+; CHECK: @objc_retain
+; CHECK: .lr.ph:
+; CHECK-NOT: @objc_r
+; CHECK: @objc_autoreleaseReturnValue
+; CHECK-NOT: @objc_
+; CHECK: }
+define %0* @test0(%0* %buffer) nounwind {
+ %1 = bitcast %0* %buffer to i8*
+ %2 = tail call i8* @objc_retain(i8* %1) nounwind
+ br i1 undef, label %.lr.ph, label %._crit_edge
+
+.lr.ph: ; preds = %.lr.ph, %0
+ br i1 false, label %.lr.ph, label %._crit_edge
+
+._crit_edge: ; preds = %.lr.ph, %0
+ %3 = tail call i8* @objc_retain(i8* %1) nounwind
+ tail call void @objc_release(i8* %1) nounwind, !clang.imprecise_release !0
+ %4 = tail call i8* @objc_autoreleaseReturnValue(i8* %1) nounwind
+ ret %0* %buffer
+}
+
+; Do delete the autorelease, even with the retain in a different block.
+
+; CHECK: define %0* @test1(
+; CHECK-NOT: @objc
+; CHECK: }
+define %0* @test1() nounwind {
+ %buffer = call %0* @foo()
+ %1 = bitcast %0* %buffer to i8*
+ %2 = tail call i8* @objc_retain(i8* %1) nounwind
+ br i1 undef, label %.lr.ph, label %._crit_edge
+
+.lr.ph: ; preds = %.lr.ph, %0
+ br i1 false, label %.lr.ph, label %._crit_edge
+
+._crit_edge: ; preds = %.lr.ph, %0
+ %3 = tail call i8* @objc_retain(i8* %1) nounwind
+ tail call void @objc_release(i8* %1) nounwind, !clang.imprecise_release !0
+ %4 = tail call i8* @objc_autoreleaseReturnValue(i8* %1) nounwind
+ ret %0* %buffer
+}
+
+declare %0* @foo()
+
+!0 = metadata !{}
diff --git a/test/Transforms/ObjCARC/invoke.ll b/test/Transforms/ObjCARC/invoke.ll
index a1b87d2..cf971e4 100644
--- a/test/Transforms/ObjCARC/invoke.ll
+++ b/test/Transforms/ObjCARC/invoke.ll
@@ -27,6 +27,8 @@ invoke.cont: ; preds = %entry
ret void
lpad: ; preds = %entry
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
call void @objc_release(i8* %zipFile) nounwind, !clang.imprecise_release !0
ret void
}
@@ -56,6 +58,8 @@ invoke.cont: ; preds = %entry
br label %done
lpad: ; preds = %entry
+ %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
call void @callee()
br label %done
@@ -64,4 +68,6 @@ done:
ret void
}
+declare i32 @__gxx_personality_v0(...)
+
!0 = metadata !{}
diff --git a/test/Transforms/ObjCARC/nested.ll b/test/Transforms/ObjCARC/nested.ll
new file mode 100644
index 0000000..9eada8a
--- /dev/null
+++ b/test/Transforms/ObjCARC/nested.ll
@@ -0,0 +1,620 @@
+; RUN: opt -objc-arc -S < %s | FileCheck %s
+
+%struct.__objcFastEnumerationState = type { i64, i8**, i64*, [5 x i64] }
+
+@"\01L_OBJC_METH_VAR_NAME_" = internal global [43 x i8] c"countByEnumeratingWithState:objects:count:\00", section "__TEXT,__objc_methname,cstring_literals", align 1
+@"\01L_OBJC_SELECTOR_REFERENCES_" = internal global i8* getelementptr inbounds ([43 x i8]* @"\01L_OBJC_METH_VAR_NAME_", i64 0, i64 0), section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
+@g = common global i8* null, align 8
+@"\01L_OBJC_IMAGE_INFO" = internal constant [2 x i32] [i32 0, i32 16], section "__DATA, __objc_imageinfo, regular, no_dead_strip"
+
+declare void @callee()
+declare i8* @returner()
+declare i8* @objc_retainAutoreleasedReturnValue(i8*)
+declare i8* @objc_retain(i8*)
+declare void @objc_enumerationMutation(i8*)
+declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
+declare i8* @objc_msgSend(i8*, i8*, ...) nonlazybind
+declare void @use(i8*)
+declare void @objc_release(i8*)
+
+!0 = metadata !{}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test0(
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test0(i8* %a) nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %0 = call i8* @objc_retain(i8* %a) nounwind
+ %tmp = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 64, i32 8, i1 false)
+ %1 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp2 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp2, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ %stateitems.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 1
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call, %forcoll.loopinit ], [ %call6, %forcoll.refetch ]
+ %tmp7 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp7, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ 0, %forcoll.loopbody.outer ], [ %4, %forcoll.notmutated ]
+ %mutationsptr3 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr3, align 8
+ %2 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %2, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %1)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %stateitems = load i8*** %stateitems.ptr, align 8
+ %currentitem.ptr = getelementptr i8** %stateitems, i64 %forcoll.index
+ %3 = load i8** %currentitem.ptr, align 8
+ call void @use(i8* %3)
+ %4 = add i64 %forcoll.index, 1
+ %exitcond = icmp eq i64 %4, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp5 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call6 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp5, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %5 = icmp eq i64 %call6, 0
+ br i1 %5, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %1) nounwind
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test2(
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test2() nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %call = call i8* @returner()
+ %0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
+ %tmp = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 64, i32 8, i1 false)
+ %1 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp2 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call3 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp2, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call3, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ %stateitems.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 1
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call3, %forcoll.loopinit ], [ %call7, %forcoll.refetch ]
+ %tmp8 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp8, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ 0, %forcoll.loopbody.outer ], [ %4, %forcoll.notmutated ]
+ %mutationsptr4 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr4, align 8
+ %2 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %2, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %1)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %stateitems = load i8*** %stateitems.ptr, align 8
+ %currentitem.ptr = getelementptr i8** %stateitems, i64 %forcoll.index
+ %3 = load i8** %currentitem.ptr, align 8
+ call void @use(i8* %3)
+ %4 = add i64 %forcoll.index, 1
+ %exitcond = icmp eq i64 %4, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp6 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call7 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp6, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %5 = icmp eq i64 %call7, 0
+ br i1 %5, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %1) nounwind
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test4(
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test4() nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %tmp = load i8** @g, align 8
+ %0 = call i8* @objc_retain(i8* %tmp) nounwind
+ %tmp2 = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp2, i8 0, i64 64, i32 8, i1 false)
+ %1 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp4 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp4, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ %stateitems.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 1
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call, %forcoll.loopinit ], [ %call8, %forcoll.refetch ]
+ %tmp9 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp9, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ 0, %forcoll.loopbody.outer ], [ %4, %forcoll.notmutated ]
+ %mutationsptr5 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr5, align 8
+ %2 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %2, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %1)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %stateitems = load i8*** %stateitems.ptr, align 8
+ %currentitem.ptr = getelementptr i8** %stateitems, i64 %forcoll.index
+ %3 = load i8** %currentitem.ptr, align 8
+ call void @use(i8* %3)
+ %4 = add i64 %forcoll.index, 1
+ %exitcond = icmp eq i64 %4, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp7 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call8 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp7, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %5 = icmp eq i64 %call8, 0
+ br i1 %5, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %1) nounwind
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test5(
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test5() nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %call = call i8* @returner()
+ %0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
+ call void @callee()
+ %tmp = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 64, i32 8, i1 false)
+ %1 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp2 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call3 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp2, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call3, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ %stateitems.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 1
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call3, %forcoll.loopinit ], [ %call7, %forcoll.refetch ]
+ %tmp8 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp8, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ 0, %forcoll.loopbody.outer ], [ %4, %forcoll.notmutated ]
+ %mutationsptr4 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr4, align 8
+ %2 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %2, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %1)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %stateitems = load i8*** %stateitems.ptr, align 8
+ %currentitem.ptr = getelementptr i8** %stateitems, i64 %forcoll.index
+ %3 = load i8** %currentitem.ptr, align 8
+ call void @use(i8* %3)
+ %4 = add i64 %forcoll.index, 1
+ %exitcond = icmp eq i64 %4, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp6 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call7 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp6, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %5 = icmp eq i64 %call7, 0
+ br i1 %5, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %1) nounwind
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test6(
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test6() nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %call = call i8* @returner()
+ %0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
+ %tmp = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 64, i32 8, i1 false)
+ %1 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp2 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call3 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp2, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call3, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ %stateitems.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 1
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call3, %forcoll.loopinit ], [ %call7, %forcoll.refetch ]
+ %tmp8 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp8, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ 0, %forcoll.loopbody.outer ], [ %4, %forcoll.notmutated ]
+ %mutationsptr4 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr4, align 8
+ %2 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %2, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %1)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %stateitems = load i8*** %stateitems.ptr, align 8
+ %currentitem.ptr = getelementptr i8** %stateitems, i64 %forcoll.index
+ %3 = load i8** %currentitem.ptr, align 8
+ call void @use(i8* %3)
+ %4 = add i64 %forcoll.index, 1
+ %exitcond = icmp eq i64 %4, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp6 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call7 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp6, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %5 = icmp eq i64 %call7, 0
+ br i1 %5, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %1) nounwind
+ call void @callee()
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test7(
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test7() nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %call = call i8* @returner()
+ %0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
+ call void @callee()
+ %tmp = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 64, i32 8, i1 false)
+ %1 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp2 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call3 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp2, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call3, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ %stateitems.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 1
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call3, %forcoll.loopinit ], [ %call7, %forcoll.refetch ]
+ %tmp8 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp8, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ 0, %forcoll.loopbody.outer ], [ %4, %forcoll.notmutated ]
+ %mutationsptr4 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr4, align 8
+ %2 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %2, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %1)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %stateitems = load i8*** %stateitems.ptr, align 8
+ %currentitem.ptr = getelementptr i8** %stateitems, i64 %forcoll.index
+ %3 = load i8** %currentitem.ptr, align 8
+ call void @use(i8* %3)
+ %4 = add i64 %forcoll.index, 1
+ %exitcond = icmp eq i64 %4, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp6 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call7 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp6, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %5 = icmp eq i64 %call7, 0
+ br i1 %5, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %1) nounwind
+ call void @callee()
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test8(
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test8() nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %call = call i8* @returner()
+ %0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
+ %tmp = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 64, i32 8, i1 false)
+ %1 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp2 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call3 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp2, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call3, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ %stateitems.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 1
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call3, %forcoll.loopinit ], [ %call7, %forcoll.refetch ]
+ %tmp8 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp8, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ 0, %forcoll.loopbody.outer ], [ %4, %forcoll.next ]
+ %mutationsptr4 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr4, align 8
+ %2 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %2, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %1)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %stateitems = load i8*** %stateitems.ptr, align 8
+ %currentitem.ptr = getelementptr i8** %stateitems, i64 %forcoll.index
+ %3 = load i8** %currentitem.ptr, align 8
+ %tobool = icmp eq i8* %3, null
+ br i1 %tobool, label %forcoll.next, label %if.then
+
+if.then:
+ call void @callee()
+ br label %forcoll.next
+
+forcoll.next:
+ %4 = add i64 %forcoll.index, 1
+ %exitcond = icmp eq i64 %4, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp6 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call7 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %1, i8* %tmp6, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %5 = icmp eq i64 %call7, 0
+ br i1 %5, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %1) nounwind
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test9(
+; CHECK: call i8* @objc_retain
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test9() nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %call = call i8* @returner()
+ %0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
+ %call1 = call i8* @returner()
+ %1 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call1) nounwind
+ %tmp = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 64, i32 8, i1 false)
+ %2 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp3 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call4 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %2, i8* %tmp3, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call4, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call4, %forcoll.loopinit ], [ %call7, %forcoll.refetch ]
+ %tmp9 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp9, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ %phitmp, %forcoll.notmutated.forcoll.loopbody_crit_edge ], [ 1, %forcoll.loopbody.outer ]
+ %mutationsptr5 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr5, align 8
+ %3 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %3, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %2)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %exitcond = icmp eq i64 %forcoll.index, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.notmutated.forcoll.loopbody_crit_edge
+
+forcoll.notmutated.forcoll.loopbody_crit_edge:
+ %phitmp = add i64 %forcoll.index, 1
+ br label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp6 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call7 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %2, i8* %tmp6, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %4 = icmp eq i64 %call7, 0
+ br i1 %4, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %2) nounwind
+ call void @objc_release(i8* %1) nounwind, !clang.imprecise_release !0
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Delete a nested retain+release pair.
+
+; CHECK: define void @test10(
+; CHECK: call i8* @objc_retain
+; CHECK: call i8* @objc_retain
+; CHECK-NOT: @objc_retain
+; CHECK: }
+define void @test10() nounwind {
+entry:
+ %state.ptr = alloca %struct.__objcFastEnumerationState, align 8
+ %items.ptr = alloca [16 x i8*], align 8
+ %call = call i8* @returner()
+ %0 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
+ %call1 = call i8* @returner()
+ %1 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call1) nounwind
+ call void @callee()
+ %tmp = bitcast %struct.__objcFastEnumerationState* %state.ptr to i8*
+ call void @llvm.memset.p0i8.i64(i8* %tmp, i8 0, i64 64, i32 8, i1 false)
+ %2 = call i8* @objc_retain(i8* %0) nounwind
+ %tmp3 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call4 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %2, i8* %tmp3, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %iszero = icmp eq i64 %call4, 0
+ br i1 %iszero, label %forcoll.empty, label %forcoll.loopinit
+
+forcoll.loopinit:
+ %mutationsptr.ptr = getelementptr inbounds %struct.__objcFastEnumerationState* %state.ptr, i64 0, i32 2
+ %mutationsptr = load i64** %mutationsptr.ptr, align 8
+ %forcoll.initial-mutations = load i64* %mutationsptr, align 8
+ br label %forcoll.loopbody.outer
+
+forcoll.loopbody.outer:
+ %forcoll.count.ph = phi i64 [ %call4, %forcoll.loopinit ], [ %call7, %forcoll.refetch ]
+ %tmp9 = icmp ugt i64 %forcoll.count.ph, 1
+ %umax = select i1 %tmp9, i64 %forcoll.count.ph, i64 1
+ br label %forcoll.loopbody
+
+forcoll.loopbody:
+ %forcoll.index = phi i64 [ %phitmp, %forcoll.notmutated.forcoll.loopbody_crit_edge ], [ 1, %forcoll.loopbody.outer ]
+ %mutationsptr5 = load i64** %mutationsptr.ptr, align 8
+ %statemutations = load i64* %mutationsptr5, align 8
+ %3 = icmp eq i64 %statemutations, %forcoll.initial-mutations
+ br i1 %3, label %forcoll.notmutated, label %forcoll.mutated
+
+forcoll.mutated:
+ call void @objc_enumerationMutation(i8* %2)
+ br label %forcoll.notmutated
+
+forcoll.notmutated:
+ %exitcond = icmp eq i64 %forcoll.index, %umax
+ br i1 %exitcond, label %forcoll.refetch, label %forcoll.notmutated.forcoll.loopbody_crit_edge
+
+forcoll.notmutated.forcoll.loopbody_crit_edge:
+ %phitmp = add i64 %forcoll.index, 1
+ br label %forcoll.loopbody
+
+forcoll.refetch:
+ %tmp6 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
+ %call7 = call i64 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i64 (i8*, i8*, %struct.__objcFastEnumerationState*, [16 x i8*]*, i64)*)(i8* %2, i8* %tmp6, %struct.__objcFastEnumerationState* %state.ptr, [16 x i8*]* %items.ptr, i64 16)
+ %4 = icmp eq i64 %call7, 0
+ br i1 %4, label %forcoll.empty, label %forcoll.loopbody.outer
+
+forcoll.empty:
+ call void @objc_release(i8* %2) nounwind
+ call void @objc_release(i8* %1) nounwind, !clang.imprecise_release !0
+ call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
+ ret void
+}
diff --git a/test/Transforms/ObjCARC/retain-block-alloca.ll b/test/Transforms/ObjCARC/retain-block-alloca.ll
new file mode 100644
index 0000000..01f2087
--- /dev/null
+++ b/test/Transforms/ObjCARC/retain-block-alloca.ll
@@ -0,0 +1,90 @@
+; 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: define void @test(
+; CHECK: %3 = call i8* @objc_retainBlock(i8* %2) nounwind
+; 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: 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*)
+
+!0 = metadata !{}
diff --git a/test/Transforms/ObjCARC/retain-block-side-effects.ll b/test/Transforms/ObjCARC/retain-block-side-effects.ll
new file mode 100644
index 0000000..e84d48f
--- /dev/null
+++ b/test/Transforms/ObjCARC/retain-block-side-effects.ll
@@ -0,0 +1,39 @@
+; RUN: opt -S -objc-arc-aa -basicaa -gvn < %s | FileCheck %s
+; rdar://10050579
+
+; objc_retainBlock stores into %repeater so the load from after the
+; call isn't forwardable from the store before the call.
+
+; CHECK: %tmp16 = call i8* @objc_retainBlock(i8* %tmp15) nounwind
+; CHECK: %tmp17 = bitcast i8* %tmp16 to void ()*
+; CHECK: %tmp18 = load %struct.__block_byref_repeater** %byref.forwarding, align 8
+; CHECK: %repeater12 = getelementptr inbounds %struct.__block_byref_repeater* %tmp18, i64 0, i32 6
+; CHECK: store void ()* %tmp17, void ()** %repeater12, align 8
+
+target 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"
+
+%0 = type opaque
+%struct.__block_byref_repeater = type { i8*, %struct.__block_byref_repeater*, i32, i32, i8*, i8*, void ()* }
+%struct.__block_descriptor = type { i64, i64 }
+
+define void @foo() noreturn {
+entry:
+ %repeater = alloca %struct.__block_byref_repeater, align 8
+ %block = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0*, i8* }>, align 8
+ %byref.forwarding = getelementptr inbounds %struct.__block_byref_repeater* %repeater, i64 0, i32 1
+ %tmp10 = getelementptr inbounds %struct.__block_byref_repeater* %repeater, i64 0, i32 6
+ store void ()* null, void ()** %tmp10, align 8
+ %block.captured11 = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0*, i8* }>* %block, i64 0, i32 6
+ %tmp14 = bitcast %struct.__block_byref_repeater* %repeater to i8*
+ store i8* %tmp14, i8** %block.captured11, align 8
+ %tmp15 = bitcast <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0*, i8* }>* %block to i8*
+ %tmp16 = call i8* @objc_retainBlock(i8* %tmp15) nounwind
+ %tmp17 = bitcast i8* %tmp16 to void ()*
+ %tmp18 = load %struct.__block_byref_repeater** %byref.forwarding, align 8
+ %repeater12 = getelementptr inbounds %struct.__block_byref_repeater* %tmp18, i64 0, i32 6
+ %tmp13 = load void ()** %repeater12, align 8
+ store void ()* %tmp17, void ()** %repeater12, align 8
+ ret void
+}
+
+declare i8* @objc_retainBlock(i8*)
diff --git a/test/Transforms/ObjCARC/retain-not-declared.ll b/test/Transforms/ObjCARC/retain-not-declared.ll
index e1fe117..41bde01 100644
--- a/test/Transforms/ObjCARC/retain-not-declared.ll
+++ b/test/Transforms/ObjCARC/retain-not-declared.ll
@@ -1,21 +1,23 @@
; RUN: opt -S -objc-arc -objc-arc-contract < %s | FileCheck %s
-; Test that the optimizer can create an objc_retainAutoreleaseReturnValue
-; declaration even if no objc_retain declaration exists.
-; rdar://9401303
-
target 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"
declare i8* @objc_unretainedObject(i8*)
declare i8* @objc_retainAutoreleasedReturnValue(i8*)
declare i8* @objc_autoreleaseReturnValue(i8*)
+declare i8* @objc_msgSend(i8*, i8*, ...)
+declare void @objc_release(i8*)
-; CHECK: define i8* @foo(i8* %p) {
+; Test that the optimizer can create an objc_retainAutoreleaseReturnValue
+; declaration even if no objc_retain declaration exists.
+; rdar://9401303
+
+; CHECK: define i8* @test0(i8* %p) {
; CHECK-NEXT: entry:
; CHECK-NEXT: %0 = tail call i8* @objc_retainAutoreleaseReturnValue(i8* %p) nounwind
; CHECK-NEXT: ret i8* %0
; CHECK-NEXT: }
-define i8* @foo(i8* %p) {
+define i8* @test0(i8* %p) {
entry:
%call = tail call i8* @objc_unretainedObject(i8* %p)
%0 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind
@@ -23,3 +25,43 @@ entry:
ret i8* %1
}
+; Properly create the @objc_retain declaration when it doesn't already exist.
+; rdar://9825114
+
+; CHECK: @test1(
+; CHECK: @objc_retain(
+; CHECK: @objc_retain(
+; CHECK: @objc_release(
+; CHECK: @objc_release(
+; CHECK: }
+define void @test1(i8* %call88) nounwind {
+entry:
+ %tmp1 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call88) nounwind
+ %call94 = invoke i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*)*)(i8* %tmp1)
+ to label %invoke.cont93 unwind label %lpad91
+
+invoke.cont93: ; preds = %entry
+ %tmp2 = call i8* @objc_retainAutoreleasedReturnValue(i8* %call94) nounwind
+ call void @objc_release(i8* %tmp1) nounwind
+ invoke void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*)*)(i8* %tmp2)
+ to label %invoke.cont102 unwind label %lpad100
+
+invoke.cont102: ; preds = %invoke.cont93
+ call void @objc_release(i8* %tmp2) nounwind, !clang.imprecise_release !0
+ unreachable
+
+lpad91: ; preds = %entry
+ %exn91 = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ unreachable
+
+lpad100: ; preds = %invoke.cont93
+ %exn100 = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
+ cleanup
+ call void @objc_release(i8* %tmp2) nounwind, !clang.imprecise_release !0
+ unreachable
+}
+
+declare i32 @__gxx_personality_v0(...)
+
+!0 = metadata !{}
diff --git a/test/Transforms/ObjCARC/rv.ll b/test/Transforms/ObjCARC/rv.ll
index da53a86..9353a19 100644
--- a/test/Transforms/ObjCARC/rv.ll
+++ b/test/Transforms/ObjCARC/rv.ll
@@ -329,3 +329,14 @@ define void @test23(i8* %p) {
call i8* @objc_autoreleaseReturnValue(i8* %p)
ret void
}
+
+; Don't convert autoreleaseRV to autorelease if the result is returned,
+; even through a bitcast.
+
+; CHECK: define {}* @test24(
+; CHECK: tail call i8* @objc_autoreleaseReturnValue(i8* %p)
+define {}* @test24(i8* %p) {
+ %t = call i8* @objc_autoreleaseReturnValue(i8* %p)
+ %s = bitcast i8* %p to {}*
+ ret {}* %s
+}