[cfe-commits] r109698 - in /cfe/trunk: lib/Rewrite/RewriteObjC.cpp test/Rewriter/rewrite-block-consts.mm
Fariborz Jahanian
fjahanian at apple.com
Wed Jul 28 16:27:30 PDT 2010
Author: fjahanian
Date: Wed Jul 28 18:27:30 2010
New Revision: 109698
URL: http://llvm.org/viewvc/llvm-project?rev=109698&view=rev
Log:
Initialize block's imported variable(s) in
block's synthesized constructor initalizer list.
Fixes radar 8240371.
Added:
cfe/trunk/test/Rewriter/rewrite-block-consts.mm
Modified:
cfe/trunk/lib/Rewrite/RewriteObjC.cpp
Modified: cfe/trunk/lib/Rewrite/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteObjC.cpp?rev=109698&r1=109697&r2=109698&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteObjC.cpp Wed Jul 28 18:27:30 2010
@@ -4309,37 +4309,48 @@
S += FieldName + "; // by ref\n";
}
// Finish writing the constructor.
- Constructor += ", int flags=0) {\n";
- if (GlobalVarDecl)
- Constructor += " impl.isa = &_NSConcreteGlobalBlock;\n";
- else
- Constructor += " impl.isa = &_NSConcreteStackBlock;\n";
- Constructor += " impl.Flags = flags;\n impl.FuncPtr = fp;\n";
-
- Constructor += " Desc = desc;\n";
-
+ Constructor += ", int flags=0)";
// Initialize all "by copy" arguments.
+ bool firsTime = true;
for (llvm::SmallVector<ValueDecl*,8>::iterator I = BlockByCopyDecls.begin(),
E = BlockByCopyDecls.end(); I != E; ++I) {
std::string Name = (*I)->getNameAsString();
- Constructor += " ";
- if (isTopLevelBlockPointerType((*I)->getType()))
- Constructor += Name + " = (struct __block_impl *)_";
- else
- Constructor += Name + " = _";
- Constructor += Name + ";\n";
+ if (firsTime) {
+ Constructor += " : ";
+ firsTime = false;
+ }
+ else
+ Constructor += ", ";
+ if (isTopLevelBlockPointerType((*I)->getType()))
+ Constructor += Name + "((struct __block_impl *)_" + Name + ")";
+ else
+ Constructor += Name + "(_" + Name + ")";
}
// Initialize all "by ref" arguments.
for (llvm::SmallVector<ValueDecl*,8>::iterator I = BlockByRefDecls.begin(),
E = BlockByRefDecls.end(); I != E; ++I) {
std::string Name = (*I)->getNameAsString();
- Constructor += " ";
+ if (firsTime) {
+ Constructor += " : ";
+ firsTime = false;
+ }
+ else
+ Constructor += ", ";
if (isTopLevelBlockPointerType((*I)->getType()))
- Constructor += Name + " = (struct __block_impl *)_";
+ Constructor += Name + "((struct __block_impl *)_"
+ + Name + "->__forwarding)";
else
- Constructor += Name + " = _";
- Constructor += Name + "->__forwarding;\n";
+ Constructor += Name + "(_" + Name + "->__forwarding)";
}
+
+ Constructor += " {\n";
+ if (GlobalVarDecl)
+ Constructor += " impl.isa = &_NSConcreteGlobalBlock;\n";
+ else
+ Constructor += " impl.isa = &_NSConcreteStackBlock;\n";
+ Constructor += " impl.Flags = flags;\n impl.FuncPtr = fp;\n";
+
+ Constructor += " Desc = desc;\n";
} else {
// Finish writing the constructor.
Constructor += ", int flags=0) {\n";
Added: cfe/trunk/test/Rewriter/rewrite-block-consts.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-block-consts.mm?rev=109698&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-block-consts.mm (added)
+++ cfe/trunk/test/Rewriter/rewrite-block-consts.mm Wed Jul 28 18:27:30 2010
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// rdar:// 8243071
+
+void x(int y) {}
+void f() {
+ const int bar = 3;
+ int baz = 4;
+ __block int bab = 4;
+ __block const int bas = 5;
+ void (^b)() = ^{
+ x(bar);
+ x(baz);
+ x(bab);
+ x(bas);
+ b();
+ };
+ b();
+}
More information about the cfe-commits
mailing list