summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2017-01-10 17:43:01 +0000
committerMatthias Braun <matze@braunis.de>2017-01-10 17:43:01 +0000
commit44bfe03da948871100c09f132e95c21e7d7297ba (patch)
tree3f003557e4e5428a4f8d12197699f8694395c5ed
parent3daffbf6a86430277f85c05abb93c1bd3316b8db (diff)
downloadbcm5719-llvm-44bfe03da948871100c09f132e95c21e7d7297ba.tar.gz
bcm5719-llvm-44bfe03da948871100c09f132e95c21e7d7297ba.zip
CGDecl: Skip static variable initializers in unreachable code
This fixes http://llvm.org/PR31054 Differential Revision: https://reviews.llvm.org/D28505 llvm-svn: 291576
-rw-r--r--clang/lib/CodeGen/CGDecl.cpp4
-rw-r--r--clang/test/CodeGenCXX/pr31054.cpp12
2 files changed, 14 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index d7613638016..0a88b2310be 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -311,7 +311,7 @@ CodeGenFunction::AddInitializerToStaticVarDecl(const VarDecl &D,
if (!Init) {
if (!getLangOpts().CPlusPlus)
CGM.ErrorUnsupported(D.getInit(), "constant l-value expression");
- else if (Builder.GetInsertBlock()) {
+ else if (HaveInsertPoint()) {
// Since we have a static initializer, this global variable can't
// be constant.
GV->setConstant(false);
@@ -352,7 +352,7 @@ CodeGenFunction::AddInitializerToStaticVarDecl(const VarDecl &D,
GV->setConstant(CGM.isTypeConstant(D.getType(), true));
GV->setInitializer(Init);
- if (hasNontrivialDestruction(D.getType())) {
+ if (hasNontrivialDestruction(D.getType()) && HaveInsertPoint()) {
// We have a constant initializer, but a nontrivial destructor. We still
// need to perform a guarded "initialization" in order to register the
// destructor.
diff --git a/clang/test/CodeGenCXX/pr31054.cpp b/clang/test/CodeGenCXX/pr31054.cpp
new file mode 100644
index 00000000000..33b17b9eafc
--- /dev/null
+++ b/clang/test/CodeGenCXX/pr31054.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+
+struct A { ~A(); };
+void func() {
+ return;
+ static A k;
+}
+
+// Test that we did not crash, by checking whether function was created.
+// CHECK-LABEL: define void @_Z4funcv() #0 {
+// CHECK: ret void
+// CHECK: }
OpenPOWER on IntegriCloud