[llvm] r299507 - [ObjCArc] Do not dereference an invalidated iterator.
Akira Hatanaka via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 4 20:44:10 PDT 2017
Author: ahatanak
Date: Tue Apr 4 22:44:09 2017
New Revision: 299507
URL: http://llvm.org/viewvc/llvm-project?rev=299507&view=rev
Log:
[ObjCArc] Do not dereference an invalidated iterator.
Fix a bug in ARC contract pass where an iterator that pointed to a
deleted instruction was dereferenced.
It appears that tryToContractReleaseIntoStoreStrong was incorrectly
assuming that a call to objc_retain would not immediately follow a call
to objc_release.
rdar://problem/25276306
Modified:
llvm/trunk/lib/Transforms/ObjCARC/ObjCARCContract.cpp
llvm/trunk/test/Transforms/ObjCARC/contract-storestrong.ll
Modified: llvm/trunk/lib/Transforms/ObjCARC/ObjCARCContract.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/ObjCARCContract.cpp?rev=299507&r1=299506&r2=299507&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/ObjCARC/ObjCARCContract.cpp (original)
+++ llvm/trunk/lib/Transforms/ObjCARC/ObjCARCContract.cpp Tue Apr 4 22:44:09 2017
@@ -394,6 +394,7 @@ void ObjCARCContract::tryToContractRelea
DEBUG(llvm::dbgs() << " New Store Strong: " << *StoreStrong << "\n");
+ if (&*Iter == Retain) ++Iter;
if (&*Iter == Store) ++Iter;
Store->eraseFromParent();
Release->eraseFromParent();
Modified: llvm/trunk/test/Transforms/ObjCARC/contract-storestrong.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ObjCARC/contract-storestrong.ll?rev=299507&r1=299506&r2=299507&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ObjCARC/contract-storestrong.ll (original)
+++ llvm/trunk/test/Transforms/ObjCARC/contract-storestrong.ll Tue Apr 4 22:44:09 2017
@@ -243,6 +243,19 @@ entry:
ret void
}
+; This used to crash.
+; CHECK-LABEL: define i8* @test13(
+; CHECK: tail call void @objc_storeStrong(i8** %{{.*}}, i8* %[[NEW:.*]])
+; CHECK-NEXT: ret i8* %[[NEW]]
+
+define i8* @test13(i8* %a0, i8* %a1, i8** %addr, i8* %new) {
+ %old = load i8*, i8** %addr, align 8
+ call void @objc_release(i8* %old)
+ %retained = call i8* @objc_retain(i8* %new)
+ store i8* %retained, i8** %addr, align 8
+ ret i8* %retained
+}
+
!0 = !{}
; CHECK: attributes [[NUW]] = { nounwind }
More information about the llvm-commits
mailing list