clang 24.0.0git
CallUtils.cpp
Go to the documentation of this file.
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
10#include "clang/AST/Attr.h"
11#include "clang/AST/ExprCXX.h"
13
14namespace clang::CodeGenUtils {
15
21
22llvm::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
31bool isArgumentMaybeUndef(const Decl *TargetDecl, unsigned NumRequiredArgs,
32 unsigned ArgNo) {
33 const auto *FD = dyn_cast_or_null<FunctionDecl>(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(ArgNo);
44 if (Param && Param->hasAttr<MaybeUndefAttr>())
45 return true;
46 }
47
48 return false;
49}
50
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>(E);
57 if (!OCE)
59
60 if (OCE->isAssignmentOp())
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:
71 default:
73 }
74}
75
82
83} // namespace clang::CodeGenUtils
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines the TargetCXXABI class, which abstracts details of the C++ ABI that we're targeting.
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2153
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:3012
Represents a canonical, potentially-qualified type.
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed.
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5548
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Represents a parameter to a function.
Definition Decl.h:1832
The basic abstraction for the target C++ ABI.
bool areArgsDestroyedLeftToRightInCallee() const
Are arguments to a call destroyed left to right in the callee?
CanQualType getCanonicalTypeUnqualified() const
QualType getType() const
Definition Decl.h:725
bool isArgumentMaybeUndef(const Decl *TargetDecl, unsigned NumRequiredArgs, unsigned ArgNo)
Definition CallUtils.cpp:31
CanQual< FunctionProtoType > getFormalType(const CXXMethodDecl *MD)
Returns the canonical formal type of the given C++ method.
Definition CallUtils.cpp:16
EvaluationOrder getCallArgEvaluationOrder(const CallExpr *E)
Returns the argument evaluation order the language requires for the given call.
Definition CallUtils.cpp:51
llvm::FPClassTest getNoFPClassTestMask(const LangOptions &LangOpts)
Returns the set of floating-point value kinds that the language options promise never reach a functio...
Definition CallUtils.cpp:22
EvaluationOrder
The order in which the arguments of a call must be evaluated.
Definition CallUtils.h:29
@ ForceLeftToRight
! Language semantics require left-to-right evaluation.
Definition CallUtils.h:33
@ Default
! No language constraints on evaluation order.
Definition CallUtils.h:31
@ ForceRightToLeft
! Language semantics require right-to-left evaluation.
Definition CallUtils.h:35
bool shouldEvaluateArgsLeftToRight(EvaluationOrder Order, const TargetCXXABI &ABI)
Returns true if call arguments should be emitted left-to-right, given the order the language requires...
Definition CallUtils.cpp:76