]> granicus.if.org Git - llvm/commitdiff
Merging r226708:
authorHans Wennborg <hans@hanshq.net>
Thu, 22 Jan 2015 19:40:47 +0000 (19:40 +0000)
committerHans Wennborg <hans@hanshq.net>
Thu, 22 Jan 2015 19:40:47 +0000 (19:40 +0000)
------------------------------------------------------------------------
r226708 | majnemer | 2015-01-21 14:32:04 -0800 (Wed, 21 Jan 2015) | 4 lines

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/branches/release_36@226854 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCalls.cpp
test/Transforms/InstCombine/call-cast-target.ll

index dab2c4b47ad66da89f27d72b0d31fe821a4c822b..83b4b82311f28fc78cdb1ab62e1c292c6641502b 100644 (file)
@@ -1376,6 +1376,10 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
     dyn_cast<Function>(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();
 
index b82dd99db36f6c28c1c8e83b4a9962703d39191b..4a5c94961e296aa94bd64d574c761eb4228396aa 100644 (file)
@@ -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
+}