diff options
author | John McCall <rjmccall@apple.com> | 2010-05-03 21:39:56 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-05-03 21:39:56 +0000 |
commit | e65ce966b6865b686b0a9ba4fc72dfadf3e83701 (patch) | |
tree | 73a08eca146d45e846c98a8a311d18d68f2c5208 | |
parent | a36f3ed3f19ebd78432d967325e9157ec02e1bdf (diff) |
Just bail out immediately when emitting an unreachable function-local static
variable. Surprisingly, this does seem to be the right way to solve this.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102961 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGDecl.cpp | 3 | ||||
-rw-r--r-- | test/CodeGenCXX/static-init.cpp | 11 |
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index 98a449ad76..244a5323d4 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/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/test/CodeGenCXX/static-init.cpp b/test/CodeGenCXX/static-init.cpp index a67d137d6a..750da02603 100644 --- a/test/CodeGenCXX/static-init.cpp +++ b/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; + } +} |