diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:04 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:11 +0000 |
commit | e3b557809604d036af6e00c60f012c2025b59a5e (patch) | |
tree | 8a11ba2269a3b669601e2fd41145b174008f4da8 /llvm/lib/Transforms/Utils/CallPromotionUtils.cpp | |
parent | 08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff) |
Diffstat (limited to 'llvm/lib/Transforms/Utils/CallPromotionUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/CallPromotionUtils.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp index e530afc277db..4a82f9606d3f 100644 --- a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp +++ b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp @@ -415,18 +415,8 @@ bool llvm::isLegalToPromote(const CallBase &CB, Function *Callee, // site. unsigned I = 0; for (; I < NumParams; ++I) { - Type *FormalTy = Callee->getFunctionType()->getFunctionParamType(I); - Type *ActualTy = CB.getArgOperand(I)->getType(); - if (FormalTy == ActualTy) - continue; - if (!CastInst::isBitOrNoopPointerCastable(ActualTy, FormalTy, DL)) { - if (FailureReason) - *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) @@ -439,6 +429,28 @@ bool llvm::isLegalToPromote(const CallBase &CB, Function *Callee, *FailureReason = "inalloca mismatch"; return false; } + + Type *FormalTy = Callee->getFunctionType()->getFunctionParamType(I); + Type *ActualTy = CB.getArgOperand(I)->getType(); + if (FormalTy == ActualTy) + continue; + if (!CastInst::isBitOrNoopPointerCastable(ActualTy, FormalTy, DL)) { + if (FailureReason) + *FailureReason = "Argument type mismatch"; + return false; + } + + // MustTail call needs stricter type match. See + // Verifier::verifyMustTailCall(). + if (CB.isMustTailCall()) { + PointerType *PF = dyn_cast<PointerType>(FormalTy); + PointerType *PA = dyn_cast<PointerType>(ActualTy); + if (!PF || !PA || PF->getAddressSpace() != PA->getAddressSpace()) { + if (FailureReason) + *FailureReason = "Musttail call Argument type mismatch"; + return false; + } + } } for (; I < NumArgs; I++) { // Vararg functions can have more arguments than parameters. |