[llvm] r250234 - [InlineFunction] Correctly inline TerminatePadInst

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 13 15:08:18 PDT 2015


Author: majnemer
Date: Tue Oct 13 17:08:17 2015
New Revision: 250234

URL: http://llvm.org/viewvc/llvm-project?rev=250234&view=rev
Log:
[InlineFunction] Correctly inline TerminatePadInst

We forgot to append the terminatepad's arguments which resulted in us
treating the old terminatepad as an argument to the new terminatepad
causing us to crash immediately.  Instead, add the old terminatepad's
arguments to the new terminatepad.

This fixes PR25155.

Added:
    llvm/trunk/test/Transforms/Inline/PR25155.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=250234&r1=250233&r2=250234&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp Tue Oct 13 17:08:17 2015
@@ -341,9 +341,10 @@ static void HandleInlinedEHPad(InvokeIns
       } else if (auto *TPI = dyn_cast<TerminatePadInst>(I)) {
         if (TPI->unwindsToCaller()) {
           SmallVector<Value *, 3> TerminatePadArgs;
-          for (Value *Operand : TPI->operands())
-            TerminatePadArgs.push_back(Operand);
-          TerminatePadInst::Create(TPI->getContext(), UnwindDest, TPI);
+          for (Value *ArgOperand : TPI->arg_operands())
+            TerminatePadArgs.push_back(ArgOperand);
+          TerminatePadInst::Create(TPI->getContext(), UnwindDest,
+                                   TerminatePadArgs, TPI);
           TPI->eraseFromParent();
           UpdatePHINodes(&*BB);
         }
@@ -1048,13 +1049,17 @@ bool llvm::InlineFunction(CallSite CS, I
 
   // Get the personality function from the callee if it contains a landing pad.
   Constant *CalledPersonality =
-      CalledFunc->hasPersonalityFn() ? CalledFunc->getPersonalityFn() : nullptr;
+      CalledFunc->hasPersonalityFn()
+          ? CalledFunc->getPersonalityFn()->stripPointerCasts()
+          : nullptr;
 
   // Find the personality function used by the landing pads of the caller. If it
   // exists, then check to see that it matches the personality function used in
   // the callee.
   Constant *CallerPersonality =
-      Caller->hasPersonalityFn() ? Caller->getPersonalityFn() : nullptr;
+      Caller->hasPersonalityFn()
+          ? Caller->getPersonalityFn()->stripPointerCasts()
+          : nullptr;
   if (CalledPersonality) {
     if (!CallerPersonality)
       Caller->setPersonalityFn(CalledPersonality);

Added: llvm/trunk/test/Transforms/Inline/PR25155.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/PR25155.ll?rev=250234&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/Inline/PR25155.ll (added)
+++ llvm/trunk/test/Transforms/Inline/PR25155.ll Tue Oct 13 17:08:17 2015
@@ -0,0 +1,54 @@
+; RUN: opt < %s -inline -S | FileCheck %s
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc18.0.0"
+
+define void @f() personality i32 (...)* @__CxxFrameHandler3 {
+entry:
+  invoke void @g()
+          to label %try.cont unwind label %catch.dispatch
+
+catch.dispatch:                                   ; preds = %entry
+  %0 = catchpad [i8* null, i32 64, i8* null]
+          to label %catch unwind label %catchendblock
+
+catch:                                            ; preds = %catch.dispatch
+  invoke void @dtor()
+          to label %invoke.cont.1 unwind label %catchendblock
+
+invoke.cont.1:                                    ; preds = %catch
+  catchret %0 to label %try.cont
+
+try.cont:                                         ; preds = %entry, %invoke.cont.1
+  ret void
+
+catchendblock:                                    ; preds = %catch, %catch.dispatch
+  catchendpad unwind to caller
+}
+
+; CHECK-LABEL:  define void @f(
+
+; CHECK:         invoke void @g()
+; CHECK:                 to label %dtor.exit unwind label %terminate.i
+
+; CHECK:       terminate.i:
+; CHECK-NEXT:    terminatepad [void ()* @terminate] unwind label %catchendblock
+
+; CHECK:       catchendblock:
+; CHECK-NEXT:    catchendpad unwind to caller
+
+declare i32 @__CxxFrameHandler3(...)
+
+define internal void @dtor() personality i32 (...)* @__CxxFrameHandler3 {
+entry:
+  invoke void @g()
+          to label %invoke.cont unwind label %terminate
+
+invoke.cont:                                      ; preds = %entry
+  ret void
+
+terminate:                                        ; preds = %entry
+  terminatepad [void ()* @terminate] unwind to caller
+}
+
+declare void @g()
+declare void @terminate()




More information about the llvm-commits mailing list