]> granicus.if.org Git - clang/commitdiff
Emit the globals, metadata, etc. associated with static variables even when
authorJohn McCall <rjmccall@apple.com>
Tue, 4 May 2010 20:45:42 +0000 (20:45 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 4 May 2010 20:45:42 +0000 (20:45 +0000)
they're unreachable.  This matters because (if they're POD, or if this is C)
the scope containing the variable might be reachable even if the variable
isn't.  Fixes PR7044.

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

lib/CodeGen/CGDecl.cpp
lib/CodeGen/CGDeclCXX.cpp
test/CodeGen/staticinit.c

index ba3a2b47edb4b1fa2eb8aa1707eb05f6e4e66c26..48198ff5761bcadfb9903a802b11b9aaa983b53c 100644 (file)
@@ -231,9 +231,6 @@ CodeGenFunction::AddInitializerToGlobalBlockVarDecl(const VarDecl &D,
 
 void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D,
                                       llvm::GlobalValue::LinkageTypes Linkage) {
-  // Bail out early if the block is unreachable.
-  if (!Builder.GetInsertBlock()) return;
-
   llvm::Value *&DMEntry = LocalDeclMap[&D];
   assert(DMEntry == 0 && "Decl already exists in localdeclmap!");
 
@@ -245,9 +242,9 @@ void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D,
   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.
   // Make sure to evaluate VLA bounds now so that we have them for later.
-  //
-  // FIXME: Can this happen?
   if (D.getType()->isVariablyModifiedType())
     EmitVLASize(D.getType());
 
index f6c805fdcaa0357d89a26bcd8c69e7250cb0e1fe..6afa53868ecc035de5cc32fb3912563f7c09ede8 100644 (file)
@@ -279,6 +279,9 @@ static llvm::Constant *getGuardAbortFn(CodeGenFunction &CGF) {
 void
 CodeGenFunction::EmitStaticCXXBlockVarDeclInit(const VarDecl &D,
                                                llvm::GlobalVariable *GV) {
+  // Bail out early if this initializer isn't reachable.
+  if (!Builder.GetInsertBlock()) return;
+
   bool ThreadsafeStatics = getContext().getLangOptions().ThreadsafeStatics;
   
   llvm::SmallString<256> GuardVName;
index cd1f059e570af386d3f976cf5a7cae3a20862bcf..8c5cdd05642d2333a086b6875a54af2370600b29 100644 (file)
@@ -29,3 +29,13 @@ void foo(void) {
 // RUN: grep "f1.l0 = internal global i32 ptrtoint (i32 ()\* @f1 to i32)" %t
 int f1(void) { static int l0 = (unsigned) f1; }
 
+// PR7044
+char *f2(char key) {
+  switch (key) {
+    static char _msg[40];
+  case '\014':
+    return _msg;
+  }
+
+  return 0;
+}