diff options
author | Duncan Sands <baldrick@free.fr> | 2008-01-13 08:02:44 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2008-01-13 08:02:44 +0000 |
commit | 781f6549dbc4a9a5a7a1eca048b16b9b4c70cde3 (patch) | |
tree | 3ae5ae5c59b88c5280adef08cf055834cb6ccf65 /llvm/lib | |
parent | d122bbdb0689fbea6910ef08b9383fcbecaf8a58 (diff) | |
download | bcm5719-llvm-781f6549dbc4a9a5a7a1eca048b16b9b4c70cde3.tar.gz bcm5719-llvm-781f6549dbc4a9a5a7a1eca048b16b9b4c70cde3.zip |
When turning a call to a bitcast function into a direct call,
if this becomes a varargs call then deal correctly with any
parameter attributes on the newly vararg call arguments.
llvm-svn: 45931
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 93fad0a1fae..ea53aec76cb 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -8142,9 +8142,9 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { return false; // Cannot transform this return value. if (!Caller->use_empty() && - !CastInst::isCastable(FT->getReturnType(), OldRetTy) && // void -> non-void is handled specially - FT->getReturnType() != Type::VoidTy) + FT->getReturnType() != Type::VoidTy && + !CastInst::isCastable(FT->getReturnType(), OldRetTy)) return false; // Cannot transform this return value. if (CallerPAL && !Caller->use_empty()) { @@ -8200,14 +8200,17 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { Callee->isDeclaration()) return false; // Do not delete arguments unless we have a function body... - if (FT->getNumParams() < NumActualArgs && FT->isVarArg()) + if (FT->getNumParams() < NumActualArgs && FT->isVarArg() && CallerPAL) // In this case we have more arguments than the new function type, but we - // won't be dropping them. Some of them may have attributes. If so, we - // cannot perform the transform because attributes are not allowed after - // the end of the function type. - if (CallerPAL && CallerPAL->size() && - CallerPAL->getParamIndex(CallerPAL->size()-1) > FT->getNumParams()) - return false; + // won't be dropping them. Check that these extra arguments have attributes + // that are compatible with being a vararg call argument. + for (unsigned i = CallerPAL->size(); i; --i) { + if (CallerPAL->getParamIndex(i - 1) <= FT->getNumParams()) + break; + uint16_t PAttrs = CallerPAL->getParamAttrsAtIndex(i - 1); + if (PAttrs & ParamAttr::VarArgsIncompatible) + return false; + } // Okay, we decided that this is a safe thing to do: go ahead and start // inserting cast instructions as necessary... @@ -8269,10 +8272,12 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { } else { Args.push_back(*AI); } - } - // No need to add parameter attributes - we already checked that there - // aren't any. + // Add any parameter attributes. + uint16_t PAttrs = CallerPAL ? CallerPAL->getParamAttrs(i + 1) : 0; + if (PAttrs) + attrVec.push_back(ParamAttrsWithIndex::get(i + 1, PAttrs)); + } } if (FT->getReturnType() == Type::VoidTy) |