[cfe-commits] r161148 - in /cfe/trunk: lib/CodeGen/CGCleanup.cpp test/CodeGenCXX/throw-expression-cleanup.cpp

Eli Friedman eli.friedman at gmail.com
Wed Aug 1 17:10:24 PDT 2012


Author: efriedma
Date: Wed Aug  1 19:10:24 2012
New Revision: 161148

URL: http://llvm.org/viewvc/llvm-project?rev=161148&view=rev
Log:
Make sure we don't emit IR for unused EH cleanups.  PR13359.


Added:
    cfe/trunk/test/CodeGenCXX/throw-expression-cleanup.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGCleanup.cpp

Modified: cfe/trunk/lib/CodeGen/CGCleanup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCleanup.cpp?rev=161148&r1=161147&r2=161148&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCleanup.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCleanup.cpp Wed Aug  1 19:10:24 2012
@@ -831,8 +831,12 @@
 
     EmitBlock(EHEntry);
 
-    cleanupFlags.setIsForEHCleanup();
-    EmitCleanup(*this, Fn, cleanupFlags, EHActiveFlag);
+    // We only actually emit the cleanup code if the cleanup is either
+    // active or was used before it was deactivated.
+    if (EHActiveFlag || IsActive) {
+      cleanupFlags.setIsForEHCleanup();
+      EmitCleanup(*this, Fn, cleanupFlags, EHActiveFlag);
+    }
 
     Builder.CreateBr(getEHDispatchBlock(EHParent));
 

Added: cfe/trunk/test/CodeGenCXX/throw-expression-cleanup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/throw-expression-cleanup.cpp?rev=161148&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/throw-expression-cleanup.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/throw-expression-cleanup.cpp Wed Aug  1 19:10:24 2012
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 %s -emit-llvm -fcxx-exceptions -fexceptions -std=c++11 -o - | FileCheck %s
+// PR13359
+
+struct X {
+  ~X();
+};
+struct Error {
+  Error(const X&) noexcept;
+};
+
+void f() {
+  try {
+    throw Error(X());
+  } catch (...) { }
+}
+
+// CHECK: define void @_Z1fv
+// CHECK: call void @_ZN5ErrorC1ERK1X
+// CHECK: invoke void @__cxa_throw
+// CHECK: landingpad
+// CHECK: call void @_ZN1XD1Ev
+// CHECK-NOT: __cxa_free_exception





More information about the cfe-commits mailing list