]> granicus.if.org Git - llvm/commitdiff
Fix assert in ObjCARC optimizer when deleting retainBlock of null or undef.
authorPete Cooper <peter_cooper@apple.com>
Wed, 2 Jan 2019 21:00:02 +0000 (21:00 +0000)
committerPete Cooper <peter_cooper@apple.com>
Wed, 2 Jan 2019 21:00:02 +0000 (21:00 +0000)
The caller to EraseInstruction had this conditional:

    // ARC calls with null are no-ops. Delete them.
    if (IsNullOrUndef(Arg))

but the assert inside EraseInstruction only allowed ConstantPointerNull and not
undef or bitcasts.

This adds support for both of these cases.

rdar://problem/47003805

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

lib/Transforms/ObjCARC/ObjCARC.h
test/Transforms/ObjCARC/rv.ll

index 1dbe72c7569f4f519e245b9b6099d2d47c8fd80e..751c8f30e814c52c31c6bdf9335b7d9aee49b5c2 100644 (file)
@@ -58,7 +58,7 @@ static inline void EraseInstruction(Instruction *CI) {
     // Replace the return value with the argument.
     assert((IsForwarding(GetBasicARCInstKind(CI)) ||
             (IsNoopOnNull(GetBasicARCInstKind(CI)) &&
-             isa<ConstantPointerNull>(OldArg))) &&
+             IsNullOrUndef(OldArg->stripPointerCasts()))) &&
            "Can't delete non-forwarding instruction with users!");
     CI->replaceAllUsesWith(OldArg);
   }
index 604ef59f119d16dcf54f9176cecf428b7cbff9cc..ca3d7e2f848d10e12153b92f4eb9d32984155e85 100644 (file)
@@ -61,6 +61,11 @@ define void @test2() {
   call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* null)
   call i8* @llvm.objc.autoreleaseReturnValue(i8* null)
   ; call i8* @llvm.objc.retainAutoreleaseReturnValue(i8* null) ; TODO
+  %bitcast = bitcast i32* null to i8*
+  %rb = call i8* @llvm.objc.retainBlock(i8* %bitcast)
+  call void @use_pointer(i8* %rb)
+  %rb2 = call i8* @llvm.objc.retainBlock(i8* undef)
+  call void @use_pointer(i8* %rb2)
   ret void
 }