[cfe-commits] r102961 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp test/CodeGenCXX/static-init.cpp

John McCall rjmccall at apple.com
Mon May 3 14:39:56 PDT 2010


Author: rjmccall
Date: Mon May  3 16:39:56 2010
New Revision: 102961

URL: http://llvm.org/viewvc/llvm-project?rev=102961&view=rev
Log:
Just bail out immediately when emitting an unreachable function-local static
variable.  Surprisingly, this does seem to be the right way to solve this.


Modified:
    cfe/trunk/lib/CodeGen/CGDecl.cpp
    cfe/trunk/test/CodeGenCXX/static-init.cpp

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=102961&r1=102960&r2=102961&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Mon May  3 16:39:56 2010
@@ -231,6 +231,9 @@
 
 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!");
 

Modified: cfe/trunk/test/CodeGenCXX/static-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/static-init.cpp?rev=102961&r1=102960&r2=102961&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/static-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/static-init.cpp Mon May  3 16:39:56 2010
@@ -34,3 +34,14 @@
 void h3() {
   h2();
 }
+
+// PR6980: this shouldn't crash
+namespace test0 {
+  struct A { A(); };
+  __attribute__((noreturn)) int throw_exception();
+
+  void test() {
+    throw_exception();
+    static A r;
+  }
+}





More information about the cfe-commits mailing list