diff options
author | Arthur Eubanks <aeubanks@google.com> | 2021-08-07 00:28:19 -0700 |
---|---|---|
committer | Arthur Eubanks <aeubanks@google.com> | 2021-08-13 16:52:04 -0700 |
commit | c19d7f8af0321d1b90343496ebd1c1aec3f1dc8c (patch) | |
tree | 62f003f0d4ef46fd75aef6ddf45ef20aa25da556 /llvm/lib/Transforms/Utils/CallPromotionUtils.cpp | |
parent | d5ff5ef65e1b66adf01e3c647c76578821338030 (diff) | |
download | llvm-c19d7f8af0321d1b90343496ebd1c1aec3f1dc8c.zip llvm-c19d7f8af0321d1b90343496ebd1c1aec3f1dc8c.tar.gz llvm-c19d7f8af0321d1b90343496ebd1c1aec3f1dc8c.tar.bz2 |
[CallPromotion] Check for inalloca/byval mismatch
Previously we would allow promotion even if the byval/inalloca
attributes on the call and the callee didn't match.
It's ok if the byval/inalloca types aren't the same. For example, LTO
importing may rename types.
Fixes PR51397.
Reviewed By: rnk
Differential Revision: https://reviews.llvm.org/D107998
Diffstat (limited to 'llvm/lib/Transforms/Utils/CallPromotionUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/CallPromotionUtils.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp index 33cb882..ebe19f1 100644 --- a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp +++ b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp @@ -424,6 +424,21 @@ bool llvm::isLegalToPromote(const CallBase &CB, Function *Callee, *FailureReason = "Argument type mismatch"; return false; } + // Make sure that the callee and call agree on byval/inalloca. The types do + // not have to match. + + if (Callee->hasParamAttribute(I, Attribute::ByVal) != + CB.getAttributes().hasParamAttr(I, Attribute::ByVal)) { + if (FailureReason) + *FailureReason = "byval mismatch"; + return false; + } + if (Callee->hasParamAttribute(I, Attribute::InAlloca) != + CB.getAttributes().hasParamAttr(I, Attribute::InAlloca)) { + if (FailureReason) + *FailureReason = "inalloca mismatch"; + return false; + } } for (; I < NumArgs; I++) { // Vararg functions can have more arguments than parameters. @@ -488,10 +503,11 @@ CallBase &llvm::promoteCall(CallBase &CB, Function *Callee, AttrBuilder ArgAttrs(CallerPAL.getParamAttrs(ArgNo)); ArgAttrs.remove(AttributeFuncs::typeIncompatible(FormalTy)); - // If byval is used, this must be a pointer type, and the byval type must - // match the element type. Update it if present. + // We may have a different byval/inalloca type. if (ArgAttrs.getByValType()) ArgAttrs.addByValAttr(Callee->getParamByValType(ArgNo)); + if (ArgAttrs.getInAllocaType()) + ArgAttrs.addInAllocaAttr(Callee->getParamInAllocaType(ArgNo)); NewArgAttrs.push_back(AttributeSet::get(Ctx, ArgAttrs)); AttributeChanged = true; |