From dc024674ff96820d6020757b48d47f46d4c07db2 Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Tue, 27 Nov 2007 13:23:08 +0000 Subject: Fix PR1146: parameter attributes are longer part of the function type, instead they belong to functions and function calls. This is an updated and slightly corrected version of Reid Spencer's original patch. The only known problem is that auto-upgrading of bitcode files doesn't seem to work properly (see test/Bitcode/AutoUpgradeIntrinsics.ll). Hopefully a bitcode guru (who might that be? :) ) will fix it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44359 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/InstructionCombining.cpp | 29 ++++++++++++++++---------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'lib/Transforms/Scalar/InstructionCombining.cpp') diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index e90d1909ae..52c66a5d87 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -7994,13 +7994,15 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { const FunctionType *FT = Callee->getFunctionType(); const Type *OldRetTy = Caller->getType(); - const FunctionType *ActualFT = - cast(cast(CE->getType())->getElementType()); - + const ParamAttrsList* CallerPAL = 0; + if (CallInst *CallerCI = dyn_cast(Caller)) + CallerPAL = CallerCI->getParamAttrs(); + else if (InvokeInst *CallerII = dyn_cast(Caller)) + CallerPAL = CallerII->getParamAttrs(); + // If the parameter attributes are not compatible, don't do the xform. We // don't want to lose an sret attribute or something. - if (!ParamAttrsList::areCompatible(FT->getParamAttrs(), - ActualFT->getParamAttrs())) + if (!ParamAttrsList::areCompatible(CallerPAL, Callee->getParamAttrs())) return false; // Check to see if we are changing the return type... @@ -8135,12 +8137,15 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { NC = new InvokeInst(Callee, II->getNormalDest(), II->getUnwindDest(), Args.begin(), Args.end(), Caller->getName(), Caller); cast(NC)->setCallingConv(II->getCallingConv()); + cast(NC)->setParamAttrs(CallerPAL); } else { NC = new CallInst(Callee, Args.begin(), Args.end(), Caller->getName(), Caller); - if (cast(Caller)->isTailCall()) + CallInst *CI = cast(Caller); + if (CI->isTailCall()) cast(NC)->setTailCall(); - cast(NC)->setCallingConv(cast(Caller)->getCallingConv()); + cast(NC)->setCallingConv(CI->getCallingConv()); + cast(NC)->setParamAttrs(CallerPAL); } // Insert a cast of the return type as necessary. @@ -8191,7 +8196,7 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) { const PointerType *NestFPTy = cast(NestF->getType()); const FunctionType *NestFTy = cast(NestFPTy->getElementType()); - if (const ParamAttrsList *NestAttrs = NestFTy->getParamAttrs()) { + if (const ParamAttrsList *NestAttrs = NestF->getParamAttrs()) { unsigned NestIdx = 1; const Type *NestTy = 0; uint16_t NestAttr = 0; @@ -8239,7 +8244,7 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) { // Handle this by synthesizing a new function type, equal to FTy // with the chain parameter inserted. Likewise for attributes. - const ParamAttrsList *Attrs = FTy->getParamAttrs(); + const ParamAttrsList *Attrs = CS.getParamAttrs(); std::vector NewTypes; ParamAttrsVector NewAttrs; NewTypes.reserve(FTy->getNumParams()+1); @@ -8280,10 +8285,10 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) { // Replace the trampoline call with a direct call. Let the generic // code sort out any function type mismatches. FunctionType *NewFTy = - FunctionType::get(FTy->getReturnType(), NewTypes, FTy->isVarArg(), - ParamAttrsList::get(NewAttrs)); + FunctionType::get(FTy->getReturnType(), NewTypes, FTy->isVarArg()); Constant *NewCallee = NestF->getType() == PointerType::get(NewFTy) ? NestF : ConstantExpr::getBitCast(NestF, PointerType::get(NewFTy)); + const ParamAttrsList *NewPAL = ParamAttrsList::get(NewAttrs); Instruction *NewCaller; if (InvokeInst *II = dyn_cast(Caller)) { @@ -8292,6 +8297,7 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) { NewArgs.begin(), NewArgs.end(), Caller->getName(), Caller); cast(NewCaller)->setCallingConv(II->getCallingConv()); + cast(NewCaller)->setParamAttrs(NewPAL); } else { NewCaller = new CallInst(NewCallee, NewArgs.begin(), NewArgs.end(), Caller->getName(), Caller); @@ -8299,6 +8305,7 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) { cast(NewCaller)->setTailCall(); cast(NewCaller)-> setCallingConv(cast(Caller)->getCallingConv()); + cast(NewCaller)->setParamAttrs(NewPAL); } if (Caller->getType() != Type::VoidTy && !Caller->use_empty()) Caller->replaceAllUsesWith(NewCaller); -- cgit v1.2.3-70-g09d2