[cfe-commits] r104526 - in /cfe/trunk: lib/Frontend/RewriteObjC.cpp test/Rewriter/rewrite-local-static-id.mm

Fariborz Jahanian fjahanian at apple.com
Mon May 24 11:32:56 PDT 2010


Author: fjahanian
Date: Mon May 24 13:32:56 2010
New Revision: 104526

URL: http://llvm.org/viewvc/llvm-project?rev=104526&view=rev
Log:
Fix a rewriting bug where a local static objective-c
pointer is copied into a block. Fixes radar 7924024.


Added:
    cfe/trunk/test/Rewriter/rewrite-local-static-id.mm
Modified:
    cfe/trunk/lib/Frontend/RewriteObjC.cpp

Modified: cfe/trunk/lib/Frontend/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteObjC.cpp?rev=104526&r1=104525&r2=104526&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Mon May 24 13:32:56 2010
@@ -5220,6 +5220,12 @@
         // FIXME: Conform to ABI ([[obj retain] autorelease]).
         FD = SynthBlockInitFunctionDecl((*I)->getNameAsCString());
         Exp = new (Context) DeclRefExpr(FD, FD->getType(), SourceLocation());
+        if (HasLocalVariableExternalStorage(*I)) {
+          QualType QT = (*I)->getType();
+          QT = Context->getPointerType(QT);
+          Exp = new (Context) UnaryOperator(Exp, UnaryOperator::AddrOf, QT,
+                                            SourceLocation());
+        }
       } else if (isTopLevelBlockPointerType((*I)->getType())) {
         FD = SynthBlockInitFunctionDecl((*I)->getNameAsCString());
         Arg = new (Context) DeclRefExpr(FD, FD->getType(), SourceLocation());

Added: cfe/trunk/test/Rewriter/rewrite-local-static-id.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-local-static-id.mm?rev=104526&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-local-static-id.mm (added)
+++ cfe/trunk/test/Rewriter/rewrite-local-static-id.mm Mon May 24 13:32:56 2010
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: %clang_cc1 -Wno-address-of-temporary -Did="void *" -D"SEL=void*" -D"__declspec(X)=" -emit-llvm -o %t %t-rw.cpp
+// radar 7946975
+
+void *sel_registerName(const char *);
+
+ at interface foo
+ at end
+
+ at interface foo2 : foo
++ (id)x;
+ at end
+
+typedef void (^b_t)(void);
+
+void bar(b_t block);
+
+void f() {
+        static id foo = 0;
+        bar(^{
+                foo = [foo2 x];
+        });
+}
+





More information about the cfe-commits mailing list