[llvm] r196711 - Fix inlining to not lose the "cleanup" clause from landingpads

Mark Seaborn mseaborn at chromium.org
Sat Dec 7 16:51:21 PST 2013


Author: mseaborn
Date: Sat Dec  7 18:51:21 2013
New Revision: 196711

URL: http://llvm.org/viewvc/llvm-project?rev=196711&view=rev
Log:
Fix inlining to not lose the "cleanup" clause from landingpads

This fixes PR17872.  This bug can lead to C++ destructors not being
called when they should be, when an exception is thrown.

Added:
    llvm/trunk/test/Transforms/Inline/invoke-cleanup.ll
Modified:
    llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp

Modified: llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp?rev=196711&r1=196710&r2=196711&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp Sat Dec  7 18:51:21 2013
@@ -238,6 +238,8 @@ static void HandleInlinedInvoke(InvokeIn
     InlinedLPad->reserveClauses(OuterNum);
     for (unsigned OuterIdx = 0; OuterIdx != OuterNum; ++OuterIdx)
       InlinedLPad->addClause(OuterLPad->getClause(OuterIdx));
+    if (OuterLPad->isCleanup())
+      InlinedLPad->setCleanup(true);
   }
 
   for (Function::iterator BB = FirstNewBlock, E = Caller->end(); BB != E; ++BB){

Added: llvm/trunk/test/Transforms/Inline/invoke-cleanup.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/invoke-cleanup.ll?rev=196711&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/Inline/invoke-cleanup.ll (added)
+++ llvm/trunk/test/Transforms/Inline/invoke-cleanup.ll Sat Dec  7 18:51:21 2013
@@ -0,0 +1,39 @@
+; RUN: opt %s -inline -S | FileCheck %s
+
+declare void @external_func()
+
+ at exception_type1 = external global i8
+ at exception_type2 = external global i8
+
+
+define internal void @inner() {
+  invoke void @external_func()
+      to label %cont unwind label %lpad
+cont:
+  ret void
+lpad:
+  %lp = landingpad i32 personality i8* null
+      catch i8* @exception_type1
+  resume i32 %lp
+}
+
+; Test that the "cleanup" clause is kept when inlining @inner() into
+; this call site (PR17872), otherwise C++ destructors will not be
+; called when they should be.
+
+define void @outer() {
+  invoke void @inner()
+      to label %cont unwind label %lpad
+cont:
+  ret void
+lpad:
+  %lp = landingpad i32 personality i8* null
+      cleanup
+      catch i8* @exception_type2
+  resume i32 %lp
+}
+; CHECK: define void @outer
+; CHECK: landingpad
+; CHECK-NEXT: cleanup
+; CHECK-NEXT: catch i8* @exception_type1
+; CHECK-NEXT: catch i8* @exception_type2





More information about the llvm-commits mailing list