summaryrefslogtreecommitdiff
path: root/test/Transforms/ObjCARC/contract-storestrong.ll
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2012-05-08 23:34:08 +0000
committerDan Gohman <gohman@apple.com>2012-05-08 23:34:08 +0000
commit4670dace66f5ef6ab0b153cd482b5bc827467c73 (patch)
tree9e79febdb512aa646228ab0380eaef3d13daff27 /test/Transforms/ObjCARC/contract-storestrong.ll
parentf191b43103113119e60b19b8e78966803a20c655 (diff)
downloadllvm-4670dace66f5ef6ab0b153cd482b5bc827467c73.tar.gz
llvm-4670dace66f5ef6ab0b153cd482b5bc827467c73.tar.bz2
llvm-4670dace66f5ef6ab0b153cd482b5bc827467c73.tar.xz
Fix objc_storeStrong pattern matching to catch a potential use of the
old value after the store but before it is released. This fixes rdar:/11116986. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156442 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms/ObjCARC/contract-storestrong.ll')
-rw-r--r--test/Transforms/ObjCARC/contract-storestrong.ll76
1 files changed, 76 insertions, 0 deletions
diff --git a/test/Transforms/ObjCARC/contract-storestrong.ll b/test/Transforms/ObjCARC/contract-storestrong.ll
index 4ff0596fbb..376120cf8b 100644
--- a/test/Transforms/ObjCARC/contract-storestrong.ll
+++ b/test/Transforms/ObjCARC/contract-storestrong.ll
@@ -4,6 +4,7 @@ target datalayout = "e-p:64:64:64"
declare i8* @objc_retain(i8*)
declare void @objc_release(i8*)
+declare void @use_pointer(i8*)
@x = external global i8*
@@ -57,3 +58,78 @@ entry:
tail call void @objc_release(i8* %tmp) nounwind
ret void
}
+
+; Don't do this if there's a use of the old pointer vlaue between the store
+; and the release.
+
+; CHECK: define void @test3(i8* %newValue) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %x0 = tail call i8* @objc_retain(i8* %newValue) nounwind
+; CHECK-NEXT: %x1 = load i8** @x, align 8
+; CHECK-NEXT: store i8* %x0, i8** @x, align 8
+; CHECK-NEXT: tail call void @use_pointer(i8* %x1), !clang.arc.no_objc_arc_exceptions !0
+; CHECK-NEXT: tail call void @objc_release(i8* %x1) nounwind, !clang.imprecise_release !0
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+define void @test3(i8* %newValue) {
+entry:
+ %x0 = tail call i8* @objc_retain(i8* %newValue) nounwind
+ %x1 = load i8** @x, align 8
+ store i8* %newValue, i8** @x, align 8
+ tail call void @use_pointer(i8* %x1), !clang.arc.no_objc_arc_exceptions !0
+ tail call void @objc_release(i8* %x1) nounwind, !clang.imprecise_release !0
+ ret void
+}
+
+; Like test3, but with an icmp use instead of a call, for good measure.
+
+; CHECK: define i1 @test4(i8* %newValue, i8* %foo) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %x0 = tail call i8* @objc_retain(i8* %newValue) nounwind
+; CHECK-NEXT: %x1 = load i8** @x, align 8
+; CHECK-NEXT: store i8* %x0, i8** @x, align 8
+; CHECK-NEXT: %t = icmp eq i8* %x1, %foo
+; CHECK-NEXT: tail call void @objc_release(i8* %x1) nounwind, !clang.imprecise_release !0
+; CHECK-NEXT: ret i1 %t
+; CHECK-NEXT: }
+define i1 @test4(i8* %newValue, i8* %foo) {
+entry:
+ %x0 = tail call i8* @objc_retain(i8* %newValue) nounwind
+ %x1 = load i8** @x, align 8
+ store i8* %newValue, i8** @x, align 8
+ %t = icmp eq i8* %x1, %foo
+ tail call void @objc_release(i8* %x1) nounwind, !clang.imprecise_release !0
+ ret i1 %t
+}
+
+; Do form an objc_storeStrong here, because the use is before the store.
+
+; CHECK: define i1 @test5(i8* %newValue, i8* %foo) {
+; CHECK: %t = icmp eq i8* %x1, %foo
+; CHECK: tail call void @objc_storeStrong(i8** @x, i8* %newValue) nounwind
+define i1 @test5(i8* %newValue, i8* %foo) {
+entry:
+ %x0 = tail call i8* @objc_retain(i8* %newValue) nounwind
+ %x1 = load i8** @x, align 8
+ %t = icmp eq i8* %x1, %foo
+ store i8* %newValue, i8** @x, align 8
+ tail call void @objc_release(i8* %x1) nounwind, !clang.imprecise_release !0
+ ret i1 %t
+}
+
+; Like test5, but the release is before the store.
+
+; CHECK: define i1 @test6(i8* %newValue, i8* %foo) {
+; CHECK: %t = icmp eq i8* %x1, %foo
+; CHECK: tail call void @objc_storeStrong(i8** @x, i8* %newValue) nounwind
+define i1 @test6(i8* %newValue, i8* %foo) {
+entry:
+ %x0 = tail call i8* @objc_retain(i8* %newValue) nounwind
+ %x1 = load i8** @x, align 8
+ tail call void @objc_release(i8* %x1) nounwind, !clang.imprecise_release !0
+ %t = icmp eq i8* %x1, %foo
+ store i8* %newValue, i8** @x, align 8
+ ret i1 %t
+}
+
+!0 = metadata !{}