]> granicus.if.org Git - llvm/commitdiff
[ObjCARC] Pass the correct BasicBlock to fix assertion failure.
authorAkira Hatanaka <ahatanaka@apple.com>
Thu, 31 Aug 2017 18:27:47 +0000 (18:27 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Thu, 31 Aug 2017 18:27:47 +0000 (18:27 +0000)
The BasicBlock passed to FindPredecessorRetainWithSafePath should be the
parent block of Autorelease. This fixes a crash that occurs in
FindDependencies when StartInst is not in StartBB.

rdar://problem/33866381

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312266 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/ObjCARC/ObjCARCOpts.cpp
test/Transforms/ObjCARC/rv.ll

index 8f3a33f66c7f5f400a36ddcde575a9f48fc31437..8c0a90843ef4e64a483edc7a66b558bb444ca9d3 100644 (file)
@@ -2027,7 +2027,8 @@ void ObjCARCOpt::OptimizeReturns(Function &F) {
       continue;
 
     CallInst *Retain = FindPredecessorRetainWithSafePath(
-        Arg, &BB, Autorelease, DependingInstructions, Visited, PA);
+        Arg, Autorelease->getParent(), Autorelease, DependingInstructions,
+        Visited, PA);
     DependingInstructions.clear();
     Visited.clear();
 
index e99ba92dc458145869c04c4423f4fe215d878493..d84a875684fb4e4ee6858403f0df7940cdf4951b 100644 (file)
@@ -314,6 +314,25 @@ define void @test25() {
   ret void
 }
 
+; Check that ObjCARCOpt::OptimizeReturns removes the redundant calls even when
+; they are not in the same basic block. This code used to cause an assertion
+; failure.
+
+; CHECK-LABEL: define i8* @test26()
+; CHECK: call i8* @returner()
+; CHECK-NOT:  call
+define i8* @test26() {
+bb0:
+  %v0 = call i8* @returner()
+  %v1 = tail call i8* @objc_retain(i8* %v0)
+  br label %bb1
+bb1:
+  %v2 = tail call i8* @objc_autoreleaseReturnValue(i8* %v1)
+  br label %bb2
+bb2:
+  ret i8* %v2
+}
+
 !0 = !{}
 
 ; CHECK: attributes [[NUW]] = { nounwind }