From a5a7987394ca15334c03b7e168677a8056561062 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 24 May 2010 18:32:56 +0000 Subject: [PATCH] Fix a rewriting bug where a local static objective-c pointer is copied into a block. Fixes radar 7924024. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104526 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/RewriteObjC.cpp | 6 ++++++ test/Rewriter/rewrite-local-static-id.mm | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 test/Rewriter/rewrite-local-static-id.mm diff --git a/lib/Frontend/RewriteObjC.cpp b/lib/Frontend/RewriteObjC.cpp index 4027b37c69..46883c9901 100644 --- a/lib/Frontend/RewriteObjC.cpp +++ b/lib/Frontend/RewriteObjC.cpp @@ -5220,6 +5220,12 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, // 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()); diff --git a/test/Rewriter/rewrite-local-static-id.mm b/test/Rewriter/rewrite-local-static-id.mm new file mode 100644 index 0000000000..a0b85f4f4d --- /dev/null +++ b/test/Rewriter/rewrite-local-static-id.mm @@ -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 *); + +@interface foo +@end + +@interface foo2 : foo ++ (id)x; +@end + +typedef void (^b_t)(void); + +void bar(b_t block); + +void f() { + static id foo = 0; + bar(^{ + foo = [foo2 x]; + }); +} + -- 2.40.0