]> granicus.if.org Git - clang/commitdiff
Do up codegen for function static data and externs in functions in block
authorMike Stump <mrs@apple.com>
Fri, 13 Mar 2009 23:34:28 +0000 (23:34 +0000)
committerMike Stump <mrs@apple.com>
Fri, 13 Mar 2009 23:34:28 +0000 (23:34 +0000)
literals.

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

lib/CodeGen/CGBlocks.cpp
lib/CodeGen/CodeGenFunction.h
test/CodeGen/blocks-1.c

index a876938c02e95e5afbd7d75609d0760687ba8406..fcda90794e94b67d67e2d84c5eba3ff15805e440 100644 (file)
@@ -155,7 +155,8 @@ llvm::Value *CodeGenFunction::BuildBlockLiteralTmp(const BlockExpr *BE) {
     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 @@ BlockModule::GetAddrOfGlobalBlock(const BlockExpr *BE, const char * n) {
   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::Value *CodeGenFunction::LoadBlockStruct() {
 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());
 
index 0b34d7a92d41ddb34c58af3729caf667039673a1..7443e449166f8a4e1f18cab3032732ddfc29adeb 100644 (file)
@@ -272,6 +272,7 @@ public:
 
   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);
index df2a3fda6b8c911779efcb6f981463d1c33c1141..8572f8d6cf85d93996d63b2db90a6a3fc781b257 100644 (file)
@@ -41,9 +41,20 @@ void test3() {
   ^{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;
 }