]> granicus.if.org Git - llvm/commitdiff
InstCombine: Don't strip bitcasts off of callsites marked 'thunk'
authorDavid Majnemer <david.majnemer@gmail.com>
Wed, 21 Jan 2015 22:32:04 +0000 (22:32 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Wed, 21 Jan 2015 22:32:04 +0000 (22:32 +0000)
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
test/Transforms/InstCombine/call-cast-target.ll

index 40f288c175caff354d67f6c08932f6fbecb7c43f..0223d69ab57a954a11887d09d57ace784ff1329f 100644 (file)
@@ -1381,6 +1381,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
+}