From a9e9918ee4e23a4d971cca8b970e378eb69cc049 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Mon, 2 Apr 2018 21:23:16 +0000 Subject: [PATCH] Treat inlining a notail call as a regular, non-tail call Otherwise, we end up inlining a musttail call into a non-tail position, which breaks verifier invariants. Fixes PR31014 llvm-svn: 329015 --- llvm/lib/Transforms/Utils/InlineFunction.cpp | 6 ++++++ llvm/test/Transforms/Inline/inline-tail.ll | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index a90628f..761c368 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1826,6 +1826,10 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI, if (CallInst *CI = dyn_cast(TheCall)) CallSiteTailKind = CI->getTailCallKind(); + // For inlining purposes, the "notail" marker is the same as no marker. + if (CallSiteTailKind == CallInst::TCK_NoTail) + CallSiteTailKind = CallInst::TCK_None; + for (Function::iterator BB = FirstNewBlock, E = Caller->end(); BB != E; ++BB) { for (auto II = BB->begin(); II != BB->end();) { @@ -1885,6 +1889,8 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI, // f -> musttail g -> tail f ==> f -> tail f // f -> g -> musttail f ==> f -> f // f -> g -> tail f ==> f -> f + // + // Inlined notail calls should remain notail calls. CallInst::TailCallKind ChildTCK = CI->getTailCallKind(); if (ChildTCK != CallInst::TCK_NoTail) ChildTCK = std::min(CallSiteTailKind, ChildTCK); diff --git a/llvm/test/Transforms/Inline/inline-tail.ll b/llvm/test/Transforms/Inline/inline-tail.ll index 7b0fe57..10b486c 100644 --- a/llvm/test/Transforms/Inline/inline-tail.ll +++ b/llvm/test/Transforms/Inline/inline-tail.ll @@ -196,3 +196,24 @@ define i32 @test_notail() { %rv = tail call i32 @notail() ret i32 %rv } + +; PR31014: Inlining a musttail call through a notail call site should remove +; any tail marking, otherwise we break verifier invariants. + +declare void @do_ret(i32) + +define void @test_notail_inline_musttail(i32 %a) { + notail call void @inline_musttail(i32 %a) + musttail call void @do_ret(i32 %a) + ret void +} + +define internal void @inline_musttail(i32 %a) { + musttail call void @do_ret(i32 %a) + ret void +} + +; CHECK-LABEL: define void @test_notail_inline_musttail(i32 %a) +; CHECK: {{^ *}}call void @do_ret(i32 %a) +; CHECK: musttail call void @do_ret(i32 %a) +; CHECK: ret void -- 2.7.4