llvm.org GIT mirror llvm / 091b1e3
change instcombine to not turn a call to non-varargs bitcast of function prototype into a call to a varargs prototype. We do allow the xform if we have a definition, but otherwise we don't want to risk that we're changing the abi in a subtle way. On X86-64, for example, varargs require passing stuff in %al. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126363 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 8 years ago
3 changed file(s) with 30 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
952952 if (Callee->isDeclaration() && !isConvertible) return false;
953953 }
954954
955 if (FT->getNumParams() < NumActualArgs && !FT->isVarArg() &&
956 Callee->isDeclaration())
957 return false; // Do not delete arguments unless we have a function body.
958
955 if (Callee->isDeclaration()) {
956 // Do not delete arguments unless we have a function body.
957 if (FT->getNumParams() < NumActualArgs && !FT->isVarArg())
958 return false;
959
960 // If the callee is just a declaration, don't change the varargsness of the
961 // call. We don't want to introduce a varargs call where one doesn't
962 // already exist.
963 const PointerType *APTy = cast(CS.getCalledValue()->getType());
964 if (FT->isVarArg()!=cast(APTy->getElementType())->isVarArg())
965 return false;
966 }
967
959968 if (FT->getNumParams() < NumActualArgs && FT->isVarArg() &&
960969 !CallerPAL.isEmpty())
961970 // In this case we have more arguments than the new function type, but we
969978 return false;
970979 }
971980
981
972982 // Okay, we decided that this is a safe thing to do: go ahead and start
973 // inserting cast instructions as necessary...
983 // inserting cast instructions as necessary.
974984 std::vector Args;
975985 Args.reserve(NumActualArgs);
976986 SmallVector attrVec;
+0
-12
test/Transforms/InstCombine/2003-11-13-ConstExprCastCall.ll less more
None ; RUN: opt < %s -instcombine -S | FileCheck %s
1 target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
2
3 declare void @free(i8*)
4
5 define void @test(i32* %X) {
6 call void (...)* bitcast (void (i8*)* @free to void (...)*)( i32* %X ) ; :1 [#uses=0]
7 ; CHECK: %tmp = bitcast i32* %X to i8*
8 ; CHECK: call void @free(i8* %tmp)
9 ret void
10 ; CHECK: ret void
11 }
3131
3232 ; Resolving this should insert a cast from sbyte to int, following the C
3333 ; promotion rules.
34 declare void @test3a(i8, ...)
34 define void @test3a(i8, ...) {unreachable }
3535
3636 define void @test3(i8 %A, i8 %B) {
3737 call void bitcast (void (i8, ...)* @test3a to void (i8, i8)*)( i8 %A, i8 %B
115115 ; CHECK: @test8() {
116116 ; CHECK-NEXT: invoke void @test8a()
117117
118
119
120 ; Don't turn this into a direct call, because test9x is just a prototype and
121 ; doing so will make it varargs.
122 ; rdar://9038601
123 declare i8* @test9x(i8*, i8*, ...) noredzone
124 define i8* @test9(i8* %arg, i8* %tmp3) nounwind ssp noredzone {
125 entry:
126 %call = call i8* bitcast (i8* (i8*, i8*, ...)* @test9x to i8* (i8*, i8*)*)(i8* %arg, i8* %tmp3) noredzone
127 ret i8* %call
128 ; CHECK: @test9(
129 ; CHECK: call i8* bitcast
130 }
131