]> granicus.if.org Git - clang/commitdiff
Patch to fix a irgen crash accessing an initialized local static
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 26 May 2010 21:45:50 +0000 (21:45 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 26 May 2010 21:45:50 +0000 (21:45 +0000)
variable in a local function. Fixes pr7101.

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

lib/CodeGen/CGDecl.cpp
test/CodeGenCXX/static-local-in-local-class.cpp

index 8115e384db845e82b09771761690775e714ee9a1..07edca0f5fefbf4013b319313e8ab64c10978128 100644 (file)
@@ -239,8 +239,6 @@ void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D,
   // Store into LocalDeclMap before generating initializer to handle
   // circular references.
   DMEntry = GV;
-  if (getContext().getLangOptions().CPlusPlus)
-    CGM.setStaticLocalDeclAddress(&D, GV);
 
   // We can't have a VLA here, but we can have a pointer to a VLA,
   // even though that doesn't really make any sense.
@@ -269,6 +267,9 @@ void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D,
   if (D.hasAttr<UsedAttr>())
     CGM.AddUsedGlobal(GV);
 
+  if (getContext().getLangOptions().CPlusPlus)
+    CGM.setStaticLocalDeclAddress(&D, GV);
+  
   // We may have to cast the constant because of the initializer
   // mismatch above.
   //
index d9e044ce9d97d81758434b6bef2ccefcf9d4de15..ebf560ab9805d37aa8c2a47f14e940bc19b8dd5e 100644 (file)
@@ -19,3 +19,15 @@ void X::f() {
   }
   (void)i;
 }
+
+// pr7101
+void foo() {
+    static int n = 0;
+    struct Helper {
+        static void Execute() {
+            n++;
+        }
+    };
+    Helper::Execute();
+}
+