aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
diff options
context:
space:
mode:
authorHans Wennborg <hans@chromium.org>2020-06-08 18:36:56 +0200
committerHans Wennborg <hans@chromium.org>2020-06-08 21:10:27 +0200
commitfc202c5fec07c8dd24c6cb2e33c3bbdb5d54db6e (patch)
tree5aaaf7a6591f38bf4c011f10f55ae0c002f102e7 /llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
parentc07339c6754e1faf4078d3c592c0ae28455503cd (diff)
downloadllvm-fc202c5fec07c8dd24c6cb2e33c3bbdb5d54db6e.zip
llvm-fc202c5fec07c8dd24c6cb2e33c3bbdb5d54db6e.tar.gz
llvm-fc202c5fec07c8dd24c6cb2e33c3bbdb5d54db6e.tar.bz2
[PGO] CallPromotion: Don't try to pass sret args to varargs functions
It's not allowed by the verifier. Differential revision: https://reviews.llvm.org/D81409
Diffstat (limited to 'llvm/lib/Transforms/Utils/CallPromotionUtils.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/CallPromotionUtils.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
index a7a0290..5a47c1f 100644
--- a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
+++ b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
@@ -403,9 +403,12 @@ bool llvm::isLegalToPromote(const CallBase &CB, Function *Callee,
// The number of formal arguments of the callee.
unsigned NumParams = Callee->getFunctionType()->getNumParams();
+ // The number of actual arguments in the call.
+ unsigned NumArgs = CB.arg_size();
+
// Check the number of arguments. The callee and call site must agree on the
// number of arguments.
- if (CB.arg_size() != NumParams && !Callee->isVarArg()) {
+ if (NumArgs != NumParams && !Callee->isVarArg()) {
if (FailureReason)
*FailureReason = "The number of arguments mismatch";
return false;
@@ -414,7 +417,8 @@ bool llvm::isLegalToPromote(const CallBase &CB, Function *Callee,
// Check the argument types. The callee's formal argument types must be
// bitcast compatible with the corresponding actual argument types of the call
// site.
- for (unsigned I = 0; I < NumParams; ++I) {
+ unsigned I = 0;
+ for (; I < NumParams; ++I) {
Type *FormalTy = Callee->getFunctionType()->getFunctionParamType(I);
Type *ActualTy = CB.getArgOperand(I)->getType();
if (FormalTy == ActualTy)
@@ -425,6 +429,14 @@ bool llvm::isLegalToPromote(const CallBase &CB, Function *Callee,
return false;
}
}
+ for (; I < NumArgs; I++) {
+ // Vararg functions can have more arguments than paramters.
+ assert(Callee->isVarArg());
+ if (CB.paramHasAttr(I, Attribute::StructRet)) {
+ *FailureReason = "SRet arg to vararg function";
+ return false;
+ }
+ }
return true;
}