[cfe-commits] r97754 - /cfe/trunk/lib/Frontend/RewriteObjC.cpp

Fariborz Jahanian fjahanian at apple.com
Thu Mar 4 13:35:37 PST 2010


Author: fjahanian
Date: Thu Mar  4 15:35:37 2010
New Revision: 97754

URL: http://llvm.org/viewvc/llvm-project?rev=97754&view=rev
Log:
Patch to get around a rewriter bug rewriting storage class
on a block API struct definition.


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=97754&r1=97753&r2=97754&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Thu Mar  4 15:35:37 2010
@@ -4266,6 +4266,17 @@
   // Insert declaration for the function in which block literal is used.
   if (CurFunctionDeclToDeclareForBlock && !Blocks.empty())
     RewriteBlockLiteralFunctionDecl(CurFunctionDeclToDeclareForBlock);
+  bool RewriteSC = (GlobalVarDecl &&
+                    !Blocks.empty() &&
+                    GlobalVarDecl->getStorageClass() == VarDecl::Static &&
+                    GlobalVarDecl->getType().getCVRQualifiers());
+  if (RewriteSC) {
+    std::string SC(" void __");
+    SC += GlobalVarDecl->getNameAsString();
+    SC += "() {}";
+    InsertText(FunLocStart, SC);
+  }
+  
   // Insert closures that were part of the function.
   for (unsigned i = 0, count=0; i < Blocks.size(); i++) {
     CollectBlockDeclRefInfo(Blocks[i]);
@@ -4311,21 +4322,19 @@
     BlockByCopyDeclsPtrSet.clear();
     ImportedBlockDecls.clear();
   }
-  if (GlobalVarDecl && !Blocks.empty()) {
+  if (RewriteSC) {
     // 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);
+    if (GlobalVarDecl->getType().isRestrictQualified())
+      SC += "restrict ";
+    InsertText(FunLocStart, SC);
   }
   
   Blocks.clear();





More information about the cfe-commits mailing list