[cfe-commits] r103052 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp lib/CodeGen/CGDeclCXX.cpp test/CodeGen/staticinit.c

John McCall rjmccall at apple.com
Tue May 4 13:45:42 PDT 2010


Author: rjmccall
Date: Tue May  4 15:45:42 2010
New Revision: 103052

URL: http://llvm.org/viewvc/llvm-project?rev=103052&view=rev
Log:
Emit the globals, metadata, etc. associated with static variables even when
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.


Modified:
    cfe/trunk/lib/CodeGen/CGDecl.cpp
    cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
    cfe/trunk/test/CodeGen/staticinit.c

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=103052&r1=103051&r2=103052&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Tue May  4 15:45:42 2010
@@ -231,9 +231,6 @@
 
 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 @@
   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());
 

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=103052&r1=103051&r2=103052&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Tue May  4 15:45:42 2010
@@ -279,6 +279,9 @@
 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;

Modified: cfe/trunk/test/CodeGen/staticinit.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/staticinit.c?rev=103052&r1=103051&r2=103052&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/staticinit.c (original)
+++ cfe/trunk/test/CodeGen/staticinit.c Tue May  4 15:45:42 2010
@@ -29,3 +29,13 @@
 // 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;
+}





More information about the cfe-commits mailing list