From c070e4e5284849b42925667342da3ca6aac93040 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Wed, 21 Jan 2015 22:32:04 +0000 Subject: [PATCH] InstCombine: Don't strip bitcasts off of callsites marked 'thunk' The return type of a thunk is meaningless, we just want the arguments and return value to be forwarded. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226708 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineCalls.cpp | 4 ++++ test/Transforms/InstCombine/call-cast-target.ll | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index 40f288c175c..0223d69ab57 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -1381,6 +1381,10 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { dyn_cast(CS.getCalledValue()->stripPointerCasts()); if (!Callee) return false; + // The prototype of thunks are a lie, don't try to directly call such + // functions. + if (Callee->hasFnAttribute("thunk")) + return false; Instruction *Caller = CS.getInstruction(); const AttributeSet &CallerPAL = CS.getAttributes(); diff --git a/test/Transforms/InstCombine/call-cast-target.ll b/test/Transforms/InstCombine/call-cast-target.ll index b82dd99db36..4a5c94961e2 100644 --- a/test/Transforms/InstCombine/call-cast-target.ll +++ b/test/Transforms/InstCombine/call-cast-target.ll @@ -61,3 +61,14 @@ entry: %call = tail call i32 bitcast (i32 (i64)* @fn3 to i32 (i32*)*)(i32* %a) ret i32 %call } + +declare i32 @fn4(i32) "thunk" + +define i32 @test4(i32* %a) { +; CHECK-LABEL: @test4 +; CHECK: %[[call:.*]] = tail call i32 bitcast (i32 (i32)* @fn4 to i32 (i32*)*)(i32* %a) +; CHECK-NEXT: ret i32 %[[call]] +entry: + %call = tail call i32 bitcast (i32 (i32)* @fn4 to i32 (i32*)*)(i32* %a) + ret i32 %call +} -- 2.34.1