From 5828ee7a2782301ef4a54b7277d6b39f928c288e Mon Sep 17 00:00:00 2001 From: John McCall Date: Mon, 3 May 2010 21:39:56 +0000 Subject: [PATCH] Just bail out immediately when emitting an unreachable function-local static variable. Surprisingly, this does seem to be the right way to solve this. llvm-svn: 102961 --- clang/lib/CodeGen/CGDecl.cpp | 3 +++ clang/test/CodeGenCXX/static-init.cpp | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 98a449ad764d..244a5323d4b2 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -231,6 +231,9 @@ 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!"); diff --git a/clang/test/CodeGenCXX/static-init.cpp b/clang/test/CodeGenCXX/static-init.cpp index a67d137d6a1d..750da02603b3 100644 --- a/clang/test/CodeGenCXX/static-init.cpp +++ b/clang/test/CodeGenCXX/static-init.cpp @@ -34,3 +34,14 @@ inline void h2() { 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; + } +}