[PATCH] D28505: CGDecl: Skip static variable initializers in unreachable code

Phabricator via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 10 09:53:59 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL291576: CGDecl: Skip static variable initializers in unreachable code (authored by matze).

Changed prior to commit:
  https://reviews.llvm.org/D28505?vs=83754&id=83820#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28505

Files:
  cfe/trunk/lib/CodeGen/CGDecl.cpp
  cfe/trunk/test/CodeGenCXX/pr31054.cpp


Index: cfe/trunk/lib/CodeGen/CGDecl.cpp
===================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp
@@ -311,7 +311,7 @@
   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 @@
   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.
Index: cfe/trunk/test/CodeGenCXX/pr31054.cpp
===================================================================
--- cfe/trunk/test/CodeGenCXX/pr31054.cpp
+++ cfe/trunk/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: }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28505.83820.patch
Type: text/x-patch
Size: 1452 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170110/b631502d/attachment.bin>


More information about the cfe-commits mailing list