[cfe-commits] r66984 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp lib/CodeGen/CodeGenFunction.h test/CodeGen/blocks-1.c

Mike Stump mrs at apple.com
Fri Mar 13 16:34:28 PDT 2009


Author: mrs
Date: Fri Mar 13 18:34:28 2009
New Revision: 66984

URL: http://llvm.org/viewvc/llvm-project?rev=66984&view=rev
Log:
Do up codegen for function static data and externs in functions in block
literals.

Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    cfe/trunk/test/CodeGen/blocks-1.c

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=66984&r1=66983&r2=66984&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Fri Mar 13 18:34:28 2009
@@ -155,7 +155,8 @@
     uint64_t subBlockSize, subBlockAlign;
     llvm::SmallVector<const Expr *, 8> subBlockDeclRefDecls;
     llvm::Function *Fn
-      = CodeGenFunction(CGM).GenerateBlockFunction(BE, Info, subBlockSize,
+      = CodeGenFunction(CGM).GenerateBlockFunction(BE, Info, LocalDeclMap,
+                                                   subBlockSize,
                                                    subBlockAlign,
                                                    subBlockDeclRefDecls,
                                                    BlockHasCopyDispose);
@@ -558,8 +559,10 @@
   uint64_t subBlockSize, subBlockAlign;
   llvm::SmallVector<const Expr *, 8> subBlockDeclRefDecls;
   bool subBlockHasCopyDispose = false;
+  llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
   llvm::Function *Fn
-    = CodeGenFunction(CGM).GenerateBlockFunction(BE, Info, subBlockSize,
+    = CodeGenFunction(CGM).GenerateBlockFunction(BE, Info, LocalDeclMap,
+                                                 subBlockSize,
                                                  subBlockAlign,
                                                  subBlockDeclRefDecls,
                                                  subBlockHasCopyDispose);
@@ -602,10 +605,24 @@
 llvm::Function *
 CodeGenFunction::GenerateBlockFunction(const BlockExpr *BExpr,
                                        const BlockInfo& Info,
+                                  llvm::DenseMap<const Decl*, llvm::Value*> ldm,
                                        uint64_t &Size,
                                        uint64_t &Align,
                        llvm::SmallVector<const Expr *, 8> &subBlockDeclRefDecls,
                                        bool &subBlockHasCopyDispose) {
+  // Arrange for local static and local extern declarations to appear
+  // to be local to this function as well, as they are directly referenced
+  // in a block.
+  for (llvm::DenseMap<const Decl *, llvm::Value*>::iterator i = ldm.begin();
+       i != ldm.end();
+       ++i) {
+    const VarDecl *VD = dyn_cast<VarDecl>(i->first);
+    
+    if (VD->getStorageClass() == VarDecl::Static
+        || VD->getStorageClass() == VarDecl::Extern)
+      LocalDeclMap[VD] = i->second;
+  }
+
   const FunctionProtoType *FTy =
     cast<FunctionProtoType>(BExpr->getFunctionType());
 

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=66984&r1=66983&r2=66984&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Mar 13 18:34:28 2009
@@ -272,6 +272,7 @@
 
   llvm::Function *GenerateBlockFunction(const BlockExpr *BExpr,
                                         const BlockInfo& Info,
+                                  llvm::DenseMap<const Decl*, llvm::Value*> ldm,
                                         uint64_t &Size, uint64_t &Align,
                       llvm::SmallVector<const Expr *, 8> &subBlockDeclRefDecls,
                                         bool &subBlockHasCopyDispose);

Modified: cfe/trunk/test/CodeGen/blocks-1.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/blocks-1.c?rev=66984&r1=66983&r2=66984&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/blocks-1.c (original)
+++ cfe/trunk/test/CodeGen/blocks-1.c Fri Mar 13 18:34:28 2009
@@ -41,9 +41,20 @@
   ^{j=0; k=0;}();
 }
 
+int test4() {
+  extern int g;
+  static int i = 1;
+  ^(int j){ i = j; g = 0; }(0);
+  return i + g;
+}
+
+int g;
+
 int main() {
+  int rv = 0;
   test1();
   test2();
   test3();
-  return 0;
+  rv += test4();
+  return rv;
 }





More information about the cfe-commits mailing list