]> granicus.if.org Git - clang/commitdiff
Fixes a bug whereby static const block var has static
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 4 Mar 2010 18:54:29 +0000 (18:54 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 4 Mar 2010 18:54:29 +0000 (18:54 +0000)
moved incorrectly. (radar 7714443).

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

lib/Frontend/RewriteObjC.cpp
test/Rewriter/rewrite-static-block.mm [new file with mode: 0644]

index a13bccbb91ecf2b002ce3eb4b4cc5fe1e6bcace4..a1fed8d58e591ce5142f610a3253c67b11ee0db4 100644 (file)
@@ -4311,6 +4311,23 @@ void RewriteObjC::SynthesizeBlockLiterals(SourceLocation FunLocStart,
     BlockByCopyDeclsPtrSet.clear();
     ImportedBlockDecls.clear();
   }
+  if (GlobalVarDecl && !Blocks.empty()) {
+    // Must insert any 'const/volatile/static here. Since it has been
+    // removed as result of rewriting of block literals.
+    // FIXME. We add as we need.
+    std::string SC;
+    if (GlobalVarDecl->getStorageClass() == VarDecl::Static)
+      SC = "static ";
+    if (GlobalVarDecl->getStorageClass() == VarDecl::Extern)
+      SC = "extern ";
+    if (GlobalVarDecl->getType().isConstQualified())
+      SC += "const ";
+    if (GlobalVarDecl->getType().isVolatileQualified())
+      SC += "volatile ";
+    if (!SC.empty())
+      InsertText(FunLocStart, SC);
+  }
+  
   Blocks.clear();
   InnerDeclRefsCount.clear();
   InnerDeclRefs.clear();
diff --git a/test/Rewriter/rewrite-static-block.mm b/test/Rewriter/rewrite-static-block.mm
new file mode 100644 (file)
index 0000000..c99557f
--- /dev/null
@@ -0,0 +1,11 @@
+// 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 -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp -emit-llvm -o %t-rw.ll
+// RUN: FileCheck --input-file=%t-rw.ll %s
+
+typedef void (^void_block_t)(void);
+
+static const void_block_t myblock = ^{
+        
+};
+
+// CHECK: myblock = internal global