[cfe-commits] r107676 - in /cfe/trunk: lib/CodeGen/CodeGenFunction.cpp test/CodeGenCXX/destructors.cpp

John McCall rjmccall at apple.com
Tue Jul 6 10:35:03 PDT 2010


Author: rjmccall
Date: Tue Jul  6 12:35:03 2010
New Revision: 107676

URL: http://llvm.org/viewvc/llvm-project?rev=107676&view=rev
Log:
When destroying a cleanup, kill any references to instructions in the entry
block before deleting it.  Fixes PR7575.

This really just a short-term fix before implementing lazy cleanups.


Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/test/CodeGenCXX/destructors.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=107676&r1=107675&r2=107676&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Tue Jul  6 12:35:03 2010
@@ -688,6 +688,12 @@
     llvm::BranchInst::Create(CGF.getUnreachableBlock(), Exit);
 
   assert(!Entry->getParent() && "cleanup entry already positioned?");
+  // We can't just delete the entry; we have to kill any references to
+  // its instructions in other blocks.
+  for (llvm::BasicBlock::iterator I = Entry->begin(), E = Entry->end();
+         I != E; ++I)
+    if (!I->use_empty())
+      I->replaceAllUsesWith(llvm::UndefValue::get(I->getType()));
   delete Entry;
 }
 

Modified: cfe/trunk/test/CodeGenCXX/destructors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/destructors.cpp?rev=107676&r1=107675&r2=107676&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/destructors.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/destructors.cpp Tue Jul  6 12:35:03 2010
@@ -228,6 +228,37 @@
   }
 }
 
+// PR7575
+namespace test5 {
+  struct A { ~A(); };
+
+  // This is really unnecessarily verbose; we should be using phis,
+  // even at -O0.
+
+  // CHECK: define void @_ZN5test53fooEv()
+  // CHECK:      [[ELEMS:%.*]] = alloca [5 x [[A:%.*]]], align
+  // CHECK-NEXT: [[IVAR:%.*]] = alloca i64
+  // CHECK:      [[ELEMSARRAY:%.*]] = bitcast [5 x [[A]]]* [[ELEMS]] to [[A]]
+  // CHECK-NEXT: store i64 5, i64* [[IVAR]]
+  // CHECK-NEXT: br label
+  // CHECK:      [[I:%.*]] = load i64* [[IVAR]]
+  // CHECK-NEXT: icmp ne i64 [[I]], 0
+  // CHECK-NEXT: br i1
+  // CHECK:      [[I:%.*]] = load i64* [[IVAR]]
+  // CHECK-NEXT: [[I2:%.*]] = sub i64 [[I]], 1
+  // CHECK-NEXT: getelementptr inbounds [[A]]* [[ELEMSARRAY]], i64 [[I2]]
+  // CHECK-NEXT: call void @_ZN5test51AD1Ev(
+  // CHECK-NEXT: br label
+  // CHECK:      [[I:%.*]] = load i64* [[IVAR]]
+  // CHECK-NEXT: [[I1:%.*]] = sub i64 [[I]], 1
+  // CHECK-NEXT: store i64 [[I1]], i64* [[IVAR]]
+  // CHECK-NEXT: br label
+  // CHECK:      ret void
+  void foo() {
+    A elems[5];
+  }
+}
+
 // Checks from test3:
 
   // CHECK: define internal void @_ZN5test312_GLOBAL__N_11CD2Ev(





More information about the cfe-commits mailing list