[llvm-commits] [llvm] r146577 - in /llvm/trunk: lib/Transforms/Scalar/ObjCARC.cpp test/Transforms/ObjCARC/basic.ll test/Transforms/ObjCARC/pointer-types.ll
Dan Gohman
gohman at apple.com
Wed Dec 14 11:10:53 PST 2011
Author: djg
Date: Wed Dec 14 13:10:53 2011
New Revision: 146577
URL: http://llvm.org/viewvc/llvm-project?rev=146577&view=rev
Log:
It turns out that clang does use pointer-to-function types to
point to ARC-managed pointers sometimes. This fixes rdar://10551239.
Added:
llvm/trunk/test/Transforms/ObjCARC/pointer-types.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp
llvm/trunk/test/Transforms/ObjCARC/basic.ll
Modified: llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp?rev=146577&r1=146576&r2=146577&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp Wed Dec 14 13:10:53 2011
@@ -179,9 +179,13 @@
Arg->hasNestAttr() ||
Arg->hasStructRetAttr())
return false;
- // Only consider values with pointer types, and not function pointers.
+ // Only consider values with pointer types.
+ // It seemes intuitive to exclude function pointer types as well, since
+ // functions are never reference-counted, however clang occasionally
+ // bitcasts reference-counted pointers to function-pointer type
+ // temporarily.
PointerType *Ty = dyn_cast<PointerType>(Op->getType());
- if (!Ty || isa<FunctionType>(Ty->getElementType()))
+ if (!Ty)
return false;
// Conservatively assume anything else is a potential use.
return true;
Modified: llvm/trunk/test/Transforms/ObjCARC/basic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ObjCARC/basic.ll?rev=146577&r1=146576&r2=146577&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ObjCARC/basic.ll (original)
+++ llvm/trunk/test/Transforms/ObjCARC/basic.ll Wed Dec 14 13:10:53 2011
@@ -1528,9 +1528,11 @@
; Like test52, but the pointer has function type, so it's assumed to
; be not reference counted.
+; Oops. That's wrong. Clang sometimes uses function types gratuitously.
+; See rdar://10551239.
; CHECK: define void @test53(
-; CHECK-NOT: @objc_
+; CHECK: @objc_
; CHECK: }
define void @test53(void ()** %zz, i8** %pp) {
%p = load i8** %pp
Added: llvm/trunk/test/Transforms/ObjCARC/pointer-types.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ObjCARC/pointer-types.ll?rev=146577&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/ObjCARC/pointer-types.ll (added)
+++ llvm/trunk/test/Transforms/ObjCARC/pointer-types.ll Wed Dec 14 13:10:53 2011
@@ -0,0 +1,31 @@
+; RUN: opt -objc-arc -S < %s | FileCheck %s
+
+; Don't hoist @objc_release past a use of its pointer, even
+; if the use has function type, because clang uses function types
+; in dubious ways.
+; rdar://10551239
+
+; CHECK: define void @test0(
+; CHECK: %otherBlock = phi void ()* [ %b1, %if.then ], [ null, %entry ]
+; CHECK-NEXT: call void @use_fptr(void ()* %otherBlock)
+; CHECK-NEXT: %tmp11 = bitcast void ()* %otherBlock to i8*
+; CHECK-NEXT: call void @objc_release(i8* %tmp11)
+
+define void @test0(i1 %tobool, void ()* %b1) {
+entry:
+ br i1 %tobool, label %if.end, label %if.then
+
+if.then: ; preds = %entry
+ br label %if.end
+
+if.end: ; preds = %if.then, %entry
+ %otherBlock = phi void ()* [ %b1, %if.then ], [ null, %entry ]
+ call void @use_fptr(void ()* %otherBlock)
+ %tmp11 = bitcast void ()* %otherBlock to i8*
+ call void @objc_release(i8* %tmp11) nounwind
+ ret void
+}
+
+declare void @use_fptr(void ()*)
+declare void @objc_release(i8*)
+
More information about the llvm-commits
mailing list