| 1 | //===--- CallUtils.cpp - Shared call emission queries ---------------------===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "clang/CodeGenUtils/CallUtils.h" |
| 10 | #include "clang/AST/Attr.h" |
| 11 | #include "clang/AST/ExprCXX.h" |
| 12 | #include "clang/Basic/TargetCXXABI.h" |
| 13 | |
| 14 | namespace clang::CodeGenUtils { |
| 15 | |
| 16 | CanQual<FunctionProtoType> getFormalType(const CXXMethodDecl *MD) { |
| 17 | return MD->getType() |
| 18 | ->getCanonicalTypeUnqualified() |
| 19 | .getAs<FunctionProtoType>(); |
| 20 | } |
| 21 | |
| 22 | llvm::FPClassTest getNoFPClassTestMask(const LangOptions &LangOpts) { |
| 23 | llvm::FPClassTest Mask = llvm::fcNone; |
| 24 | if (LangOpts.NoHonorInfs) |
| 25 | Mask |= llvm::fcInf; |
| 26 | if (LangOpts.NoHonorNaNs) |
| 27 | Mask |= llvm::fcNan; |
| 28 | return Mask; |
| 29 | } |
| 30 | |
| 31 | bool isArgumentMaybeUndef(const Decl *TargetDecl, unsigned NumRequiredArgs, |
| 32 | unsigned ArgNo) { |
| 33 | const auto *FD = dyn_cast_or_null<FunctionDecl>(Val: TargetDecl); |
| 34 | if (!FD) |
| 35 | return false; |
| 36 | |
| 37 | // Assume variadic arguments do not have maybe_undef attribute. |
| 38 | if (ArgNo >= NumRequiredArgs) |
| 39 | return false; |
| 40 | |
| 41 | // Check if argument has maybe_undef attribute. |
| 42 | if (ArgNo < FD->getNumParams()) { |
| 43 | const ParmVarDecl *Param = FD->getParamDecl(i: ArgNo); |
| 44 | if (Param && Param->hasAttr<MaybeUndefAttr>()) |
| 45 | return true; |
| 46 | } |
| 47 | |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | EvaluationOrder getCallArgEvaluationOrder(const CallExpr *E) { |
| 52 | // Note that we allow this to override the order dictated by the calling |
| 53 | // convention on the MS ABI, which means that parameter destruction order is |
| 54 | // not necessarily reverse construction order. |
| 55 | // FIXME: Revisit this based on C++ committee response to unimplementability. |
| 56 | const auto *OCE = dyn_cast<CXXOperatorCallExpr>(Val: E); |
| 57 | if (!OCE) |
| 58 | return EvaluationOrder::Default; |
| 59 | |
| 60 | if (OCE->isAssignmentOp()) |
| 61 | return EvaluationOrder::ForceRightToLeft; |
| 62 | |
| 63 | switch (OCE->getOperator()) { |
| 64 | case OO_LessLess: |
| 65 | case OO_GreaterGreater: |
| 66 | case OO_AmpAmp: |
| 67 | case OO_PipePipe: |
| 68 | case OO_Comma: |
| 69 | case OO_ArrowStar: |
| 70 | return EvaluationOrder::ForceLeftToRight; |
| 71 | default: |
| 72 | return EvaluationOrder::Default; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | bool shouldEvaluateArgsLeftToRight(EvaluationOrder Order, |
| 77 | const TargetCXXABI &ABI) { |
| 78 | return ABI.areArgsDestroyedLeftToRightInCallee() |
| 79 | ? Order == EvaluationOrder::ForceLeftToRight |
| 80 | : Order != EvaluationOrder::ForceRightToLeft; |
| 81 | } |
| 82 | |
| 83 | } // namespace clang::CodeGenUtils |
| 84 |