summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-05-03 21:39:56 +0000
committerJohn McCall <rjmccall@apple.com>2010-05-03 21:39:56 +0000
commit5828ee7a2782301ef4a54b7277d6b39f928c288e (patch)
tree038dcd7345fdc05bf33b00eb153f5d04677dc6a3 /clang
parentc936b568719a9b59da368beaa941247b6d057f13 (diff)
downloadbcm5719-llvm-5828ee7a2782301ef4a54b7277d6b39f928c288e.tar.gz
bcm5719-llvm-5828ee7a2782301ef4a54b7277d6b39f928c288e.zip
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
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/CGDecl.cpp3
-rw-r--r--clang/test/CodeGenCXX/static-init.cpp11
2 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 98a449ad764..244a5323d4b 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 a67d137d6a1..750da02603b 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;
+ }
+}
OpenPOWER on IntegriCloud