clang  10.0.0svn
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions
ExprConstant.cpp File Reference
#include <cstring>
#include <functional>
#include "Interp/Context.h"
#include "Interp/Frame.h"
#include "Interp/State.h"
#include "clang/AST/APValue.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTDiagnostic.h"
#include "clang/AST/ASTLambda.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/AST/CharUnits.h"
#include "clang/AST/CurrentSourceLocExprScope.h"
#include "clang/AST/Expr.h"
#include "clang/AST/OSLog.h"
#include "clang/AST/OptionalDiagnostic.h"
#include "clang/AST/RecordLayout.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/FixedPoint.h"
#include "clang/Basic/TargetInfo.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/raw_ostream.h"
#include "clang/AST/TypeNodes.inc"
#include "clang/AST/BuiltinTypes.def"
#include "clang/Basic/OpenCLImageTypes.def"
#include "clang/Basic/OpenCLExtensionTypes.def"
#include "clang/Basic/AArch64SVEACLETypes.def"
#include "clang/AST/StmtNodes.inc"
Include dependency graph for ExprConstant.cpp:

Go to the source code of this file.

Classes

struct  llvm::DenseMapInfo< ObjectUnderConstruction >
 
struct  DynamicType
 

Namespaces

 llvm
 Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion.
 

Macros

#define DEBUG_TYPE   "exprconstant"
 
#define TYPE(Class, Base)
 
#define ABSTRACT_TYPE(Class, Base)
 
#define NON_CANONICAL_TYPE(Class, Base)
 
#define DEPENDENT_TYPE(Class, Base)
 
#define NON_CANONICAL_UNLESS_DEPENDENT(Class, Base)
 
#define TYPE(ID, BASE)
 
#define DEPENDENT_TYPE(ID, BASE)   case Type::ID:
 
#define NON_CANONICAL_TYPE(ID, BASE)   case Type::ID:
 
#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(ID, BASE)   case Type::ID:
 
#define BUILTIN_TYPE(ID, SINGLETON_ID)
 
#define SIGNED_TYPE(ID, SINGLETON_ID)   case BuiltinType::ID: return GCCTypeClass::Integer;
 
#define FLOATING_TYPE(ID, SINGLETON_ID)   case BuiltinType::ID: return GCCTypeClass::RealFloat;
 
#define PLACEHOLDER_TYPE(ID, SINGLETON_ID)   case BuiltinType::ID: break;
 
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   case BuiltinType::Id:
 
#define EXT_OPAQUE_TYPE(ExtType, Id, Ext)   case BuiltinType::Id:
 
#define SVE_TYPE(Name, Id, SingletonId)   case BuiltinType::Id:
 
#define ABSTRACT_STMT(Node)
 
#define STMT(Node, Base)   case Expr::Node##Class:
 
#define EXPR(Node, Base)
 

Typedefs

using CheckedTemporaries = llvm::SmallPtrSet< const MaterializeTemporaryExpr *, 8 >
 Materialized temporaries that we've already checked to determine if they're initializsed by a constant expression. More...
 

Enumerations

enum  ConstructionPhase
 
enum  CheckEvaluationResultKind { CheckEvaluationResultKind::ConstantExpression, CheckEvaluationResultKind::FullyInitialized }
 
enum  EvalStmtResult
 
enum  GCCTypeClass {
  GCCTypeClass::None = -1, GCCTypeClass::Void = 0, GCCTypeClass::Integer = 1, GCCTypeClass::Enum = 3,
  GCCTypeClass::Bool = 4, GCCTypeClass::Pointer = 5, GCCTypeClass::PointerToDataMember = 7, GCCTypeClass::RealFloat = 8,
  GCCTypeClass::Complex = 9, GCCTypeClass::PointerToMemberFunction = 12, GCCTypeClass::ClassOrStruct = 12, GCCTypeClass::Union = 13
}
 Values returned by __builtin_classify_type, chosen to match the values produced by GCC's builtin. More...
 
enum  ICEKind
 

Functions

static bool HandleDestruction (EvalInfo &Info, const Expr *E, const LValue &This, QualType ThisType)
 Perform a destructor or pseudo-destructor call on the given object, which might in general not be a complete object. More...
 
static bool HandleDestruction (EvalInfo &Info, SourceLocation Loc, APValue::LValueBase LVBase, APValue &Value, QualType T)
 Destroy and end the lifetime of the given complete object. More...
 
static bool isRead (AccessKinds AK)
 
static bool isModification (AccessKinds AK)
 
static bool isAnyAccess (AccessKinds AK)
 
static bool isFormalAccess (AccessKinds AK)
 Is this an access per the C++ definition? More...
 
static bool Evaluate (APValue &Result, EvalInfo &Info, const Expr *E)
 
static bool EvaluateInPlace (APValue &Result, EvalInfo &Info, const LValue &This, const Expr *E, bool AllowNonLiteralTypes)
 EvaluateInPlace - Evaluate an expression in-place in an APValue. More...
 
static bool EvaluateLValue (const Expr *E, LValue &Result, EvalInfo &Info, bool InvalidBaseOK)
 Evaluate an expression as an lvalue. More...
 
static bool EvaluatePointer (const Expr *E, LValue &Result, EvalInfo &Info, bool InvalidBaseOK=false)
 
static bool EvaluateMemberPointer (const Expr *E, MemberPtr &Result, EvalInfo &Info)
 
static bool EvaluateTemporary (const Expr *E, LValue &Result, EvalInfo &Info)
 Evaluate an expression of record type as a temporary. More...
 
static bool EvaluateInteger (const Expr *E, APSInt &Result, EvalInfo &Info)
 
static bool EvaluateIntegerOrLValue (const Expr *E, APValue &Result, EvalInfo &Info)
 EvaluateIntegerOrLValue - Evaluate an rvalue integral-typed expression, and produce either the integer value or a pointer. More...
 
static bool EvaluateFloat (const Expr *E, APFloat &Result, EvalInfo &Info)
 
static bool EvaluateComplex (const Expr *E, ComplexValue &Res, EvalInfo &Info)
 
static bool EvaluateAtomic (const Expr *E, const LValue *This, APValue &Result, EvalInfo &Info)
 
static bool EvaluateAsRValue (EvalInfo &Info, const Expr *E, APValue &Result)
 EvaluateAsRValue - Try to evaluate this expression, performing an implicit lvalue-to-rvalue cast if it is an lvalue. More...
 
static bool EvaluateFixedPointOrInteger (const Expr *E, APFixedPoint &Result, EvalInfo &Info)
 Evaluate an integer or fixed point expression into an APResult. More...
 
static bool EvaluateFixedPoint (const Expr *E, APFixedPoint &Result, EvalInfo &Info)
 Evaluate only a fixed point expression into an APResult. More...
 
static void negateAsSigned (APSInt &Int)
 Negate an APSInt in place, converting it to a signed form if necessary, and preserving its value (by extending by up to one bit as needed). More...
 
static bool EvaluateIgnoredValue (EvalInfo &Info, const Expr *E)
 Evaluate an expression to see if it had side-effects, and discard its result. More...
 
static bool IsStringLiteralCall (const CallExpr *E)
 Should this call expression be treated as a string literal? More...
 
static bool IsGlobalLValue (APValue::LValueBase B)
 
static const ValueDeclGetLValueBaseDecl (const LValue &LVal)
 
static bool IsLiteralLValue (const LValue &Value)
 
static bool IsWeakLValue (const LValue &Value)
 
static bool isZeroSized (const LValue &Value)
 
static bool HasSameBase (const LValue &A, const LValue &B)
 
static void NoteLValueLocation (EvalInfo &Info, APValue::LValueBase Base)
 
static bool CheckEvaluationResult (CheckEvaluationResultKind CERK, EvalInfo &Info, SourceLocation DiagLoc, QualType Type, const APValue &Value, Expr::ConstExprUsage Usage, SourceLocation SubobjectLoc, CheckedTemporaries &CheckedTemps)
 
static bool CheckLValueConstantExpression (EvalInfo &Info, SourceLocation Loc, QualType Type, const LValue &LVal, Expr::ConstExprUsage Usage, CheckedTemporaries &CheckedTemps)
 Check that this reference or pointer core constant expression is a valid value for an address or reference constant expression. More...
 
static bool CheckMemberPointerConstantExpression (EvalInfo &Info, SourceLocation Loc, QualType Type, const APValue &Value, Expr::ConstExprUsage Usage)
 Member pointers are constant expressions unless they point to a non-virtual dllimport member function. More...
 
static bool CheckLiteralType (EvalInfo &Info, const Expr *E, const LValue *This=nullptr)
 Check that this core constant expression is of literal type, and if not, produce an appropriate diagnostic. More...
 
static bool CheckConstantExpression (EvalInfo &Info, SourceLocation DiagLoc, QualType Type, const APValue &Value, Expr::ConstExprUsage Usage=Expr::EvaluateForCodeGen)
 Check that this core constant expression value is a valid value for a constant expression. More...
 
static bool CheckFullyInitialized (EvalInfo &Info, SourceLocation DiagLoc, QualType Type, const APValue &Value)
 Check that this evaluated value is fully-initialized and can be loaded by an lvalue-to-rvalue conversion. More...
 
static bool CheckMemoryLeaks (EvalInfo &Info)
 Enforce C++2a [expr.const]/4.17, which disallows new-expressions unless "the allocated storage is deallocated within the evaluation". More...
 
static bool EvalPointerValueAsBool (const APValue &Value, bool &Result)
 
static bool HandleConversionToBool (const APValue &Val, bool &Result)
 
static bool EvaluateAsBooleanCondition (const Expr *E, bool &Result, EvalInfo &Info)
 
template<typename T >
static bool HandleOverflow (EvalInfo &Info, const Expr *E, const T &SrcValue, QualType DestType)
 
static bool HandleFloatToIntCast (EvalInfo &Info, const Expr *E, QualType SrcType, const APFloat &Value, QualType DestType, APSInt &Result)
 
static bool HandleFloatToFloatCast (EvalInfo &Info, const Expr *E, QualType SrcType, QualType DestType, APFloat &Result)
 
static APSInt HandleIntToIntCast (EvalInfo &Info, const Expr *E, QualType DestType, QualType SrcType, const APSInt &Value)
 
static bool HandleIntToFloatCast (EvalInfo &Info, const Expr *E, QualType SrcType, const APSInt &Value, QualType DestType, APFloat &Result)
 
static bool truncateBitfieldValue (EvalInfo &Info, const Expr *E, APValue &Value, const FieldDecl *FD)
 
static bool EvalAndBitcastToAPInt (EvalInfo &Info, const Expr *E, llvm::APInt &Res)
 
template<typename Operation >
static bool CheckedIntArithmetic (EvalInfo &Info, const Expr *E, const APSInt &LHS, const APSInt &RHS, unsigned BitWidth, Operation Op, APSInt &Result)
 Perform the given integer operation, which is known to need at most BitWidth bits, and check for overflow in the original type (if that type was not an unsigned type). More...
 
static bool handleIntIntBinOp (EvalInfo &Info, const Expr *E, const APSInt &LHS, BinaryOperatorKind Opcode, APSInt RHS, APSInt &Result)
 Perform the given binary integer operation. More...
 
static bool handleFloatFloatBinOp (EvalInfo &Info, const Expr *E, APFloat &LHS, BinaryOperatorKind Opcode, const APFloat &RHS)
 Perform the given binary floating-point operation, in-place, on LHS. More...
 
static bool CastToDerivedClass (EvalInfo &Info, const Expr *E, LValue &Result, const RecordDecl *TruncatedType, unsigned TruncatedElements)
 Cast an lvalue referring to a base subobject to a derived class, by truncating the lvalue's path to the given length. More...
 
static bool HandleLValueDirectBase (EvalInfo &Info, const Expr *E, LValue &Obj, const CXXRecordDecl *Derived, const CXXRecordDecl *Base, const ASTRecordLayout *RL=nullptr)
 
static bool HandleLValueBase (EvalInfo &Info, const Expr *E, LValue &Obj, const CXXRecordDecl *DerivedDecl, const CXXBaseSpecifier *Base)
 
static bool HandleLValueBasePath (EvalInfo &Info, const CastExpr *E, QualType Type, LValue &Result)
 
static bool CastToBaseClass (EvalInfo &Info, const Expr *E, LValue &Result, const CXXRecordDecl *DerivedRD, const CXXRecordDecl *BaseRD)
 Cast an lvalue referring to a derived class to a known base subobject. More...
 
static bool HandleLValueMember (EvalInfo &Info, const Expr *E, LValue &LVal, const FieldDecl *FD, const ASTRecordLayout *RL=nullptr)
 Update LVal to refer to the given field, which must be a member of the type currently described by LVal. More...
 
static bool HandleLValueIndirectMember (EvalInfo &Info, const Expr *E, LValue &LVal, const IndirectFieldDecl *IFD)
 Update LVal to refer to the given indirect field. More...
 
static bool HandleSizeof (EvalInfo &Info, SourceLocation Loc, QualType Type, CharUnits &Size)
 Get the size of the given type in char units. More...
 
static bool HandleLValueArrayAdjustment (EvalInfo &Info, const Expr *E, LValue &LVal, QualType EltTy, APSInt Adjustment)
 Update a pointer value to model pointer arithmetic. More...
 
static bool HandleLValueArrayAdjustment (EvalInfo &Info, const Expr *E, LValue &LVal, QualType EltTy, int64_t Adjustment)
 
static bool HandleLValueComplexElement (EvalInfo &Info, const Expr *E, LValue &LVal, QualType EltTy, bool Imag)
 Update an lvalue to refer to a component of a complex number. More...
 
static bool evaluateVarDeclInit (EvalInfo &Info, const Expr *E, const VarDecl *VD, CallStackFrame *Frame, APValue *&Result, const LValue *LVal)
 Try to evaluate the initializer for a variable declaration. More...
 
static bool IsConstNonVolatile (QualType T)
 
static unsigned getBaseIndex (const CXXRecordDecl *Derived, const CXXRecordDecl *Base)
 Get the base index of the given base class within an APValue representing the given derived class. More...
 
static APSInt extractStringLiteralCharacter (EvalInfo &Info, const Expr *Lit, uint64_t Index)
 Extract the value of a character from a string literal. More...
 
static void expandStringLiteral (EvalInfo &Info, const StringLiteral *S, APValue &Result, QualType AllocType=QualType())
 
static void expandArray (APValue &Array, unsigned Index)
 
static bool isReadByLvalueToRvalueConversion (QualType T)
 Determine whether a type would actually be read by an lvalue-to-rvalue conversion. More...
 
static bool diagnoseMutableFields (EvalInfo &Info, const Expr *E, AccessKinds AK, QualType T)
 Diagnose an attempt to read from any unreadable field within the specified type, which might be a class type. More...
 
static bool lifetimeStartedInEvaluation (EvalInfo &Info, APValue::LValueBase Base, bool MutableSubobject=false)
 
static QualType getSubobjectType (QualType ObjType, QualType SubobjType, bool IsMutable=false)
 
template<typename SubobjectHandler >
SubobjectHandler::result_type findSubobject (EvalInfo &Info, const Expr *E, const CompleteObject &Obj, const SubobjectDesignator &Sub, SubobjectHandler &handler)
 Find the designated sub-object of an rvalue. More...
 
static bool extractSubobject (EvalInfo &Info, const Expr *E, const CompleteObject &Obj, const SubobjectDesignator &Sub, APValue &Result, AccessKinds AK=AK_Read)
 Extract the designated sub-object of an rvalue. More...
 
static bool modifySubobject (EvalInfo &Info, const Expr *E, const CompleteObject &Obj, const SubobjectDesignator &Sub, APValue &NewVal)
 Update the designated sub-object of an rvalue to the given value. More...
 
static unsigned FindDesignatorMismatch (QualType ObjType, const SubobjectDesignator &A, const SubobjectDesignator &B, bool &WasArrayIndex)
 Find the position where two subobject designators diverge, or equivalently the length of the common initial subsequence. More...
 
static bool AreElementsOfSameArray (QualType ObjType, const SubobjectDesignator &A, const SubobjectDesignator &B)
 Determine whether the given subobject designators refer to elements of the same array object. More...
 
static CompleteObject findCompleteObject (EvalInfo &Info, const Expr *E, AccessKinds AK, const LValue &LVal, QualType LValType)
 Find the complete object to which an LValue refers. More...
 
static bool handleLValueToRValueConversion (EvalInfo &Info, const Expr *Conv, QualType Type, const LValue &LVal, APValue &RVal, bool WantObjectRepresentation=false)
 Perform an lvalue-to-rvalue conversion on the given glvalue. More...
 
static bool handleAssignment (EvalInfo &Info, const Expr *E, const LValue &LVal, QualType LValType, APValue &Val)
 Perform an assignment of Val to LVal. Takes ownership of Val. More...
 
static bool handleCompoundAssignment (EvalInfo &Info, const Expr *E, const LValue &LVal, QualType LValType, QualType PromotedLValType, BinaryOperatorKind Opcode, const APValue &RVal)
 Perform a compound assignment of LVal <op>= RVal. More...
 
static bool handleIncDec (EvalInfo &Info, const Expr *E, const LValue &LVal, QualType LValType, bool IsIncrement, APValue *Old)
 Perform an increment or decrement on LVal. More...
 
static bool EvaluateObjectArgument (EvalInfo &Info, const Expr *Object, LValue &This)
 Build an lvalue for the object argument of a member function call. More...
 
static const ValueDeclHandleMemberPointerAccess (EvalInfo &Info, QualType LVType, LValue &LV, const Expr *RHS, bool IncludeMember=true)
 HandleMemberPointerAccess - Evaluate a member access operation and build an lvalue referring to the result. More...
 
static const ValueDeclHandleMemberPointerAccess (EvalInfo &Info, const BinaryOperator *BO, LValue &LV, bool IncludeMember=true)
 
static bool HandleBaseToDerivedCast (EvalInfo &Info, const CastExpr *E, LValue &Result)
 HandleBaseToDerivedCast - Apply the given base-to-derived cast operation on the provided lvalue, which currently refers to the base object. More...
 
static APValue getDefaultInitValue (QualType T)
 Get the value to use for a default-initialized object of type T. More...
 
static bool EvaluateVarDecl (EvalInfo &Info, const VarDecl *VD)
 
static bool EvaluateDecl (EvalInfo &Info, const Decl *D)
 
static bool EvaluateCond (EvalInfo &Info, const VarDecl *CondDecl, const Expr *Cond, bool &Result)
 Evaluate a condition (either a variable declaration or an expression). More...
 
static EvalStmtResult EvaluateStmt (StmtResult &Result, EvalInfo &Info, const Stmt *S, const SwitchCase *SC=nullptr)
 
static EvalStmtResult EvaluateLoopBody (StmtResult &Result, EvalInfo &Info, const Stmt *Body, const SwitchCase *Case=nullptr)
 Evaluate the body of a loop, and translate the result as appropriate. More...
 
static EvalStmtResult EvaluateSwitch (StmtResult &Result, EvalInfo &Info, const SwitchStmt *SS)
 Evaluate a switch statement. More...
 
static bool CheckTrivialDefaultConstructor (EvalInfo &Info, SourceLocation Loc, const CXXConstructorDecl *CD, bool IsValueInitialization)
 CheckTrivialDefaultConstructor - Check whether a constructor is a trivial default constructor. More...
 
static bool CheckConstexprFunction (EvalInfo &Info, SourceLocation CallLoc, const FunctionDecl *Declaration, const FunctionDecl *Definition, const Stmt *Body)
 CheckConstexprFunction - Check that a function can be called in a constant expression. More...
 
static bool checkDynamicType (EvalInfo &Info, const Expr *E, const LValue &This, AccessKinds AK, bool Polymorphic)
 Check that we can access the notional vptr of an object / determine its dynamic type. More...
 
static bool checkNonVirtualMemberCallThisPointer (EvalInfo &Info, const Expr *E, const LValue &This, const CXXMethodDecl *NamedMember)
 Check that the pointee of the 'this' pointer in a member function call is either within its lifetime or in its period of construction or destruction. More...
 
static const CXXRecordDeclgetBaseClassType (SubobjectDesignator &Designator, unsigned PathLength)
 
static Optional< DynamicTypeComputeDynamicType (EvalInfo &Info, const Expr *E, LValue &This, AccessKinds AK)
 Determine the dynamic type of an object. More...
 
static const CXXMethodDeclHandleVirtualDispatch (EvalInfo &Info, const Expr *E, LValue &This, const CXXMethodDecl *Found, llvm::SmallVectorImpl< QualType > &CovariantAdjustmentPath)
 Perform virtual dispatch. More...
 
static bool HandleCovariantReturnAdjustment (EvalInfo &Info, const Expr *E, APValue &Result, ArrayRef< QualType > Path)
 Perform the adjustment from a value returned by a virtual function to a value of the statically expected type, which may be a pointer or reference to a base class of the returned type. More...
 
static bool isBaseClassPublic (const CXXRecordDecl *Derived, const CXXRecordDecl *Base)
 Determine whether Base, which is known to be a direct base class of Derived, is a public base class. More...
 
static bool HandleDynamicCast (EvalInfo &Info, const ExplicitCastExpr *E, LValue &Ptr)
 Apply the given dynamic cast operation on the provided lvalue. More...
 
static bool HandleUnionActiveMemberChange (EvalInfo &Info, const Expr *LHSExpr, const LValue &LHS)
 Handle a builtin simple-assignment or a call to a trivial assignment operator whose left-hand side might involve a union member access. More...
 
static bool hasFields (const CXXRecordDecl *RD)
 Determine if a class has any fields that might need to be copied by a trivial copy or move operation. More...
 
static bool EvaluateArgs (ArrayRef< const Expr *> Args, ArgVector &ArgValues, EvalInfo &Info, const FunctionDecl *Callee)
 EvaluateArgs - Evaluate the arguments to a function call. More...
 
static bool HandleFunctionCall (SourceLocation CallLoc, const FunctionDecl *Callee, const LValue *This, ArrayRef< const Expr *> Args, const Stmt *Body, EvalInfo &Info, APValue &Result, const LValue *ResultSlot)
 Evaluate a function call. More...
 
static bool HandleConstructorCall (const Expr *E, const LValue &This, APValue *ArgValues, const CXXConstructorDecl *Definition, EvalInfo &Info, APValue &Result)
 Evaluate a constructor call. More...
 
static bool HandleConstructorCall (const Expr *E, const LValue &This, ArrayRef< const Expr *> Args, const CXXConstructorDecl *Definition, EvalInfo &Info, APValue &Result)
 
static bool HandleDestructionImpl (EvalInfo &Info, SourceLocation CallLoc, const LValue &This, APValue &Value, QualType T)
 
static bool HandleOperatorNewCall (EvalInfo &Info, const CallExpr *E, LValue &Result)
 Perform a call to 'perator new' or to `__builtin_operator_new'. More...
 
static bool hasVirtualDestructor (QualType T)
 
static const FunctionDeclgetVirtualOperatorDelete (QualType T)
 
static Optional< DynAlloc * > CheckDeleteKind (EvalInfo &Info, const Expr *E, const LValue &Pointer, DynAlloc::Kind DeallocKind)
 Check that the given object is a suitable pointer to a heap allocation that still exists and is of the right kind for the purpose of a deletion. More...
 
bool HandleOperatorDeleteCall (EvalInfo &Info, const CallExpr *E)
 
static bool getBytesReturnedByAllocSizeCall (const ASTContext &Ctx, const CallExpr *Call, llvm::APInt &Result)
 Attempts to compute the number of bytes available at the pointer returned by a function with the alloc_size attribute. More...
 
static bool getBytesReturnedByAllocSizeCall (const ASTContext &Ctx, const LValue &LVal, llvm::APInt &Result)
 Convenience function. More...
 
static bool evaluateLValueAsAllocSize (EvalInfo &Info, APValue::LValueBase Base, LValue &Result)
 Attempts to evaluate the given LValueBase as the result of a call to a function with the alloc_size attribute. More...
 
static CharUnits GetAlignOfType (EvalInfo &Info, QualType T, UnaryExprOrTypeTrait ExprKind)
 
static CharUnits GetAlignOfExpr (EvalInfo &Info, const Expr *E, UnaryExprOrTypeTrait ExprKind)
 
static bool EvaluateArrayNewInitList (EvalInfo &Info, LValue &This, APValue &Result, const InitListExpr *ILE, QualType AllocType)
 
static bool HandleClassZeroInitialization (EvalInfo &Info, const Expr *E, const RecordDecl *RD, const LValue &This, APValue &Result)
 Perform zero-initialization on an object of non-union class type. More...
 
static bool EvaluateRecord (const Expr *E, const LValue &This, APValue &Result, EvalInfo &Info)
 
static bool EvaluateVector (const Expr *E, APValue &Result, EvalInfo &Info)
 
static bool EvaluateArray (const Expr *E, const LValue &This, APValue &Result, EvalInfo &Info)
 
static bool MaybeElementDependentArrayFiller (const Expr *FillerExpr)
 
static GCCTypeClass EvaluateBuiltinClassifyType (QualType T, const LangOptions &LangOpts)
 EvaluateBuiltinClassifyType - Evaluate __builtin_classify_type the same way as GCC. More...
 
static GCCTypeClass EvaluateBuiltinClassifyType (const CallExpr *E, const LangOptions &LangOpts)
 EvaluateBuiltinClassifyType - Evaluate __builtin_classify_type the same way as GCC. More...
 
static bool EvaluateBuiltinConstantPForLValue (const APValue &LV)
 EvaluateBuiltinConstantPForLValue - Determine the result of __builtin_constant_p when applied to the given pointer. More...
 
static bool EvaluateBuiltinConstantP (EvalInfo &Info, const Expr *Arg)
 EvaluateBuiltinConstantP - Evaluate __builtin_constant_p as similarly to GCC as we can manage. More...
 
static QualType getObjectType (APValue::LValueBase B)
 Retrieves the "underlying object type" of the given expression, as used by __builtin_object_size. More...
 
static const ExprignorePointerCastsAndParens (const Expr *E)
 A more selective version of E->IgnoreParenCasts for tryEvaluateBuiltinObjectSize. More...
 
static bool isDesignatorAtObjectEnd (const ASTContext &Ctx, const LValue &LVal)
 Checks to see if the given LValue's Designator is at the end of the LValue's record layout. More...
 
static bool refersToCompleteObject (const LValue &LVal)
 Tests to see if the LValue has a user-specified designator (that isn't necessarily valid). More...
 
static bool isUserWritingOffTheEnd (const ASTContext &Ctx, const LValue &LVal)
 Attempts to detect a user writing into a piece of memory that's impossible to figure out the size of by just using types. More...
 
static bool convertUnsignedAPIntToCharUnits (const llvm::APInt &Int, CharUnits &Result)
 Converts the given APInt to CharUnits, assuming the APInt is unsigned. More...
 
static bool determineEndOffset (EvalInfo &Info, SourceLocation ExprLoc, unsigned Type, const LValue &LVal, CharUnits &EndOffset)
 Helper for tryEvaluateBuiltinObjectSize – Given an LValue, this will determine how many bytes exist from the beginning of the object to either the end of the current subobject, or the end of the object itself, depending on what the LValue looks like + the value of Type. More...
 
static bool tryEvaluateBuiltinObjectSize (const Expr *E, unsigned Type, EvalInfo &Info, uint64_t &Size)
 Tries to evaluate the __builtin_object_size for E. More...
 
static bool isOnePastTheEndOfCompleteObject (const ASTContext &Ctx, const LValue &LV)
 Determine whether this is a pointer past the end of the complete object referred to by the lvalue. More...
 
static void addOrSubLValueAsInteger (APValue &LVal, const APSInt &Index, bool IsSub)
 
template<class SuccessCB , class AfterCB >
static bool EvaluateComparisonBinaryOperator (EvalInfo &Info, const BinaryOperator *E, SuccessCB &&Success, AfterCB &&DoAfter)
 
static bool TryEvaluateBuiltinNaN (const ASTContext &Context, QualType ResultTy, const Expr *Arg, bool SNaN, llvm::APFloat &Result)
 
static bool EvaluateVoid (const Expr *E, EvalInfo &Info)
 
static bool FastEvaluateAsRValue (const Expr *Exp, Expr::EvalResult &Result, const ASTContext &Ctx, bool &IsConst)
 
static bool hasUnacceptableSideEffect (Expr::EvalStatus &Result, Expr::SideEffectsKind SEK)
 
static bool EvaluateAsRValue (const Expr *E, Expr::EvalResult &Result, const ASTContext &Ctx, EvalInfo &Info)
 
static bool EvaluateAsInt (const Expr *E, Expr::EvalResult &ExprResult, const ASTContext &Ctx, Expr::SideEffectsKind AllowSideEffects, EvalInfo &Info)
 
static bool EvaluateAsFixedPoint (const Expr *E, Expr::EvalResult &ExprResult, const ASTContext &Ctx, Expr::SideEffectsKind AllowSideEffects, EvalInfo &Info)
 
static ICEDiag NoDiag ()
 
static ICEDiag Worst (ICEDiag A, ICEDiag B)
 
static ICEDiag CheckEvalInICE (const Expr *E, const ASTContext &Ctx)
 
static ICEDiag CheckICE (const Expr *E, const ASTContext &Ctx)
 
static bool EvaluateCPlusPlus11IntegralConstantExpr (const ASTContext &Ctx, const Expr *E, llvm::APSInt *Value, SourceLocation *Loc)
 Evaluate an expression as a C++11 integral constant expression. More...
 

Macro Definition Documentation

◆ ABSTRACT_STMT

#define ABSTRACT_STMT (   Node)

◆ ABSTRACT_TYPE

#define ABSTRACT_TYPE (   Class,
  Base 
)

◆ BUILTIN_TYPE

#define BUILTIN_TYPE (   ID,
  SINGLETON_ID 
)

◆ DEBUG_TYPE

#define DEBUG_TYPE   "exprconstant"

Definition at line 61 of file ExprConstant.cpp.

◆ DEPENDENT_TYPE [1/2]

#define DEPENDENT_TYPE (   Class,
  Base 
)
Value:
case Type::Class: \
llvm_unreachable( \
"dependent types aren't supported in the constant evaluator!");

◆ DEPENDENT_TYPE [2/2]

#define DEPENDENT_TYPE (   ID,
  BASE 
)    case Type::ID:

◆ EXPR

#define EXPR (   Node,
  Base 
)

◆ EXT_OPAQUE_TYPE

#define EXT_OPAQUE_TYPE (   ExtType,
  Id,
  Ext 
)    case BuiltinType::Id:

◆ FLOATING_TYPE

#define FLOATING_TYPE (   ID,
  SINGLETON_ID 
)    case BuiltinType::ID: return GCCTypeClass::RealFloat;

◆ IMAGE_TYPE

#define IMAGE_TYPE (   ImgType,
  Id,
  SingletonId,
  Access,
  Suffix 
)    case BuiltinType::Id:

◆ NON_CANONICAL_TYPE [1/2]

#define NON_CANONICAL_TYPE (   Class,
  Base 
)
Value:
case Type::Class: \
llvm_unreachable("non-canonical type should be impossible!");

◆ NON_CANONICAL_TYPE [2/2]

#define NON_CANONICAL_TYPE (   ID,
  BASE 
)    case Type::ID:

◆ NON_CANONICAL_UNLESS_DEPENDENT

#define NON_CANONICAL_UNLESS_DEPENDENT (   Class,
  Base 
)
Value:
case Type::Class: \
llvm_unreachable("either dependent or not canonical!");

◆ NON_CANONICAL_UNLESS_DEPENDENT_TYPE

#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE (   ID,
  BASE 
)    case Type::ID:

◆ PLACEHOLDER_TYPE

#define PLACEHOLDER_TYPE (   ID,
  SINGLETON_ID 
)    case BuiltinType::ID: break;

◆ SIGNED_TYPE

#define SIGNED_TYPE (   ID,
  SINGLETON_ID 
)    case BuiltinType::ID: return GCCTypeClass::Integer;

◆ STMT

#define STMT (   Node,
  Base 
)    case Expr::Node##Class:

◆ SVE_TYPE

#define SVE_TYPE (   Name,
  Id,
  SingletonId 
)    case BuiltinType::Id:

◆ TYPE [1/2]

#define TYPE (   Class,
  Base 
)
Value:
case Type::Class: \
return visit(cast<Class##Type>(Can.getTypePtr()), Offset);
unsigned Offset
Definition: Format.cpp:1809

◆ TYPE [2/2]

#define TYPE (   ID,
  BASE 
)

Typedef Documentation

◆ CheckedTemporaries

using CheckedTemporaries = llvm::SmallPtrSet<const MaterializeTemporaryExpr *, 8>

Materialized temporaries that we've already checked to determine if they're initializsed by a constant expression.

Definition at line 1988 of file ExprConstant.cpp.

Enumeration Type Documentation

◆ CheckEvaluationResultKind

Enumerator
ConstantExpression 
FullyInitialized 

Definition at line 1980 of file ExprConstant.cpp.

◆ ConstructionPhase

enum ConstructionPhase
strong

Definition at line 672 of file ExprConstant.cpp.

◆ EvalStmtResult

Definition at line 4268 of file ExprConstant.cpp.

◆ GCCTypeClass

enum GCCTypeClass
strong

Values returned by __builtin_classify_type, chosen to match the values produced by GCC's builtin.

Enumerator
None 
Void 
Integer 
Enum 
Bool 
Pointer 
PointerToDataMember 
RealFloat 
Complex 
PointerToMemberFunction 
ClassOrStruct 
Union 

Definition at line 9916 of file ExprConstant.cpp.

◆ ICEKind

enum ICEKind

Definition at line 13777 of file ExprConstant.cpp.

Function Documentation

◆ addOrSubLValueAsInteger()

static void addOrSubLValueAsInteger ( APValue LVal,
const APSInt Index,
bool  IsSub 
)
static

Definition at line 11248 of file ExprConstant.cpp.

◆ AreElementsOfSameArray()

static bool AreElementsOfSameArray ( QualType  ObjType,
const SubobjectDesignator &  A,
const SubobjectDesignator &  B 
)
static

Determine whether the given subobject designators refer to elements of the same array object.

Definition at line 3487 of file ExprConstant.cpp.

References FindDesignatorMismatch().

Referenced by EvaluateComparisonBinaryOperator().

◆ CastToBaseClass()

static bool CastToBaseClass ( EvalInfo &  Info,
const Expr E,
LValue &  Result,
const CXXRecordDecl DerivedRD,
const CXXRecordDecl BaseRD 
)
static

Cast an lvalue referring to a derived class to a known base subobject.

Definition at line 2706 of file ExprConstant.cpp.

Referenced by HandleCovariantReturnAdjustment().

◆ CastToDerivedClass()

static bool CastToDerivedClass ( EvalInfo &  Info,
const Expr E,
LValue &  Result,
const RecordDecl TruncatedType,
unsigned  TruncatedElements 
)
static

Cast an lvalue referring to a base subobject to a derived class, by truncating the lvalue's path to the given length.

Definition at line 2624 of file ExprConstant.cpp.

References clang::CSK_Derived, clang::ASTRecordLayout::getBaseClassOffset(), clang::ASTRecordLayout::getVBaseClassOffset(), and clang::Decl::isInvalidDecl().

Referenced by HandleBaseToDerivedCast(), HandleDynamicCast(), HandleLValueBase(), and HandleMemberPointerAccess().

◆ CheckConstantExpression()

static bool CheckConstantExpression ( EvalInfo &  Info,
SourceLocation  DiagLoc,
QualType  Type,
const APValue Value,
Expr::ConstExprUsage  Usage = Expr::EvaluateForCodeGen 
)
static

Check that this core constant expression value is a valid value for a constant expression.

If not, report an appropriate diagnostic. Does not check that the expression is of literal type.

Definition at line 2239 of file ExprConstant.cpp.

References CheckEvaluationResult(), and ConstantExpression.

Referenced by clang::Expr::EvaluateAsConstantExpr(), clang::Expr::EvaluateAsInitializer(), EvaluateAsRValue(), and EvaluateComparisonBinaryOperator().

◆ CheckConstexprFunction()

static bool CheckConstexprFunction ( EvalInfo &  Info,
SourceLocation  CallLoc,
const FunctionDecl Declaration,
const FunctionDecl Definition,
const Stmt Body 
)
static

CheckConstexprFunction - Check that a function can be called in a constant expression.

Definition at line 4884 of file ExprConstant.cpp.

References bool, clang::InheritedConstructor::getConstructor(), clang::CXXConstructorDecl::getInheritedConstructor(), clang::Decl::getLocation(), clang::FunctionDecl::isConstexpr(), and clang::Decl::isInvalidDecl().

Referenced by HandleDestructionImpl().

◆ CheckDeleteKind()

static Optional<DynAlloc *> CheckDeleteKind ( EvalInfo &  Info,
const Expr E,
const LValue &  Pointer,
DynAlloc::Kind  DeallocKind 
)
static

Check that the given object is a suitable pointer to a heap allocation that still exists and is of the right kind for the purpose of a deletion.

On success, returns the heap allocation to deallocate. On failure, produces a diagnostic and returns None.

Definition at line 6034 of file ExprConstant.cpp.

References clang::None, and NoteLValueLocation().

Referenced by EvaluateAtomic(), and HandleOperatorDeleteCall().

◆ checkDynamicType()

static bool checkDynamicType ( EvalInfo &  Info,
const Expr E,
const LValue &  This,
AccessKinds  AK,
bool  Polymorphic 
)
static

Check that we can access the notional vptr of an object / determine its dynamic type.

Definition at line 4959 of file ExprConstant.cpp.

References findCompleteObject(), findSubobject(), and clang::APValue::getAsString().

Referenced by checkNonVirtualMemberCallThisPointer(), and ComputeDynamicType().

◆ CheckedIntArithmetic()

template<typename Operation >
static bool CheckedIntArithmetic ( EvalInfo &  Info,
const Expr E,
const APSInt LHS,
const APSInt RHS,
unsigned  BitWidth,
Operation  Op,
APSInt Result 
)
static

Perform the given integer operation, which is known to need at most BitWidth bits, and check for overflow in the original type (if that type was not an unsigned type).

Definition at line 2461 of file ExprConstant.cpp.

References clang::Expr::getExprLoc(), clang::Expr::getType(), and HandleOverflow().

Referenced by handleIntIntBinOp().

◆ CheckEvalInICE()

static ICEDiag CheckEvalInICE ( const Expr E,
const ASTContext Ctx 
)
static

Definition at line 13801 of file ExprConstant.cpp.

Referenced by CheckICE().

◆ CheckEvaluationResult()

static bool CheckEvaluationResult ( CheckEvaluationResultKind  CERK,
EvalInfo &  Info,
SourceLocation  DiagLoc,
QualType  Type,
const APValue Value,
Expr::ConstExprUsage  Usage,
SourceLocation  SubobjectLoc,
CheckedTemporaries CheckedTemps 
)
static

◆ CheckFullyInitialized()

static bool CheckFullyInitialized ( EvalInfo &  Info,
SourceLocation  DiagLoc,
QualType  Type,
const APValue Value 
)
static

Check that this evaluated value is fully-initialized and can be loaded by an lvalue-to-rvalue conversion.

Definition at line 2250 of file ExprConstant.cpp.

References CheckEvaluationResult(), clang::Expr::EvaluateForCodeGen, and FullyInitialized.

◆ CheckICE()

static ICEDiag CheckICE ( const Expr E,
const ASTContext Ctx 
)
static

◆ CheckLiteralType()

static bool CheckLiteralType ( EvalInfo &  Info,
const Expr E,
const LValue *  This = nullptr 
)
static

Check that this core constant expression is of literal type, and if not, produce an appropriate diagnostic.

Definition at line 2124 of file ExprConstant.cpp.

References clang::Expr::getType(), clang::Type::isLiteralType(), and clang::Expr::isRValue().

Referenced by EvaluateAsRValue(), EvaluateComparisonBinaryOperator(), and EvaluateInPlace().

◆ CheckLValueConstantExpression()

static bool CheckLValueConstantExpression ( EvalInfo &  Info,
SourceLocation  Loc,
QualType  Type,
const LValue &  LVal,
Expr::ConstExprUsage  Usage,
CheckedTemporaries CheckedTemps 
)
static

Check that this reference or pointer core constant expression is a valid value for an address or reference constant expression.

Return true if we can fold this expression, whether or not it's a constant expression.

Definition at line 2000 of file ExprConstant.cpp.

References CheckEvaluationResult(), ConstantExpression, clang::APValue::LValueBase::dyn_cast(), clang::Expr::EvaluateForCodeGen, clang::APValue::LValueBase::is(), clang::QualType::isDestructedType(), IsGlobalLValue(), clang::Type::isReferenceType(), NoteLValueLocation(), and V.

Referenced by CheckEvaluationResult(), and clang::Expr::EvaluateAsLValue().

◆ CheckMemberPointerConstantExpression()

static bool CheckMemberPointerConstantExpression ( EvalInfo &  Info,
SourceLocation  Loc,
QualType  Type,
const APValue Value,
Expr::ConstExprUsage  Usage 
)
static

Member pointers are constant expressions unless they point to a non-virtual dllimport member function.

Definition at line 2109 of file ExprConstant.cpp.

References clang::Expr::EvaluateForMangling, and clang::APValue::getMemberPointerDecl().

Referenced by CheckEvaluationResult().

◆ CheckMemoryLeaks()

static bool CheckMemoryLeaks ( EvalInfo &  Info)
static

Enforce C++2a [expr.const]/4.17, which disallows new-expressions unless "the allocated storage is deallocated within the evaluation".

Definition at line 2260 of file ExprConstant.cpp.

Referenced by clang::Expr::EvaluateAsConstantExpr(), clang::Expr::EvaluateAsInitializer(), and EvaluateAsRValue().

◆ checkNonVirtualMemberCallThisPointer()

static bool checkNonVirtualMemberCallThisPointer ( EvalInfo &  Info,
const Expr E,
const LValue &  This,
const CXXMethodDecl NamedMember 
)
static

Check that the pointee of the 'this' pointer in a member function call is either within its lifetime or in its period of construction or destruction.

Definition at line 5001 of file ExprConstant.cpp.

References clang::AK_Destroy, clang::AK_MemberCall, and checkDynamicType().

◆ CheckTrivialDefaultConstructor()

static bool CheckTrivialDefaultConstructor ( EvalInfo &  Info,
SourceLocation  Loc,
const CXXConstructorDecl CD,
bool  IsValueInitialization 
)
static

CheckTrivialDefaultConstructor - Check whether a constructor is a trivial default constructor.

If so, we'll fold it whether or not it's marked as constexpr. If it is marked as constexpr, we will never implicitly define it, so we need special handling.

Definition at line 4859 of file ExprConstant.cpp.

References clang::Decl::getLocation(), clang::FunctionDecl::isConstexpr(), clang::CXXConstructorDecl::isDefaultConstructor(), and clang::FunctionDecl::isTrivial().

◆ ComputeDynamicType()

static Optional<DynamicType> ComputeDynamicType ( EvalInfo &  Info,
const Expr E,
LValue &  This,
AccessKinds  AK 
)
static

Determine the dynamic type of an object.

Definition at line 5026 of file ExprConstant.cpp.

References checkDynamicType(), getBaseClassType(), clang::CXXRecordDecl::getNumVBases(), and clang::None.

Referenced by HandleDynamicCast(), and HandleVirtualDispatch().

◆ convertUnsignedAPIntToCharUnits()

static bool convertUnsignedAPIntToCharUnits ( const llvm::APInt &  Int,
CharUnits Result 
)
static

Converts the given APInt to CharUnits, assuming the APInt is unsigned.

Fails if the conversion would cause loss of precision.

Definition at line 10340 of file ExprConstant.cpp.

References clang::CharUnits::fromQuantity(), and max().

Referenced by determineEndOffset().

◆ determineEndOffset()

static bool determineEndOffset ( EvalInfo &  Info,
SourceLocation  ExprLoc,
unsigned  Type,
const LValue &  LVal,
CharUnits EndOffset 
)
static

Helper for tryEvaluateBuiltinObjectSize – Given an LValue, this will determine how many bytes exist from the beginning of the object to either the end of the current subobject, or the end of the object itself, depending on what the LValue looks like + the value of Type.

If this returns false, the value of Result is undefined.

Definition at line 10355 of file ExprConstant.cpp.

References convertUnsignedAPIntToCharUnits(), getBytesReturnedByAllocSizeCall(), getObjectType(), HandleSizeof(), clang::Type::isFunctionType(), clang::Type::isIncompleteType(), clang::QualType::isNull(), isUserWritingOffTheEnd(), refersToCompleteObject(), and clang::Result.

Referenced by tryEvaluateBuiltinObjectSize().

◆ diagnoseMutableFields()

static bool diagnoseMutableFields ( EvalInfo &  Info,
const Expr E,
AccessKinds  AK,
QualType  T 
)
static

◆ EvalAndBitcastToAPInt()

static bool EvalAndBitcastToAPInt ( EvalInfo &  Info,
const Expr E,
llvm::APInt &  Res 
)
static

◆ EvalPointerValueAsBool()

static bool EvalPointerValueAsBool ( const APValue Value,
bool Result 
)
static

◆ Evaluate()

static bool Evaluate ( APValue Result,
EvalInfo &  Info,
const Expr E 
)
static

◆ EvaluateArgs()

static bool EvaluateArgs ( ArrayRef< const Expr *>  Args,
ArgVector &  ArgValues,
EvalInfo &  Info,
const FunctionDecl Callee 
)
static

EvaluateArgs - Evaluate the arguments to a function call.

Definition at line 5425 of file ExprConstant.cpp.

References Evaluate(), clang::Decl::hasAttr(), and clang::Decl::specific_attrs().

Referenced by HandleConstructorCall(), and HandleFunctionCall().

◆ EvaluateArray()

static bool EvaluateArray ( const Expr E,
const LValue &  This,
APValue Result,
EvalInfo &  Info 
)
static

◆ EvaluateArrayNewInitList()

static bool EvaluateArrayNewInitList ( EvalInfo &  Info,
LValue &  This,
APValue Result,
const InitListExpr ILE,
QualType  AllocType 
)
static

◆ EvaluateAsBooleanCondition()

static bool EvaluateAsBooleanCondition ( const Expr E,
bool Result,
EvalInfo &  Info 
)
static

◆ EvaluateAsFixedPoint()

static bool EvaluateAsFixedPoint ( const Expr E,
Expr::EvalResult ExprResult,
const ASTContext Ctx,
Expr::SideEffectsKind  AllowSideEffects,
EvalInfo &  Info 
)
static

◆ EvaluateAsInt()

static bool EvaluateAsInt ( const Expr E,
Expr::EvalResult ExprResult,
const ASTContext Ctx,
Expr::SideEffectsKind  AllowSideEffects,
EvalInfo &  Info 
)
static

◆ EvaluateAsRValue() [1/2]

static bool EvaluateAsRValue ( EvalInfo &  Info,
const Expr E,
APValue Result 
)
static

◆ EvaluateAsRValue() [2/2]

static bool EvaluateAsRValue ( const Expr E,
Expr::EvalResult Result,
const ASTContext Ctx,
EvalInfo &  Info 
)
static

◆ EvaluateAtomic()

static bool EvaluateAtomic ( const Expr E,
const LValue *  This,
APValue Result,
EvalInfo &  Info 
)
static

◆ EvaluateBuiltinClassifyType() [1/2]

static GCCTypeClass EvaluateBuiltinClassifyType ( QualType  T,
const LangOptions LangOpts 
)
static

◆ EvaluateBuiltinClassifyType() [2/2]

static GCCTypeClass EvaluateBuiltinClassifyType ( const CallExpr E,
const LangOptions LangOpts 
)
static

EvaluateBuiltinClassifyType - Evaluate __builtin_classify_type the same way as GCC.

Definition at line 10082 of file ExprConstant.cpp.

References EvaluateBuiltinClassifyType(), clang::CallExpr::getArg(), clang::CallExpr::getNumArgs(), clang::Expr::getType(), and None.

◆ EvaluateBuiltinConstantP()

static bool EvaluateBuiltinConstantP ( EvalInfo &  Info,
const Expr Arg 
)
static

◆ EvaluateBuiltinConstantPForLValue()

static bool EvaluateBuiltinConstantPForLValue ( const APValue LV)
static

EvaluateBuiltinConstantPForLValue - Determine the result of __builtin_constant_p when applied to the given pointer.

A pointer is only "constant" if it is null (or a pointer cast to integer) or it points to the first character of a string literal.

Definition at line 10099 of file ExprConstant.cpp.

References clang::APValue::LValueBase::dyn_cast(), clang::APValue::getLValueBase(), clang::APValue::getLValueOffset(), clang::APValue::LValueBase::is(), clang::APValue::LValueBase::isNull(), and clang::CharUnits::isZero().

Referenced by EvaluateBuiltinConstantP().

◆ EvaluateComparisonBinaryOperator()

template<class SuccessCB , class AfterCB >
static bool EvaluateComparisonBinaryOperator ( EvalInfo &  Info,
const BinaryOperator E,
SuccessCB &&  Success,
AfterCB &&  DoAfter 
)
static

Definition at line 11424 of file ExprConstant.cpp.

References clang::APFixedPoint::add(), AreElementsOfSameArray(), clang::OffsetOfNode::Array, clang::OffsetOfNode::Base, clang::C, clang::UnaryOperator::canOverflow(), clang::Type::castAs(), CheckConstantExpression(), CheckLiteralType(), clang::APFixedPoint::convert(), clang::Equal, clang::Error, Evaluate(), EvaluateAsBooleanCondition(), EvaluateComplex(), EvaluateFixedPoint(), EvaluateFixedPointOrInteger(), EvaluateFloat(), EvaluateInteger(), EvaluateLValue(), EvaluateMemberPointer(), EvaluatePointer(), clang::OffsetOfNode::Field, FindDesignatorMismatch(), clang::Decl::getAccess(), GetAlignOfExpr(), GetAlignOfType(), clang::UnaryExprOrTypeTraitExpr::getArgumentExpr(), clang::UnaryExprOrTypeTraitExpr::getArgumentType(), clang::OffsetOfNode::getArrayExprIndex(), clang::Type::getAs(), clang::OffsetOfNode::getBase(), clang::ASTRecordLayout::getBaseClassOffset(), clang::APFixedPoint::getBoolValue(), clang::CastExpr::getCastKind(), clang::OffsetOfExpr::getComponent(), clang::RecordType::getDecl(), clang::Decl::getDeclContext(), clang::ArrayType::getElementType(), clang::Expr::getExprLoc(), clang::BinaryOperator::getExprLoc(), clang::OffsetOfNode::getField(), clang::ASTRecordLayout::getFieldCount(), clang::FieldDecl::getFieldIndex(), clang::ASTRecordLayout::getFieldOffset(), clang::APValue::getFixedPoint(), clang::APValue::getFloat(), clang::APFixedPoint::getFromIntValue(), clang::OffsetOfExpr::getIndexExpr(), clang::OffsetOfNode::getKind(), clang::UnaryExprOrTypeTraitExpr::getKind(), clang::AddrLabelExpr::getLabel(), clang::BinaryOperator::getLHS(), clang::QualType::getNonReferenceType(), clang::OffsetOfExpr::getNumComponents(), clang::UnaryOperator::getOpcode(), clang::BinaryOperator::getOpcode(), clang::SizeOfPackExpr::getPackLength(), clang::FieldDecl::getParent(), clang::Type::getPointeeType(), clang::CharUnits::getQuantity(), clang::BinaryOperator::getRHS(), clang::UnaryOperator::getSubExpr(), clang::CastExpr::getSubExpr(), clang::TypeSourceInfo::getType(), clang::Expr::getType(), clang::CXXBaseSpecifier::getType(), clang::ValueDecl::getType(), clang::UnaryExprOrTypeTraitExpr::getTypeOfArgument(), clang::OffsetOfExpr::getTypeSourceInfo(), clang::CXXNoexceptExpr::getValue(), clang::ComparisonCategoryInfo::getValueInfo(), clang::Greater, HandleFloatToIntCast(), HandleIntToIntCast(), handleLValueToRValueConversion(), HandleOverflow(), HandleSizeof(), HasSameBase(), clang::OffsetOfNode::Identifier, clang::Type::isAnyComplexType(), clang::UnaryExprOrTypeTraitExpr::isArgumentType(), clang::BinaryOperator::isAssignmentOp(), clang::BinaryOperator::isComparisonOp(), clang::Type::isComplexIntegerType(), clang::ComparisonCategoryInfo::isEquality(), clang::BinaryOperator::isEqualityOp(), clang::Type::isFixedPointType(), clang::Type::isIncompleteType(), clang::Type::isIntegralOrEnumerationType(), clang::Decl::isInvalidDecl(), IsLiteralLValue(), clang::Type::isMemberPointerType(), clang::Type::isNullPtrType(), isOnePastTheEndOfCompleteObject(), clang::ComparisonCategoryInfo::isOrdered(), clang::Type::isPointerType(), clang::Type::isRealFloatingType(), clang::BinaryOperator::isRelationalOp(), clang::ConceptSpecializationExpr::isSatisfied(), clang::Type::isSignedIntegerOrEnumerationType(), clang::TagDecl::isUnion(), clang::Type::isVectorType(), clang::CXXBaseSpecifier::isVirtual(), clang::Type::isVoidPointerType(), IsWeakLValue(), clang::CharUnits::isZero(), isZeroSized(), clang::Less, clang::ComparisonCategoryInfo::makeWeakResult(), clang::Nonequal, clang::Result, clang::APValue::toIntegralConstant(), clang::UETT_AlignOf, clang::UETT_OpenMPRequiredSimdAlign, clang::UETT_PreferredAlignOf, clang::UETT_SizeOf, clang::UETT_VecStep, clang::Unordered, and V.

◆ EvaluateComplex()

static bool EvaluateComplex ( const Expr E,
ComplexValue &  Res,
EvalInfo &  Info 
)
static

◆ EvaluateCond()

static bool EvaluateCond ( EvalInfo &  Info,
const VarDecl CondDecl,
const Expr Cond,
bool Result 
)
static

Evaluate a condition (either a variable declaration or an expression).

Definition at line 4328 of file ExprConstant.cpp.

References EvaluateAsBooleanCondition(), EvaluateDecl(), and EvaluateStmt().

◆ EvaluateCPlusPlus11IntegralConstantExpr()

static bool EvaluateCPlusPlus11IntegralConstantExpr ( const ASTContext Ctx,
const Expr E,
llvm::APSInt Value,
SourceLocation Loc 
)
static

◆ EvaluateDecl()

static bool EvaluateDecl ( EvalInfo &  Info,
const Decl D 
)
static

Definition at line 4312 of file ExprConstant.cpp.

References EvaluateVarDecl().

Referenced by EvaluateCond(), and EvaluateSwitch().

◆ EvaluateFixedPoint()

static bool EvaluateFixedPoint ( const Expr E,
APFixedPoint Result,
EvalInfo &  Info 
)
static

Evaluate only a fixed point expression into an APResult.

Definition at line 9857 of file ExprConstant.cpp.

References clang::APValue::getFixedPoint(), clang::Expr::getType(), clang::APValue::isFixedPoint(), and clang::Type::isFixedPointType().

Referenced by EvaluateComparisonBinaryOperator(), and EvaluateFixedPointOrInteger().

◆ EvaluateFixedPointOrInteger()

static bool EvaluateFixedPointOrInteger ( const Expr E,
APFixedPoint Result,
EvalInfo &  Info 
)
static

◆ EvaluateFloat()

static bool EvaluateFloat ( const Expr E,
APFloat &  Result,
EvalInfo &  Info 
)
static

◆ EvaluateIgnoredValue()

static bool EvaluateIgnoredValue ( EvalInfo &  Info,
const Expr E 
)
static

Evaluate an expression to see if it had side-effects, and discard its result.

Returns
true if the caller should keep evaluating.

Definition at line 1841 of file ExprConstant.cpp.

References Evaluate().

Referenced by evaluateLValueAsAllocSize(), HandleOperatorDeleteCall(), and HandleOperatorNewCall().

◆ EvaluateInPlace()

static bool EvaluateInPlace ( APValue Result,
EvalInfo &  Info,
const LValue &  This,
const Expr E,
bool  AllowNonLiteralTypes 
)
static

EvaluateInPlace - Evaluate an expression in-place in an APValue.

In some cases, the in-place evaluation is essential, since later initializers for an object can indirectly refer to subobjects which were initialized earlier.

Definition at line 13348 of file ExprConstant.cpp.

References CheckLiteralType(), Evaluate(), EvaluateArray(), EvaluateAtomic(), EvaluateRecord(), clang::QualType::getAtomicUnqualifiedType(), clang::Expr::getType(), clang::Type::isArrayType(), clang::Type::isAtomicType(), clang::Type::isRecordType(), clang::Expr::isRValue(), and clang::Expr::isValueDependent().

Referenced by clang::Expr::EvaluateAsInitializer(), EvaluateComplex(), EvaluatePointer(), EvaluateRecord(), EvaluateVarDecl(), EvaluateVector(), GetAlignOfExpr(), and HandleConstructorCall().

◆ EvaluateInteger()

static bool EvaluateInteger ( const Expr E,
APSInt Result,
EvalInfo &  Info 
)
static

◆ EvaluateIntegerOrLValue()

static bool EvaluateIntegerOrLValue ( const Expr E,
APValue Result,
EvalInfo &  Info 
)
static

EvaluateIntegerOrLValue - Evaluate an rvalue integral-typed expression, and produce either the integer value or a pointer.

GCC has a heinous extension which folds casts between pointer types and pointer-sized integral types. We support this by allowing the evaluation of an integer rvalue to produce a pointer (represented as an lvalue) instead. Some simple arithmetic on such values is supported (they are treated much like char*).

Definition at line 9831 of file ExprConstant.cpp.

References clang::Expr::getType(), clang::Type::isIntegralOrEnumerationType(), and clang::Expr::isRValue().

Referenced by EvaluateInteger(), and EvaluatePointer().

◆ EvaluateLoopBody()

static EvalStmtResult EvaluateLoopBody ( StmtResult &  Result,
EvalInfo &  Info,
const Stmt Body,
const SwitchCase Case = nullptr 
)
static

Evaluate the body of a loop, and translate the result as appropriate.

Definition at line 4367 of file ExprConstant.cpp.

References EvaluateStmt().

◆ EvaluateLValue()

static bool EvaluateLValue ( const Expr E,
LValue &  Result,
EvalInfo &  Info,
bool  InvalidBaseOK 
)
static

◆ evaluateLValueAsAllocSize()

static bool evaluateLValueAsAllocSize ( EvalInfo &  Info,
APValue::LValueBase  Base,
LValue &  Result 
)
static

◆ EvaluateMemberPointer()

static bool EvaluateMemberPointer ( const Expr E,
MemberPtr &  Result,
EvalInfo &  Info 
)
static

◆ EvaluateObjectArgument()

static bool EvaluateObjectArgument ( EvalInfo &  Info,
const Expr Object,
LValue &  This 
)
static

◆ EvaluatePointer()

static bool EvaluatePointer ( const Expr E,
LValue &  Result,
EvalInfo &  Info,
bool  InvalidBaseOK = false 
)
static

◆ EvaluateRecord()

static bool EvaluateRecord ( const Expr E,
const LValue &  This,
APValue Result,
EvalInfo &  Info 
)
static

◆ EvaluateStmt()

static EvalStmtResult EvaluateStmt ( StmtResult &  Result,
EvalInfo &  Info,
const Stmt S,
const SwitchCase SC = nullptr 
)
static

◆ EvaluateSwitch()

static EvalStmtResult EvaluateSwitch ( StmtResult &  Result,
EvalInfo &  Info,
const SwitchStmt SS 
)
static

◆ EvaluateTemporary()

static bool EvaluateTemporary ( const Expr E,
LValue &  Result,
EvalInfo &  Info 
)
static

◆ EvaluateVarDecl()

static bool EvaluateVarDecl ( EvalInfo &  Info,
const VarDecl VD 
)
static

◆ evaluateVarDeclInit()

static bool evaluateVarDeclInit ( EvalInfo &  Info,
const Expr E,
const VarDecl VD,
CallStackFrame *  Frame,
APValue *&  Result,
const LValue *  LVal 
)
static

Try to evaluate the initializer for a variable declaration.

Parameters
InfoInformation about the ongoing evaluation.
EAn expression to be used when printing diagnostics.
VDThe variable whose initializer should be obtained.
FrameThe frame in which the variable was created. Must be null if this variable is not local to the evaluation.
ResultFilled in with a pointer to the value of the variable.

Definition at line 2822 of file ExprConstant.cpp.

References clang::VarDecl::checkInitIsICE(), clang::VarDecl::evaluateValue(), clang::VarDecl::getAnyInitializer(), clang::Stmt::getBeginLoc(), clang::Decl::getDeclContext(), clang::VarDecl::getEvaluatedValue(), clang::Decl::getLocation(), clang::VarDecl::isInitCapture(), clang::isLambdaCallOperator(), clang::Expr::isValueDependent(), and clang::ValueDecl::isWeak().

Referenced by EvaluateLValue(), and findCompleteObject().

◆ EvaluateVector()

static bool EvaluateVector ( const Expr E,
APValue Result,
EvalInfo &  Info 
)
static

◆ EvaluateVoid()

static bool EvaluateVoid ( const Expr E,
EvalInfo &  Info 
)
static

Definition at line 13257 of file ExprConstant.cpp.

References clang::Expr::getType(), clang::Expr::isRValue(), and clang::Type::isVoidType().

Referenced by Evaluate().

◆ expandArray()

static void expandArray ( APValue Array,
unsigned  Index 
)
static

Definition at line 2985 of file ExprConstant.cpp.

Referenced by HandleDestructionImpl().

◆ expandStringLiteral()

static void expandStringLiteral ( EvalInfo &  Info,
const StringLiteral S,
APValue Result,
QualType  AllocType = QualType() 
)
static

Definition at line 2962 of file ExprConstant.cpp.

Referenced by EvaluateVector().

◆ extractStringLiteralCharacter()

static APSInt extractStringLiteralCharacter ( EvalInfo &  Info,
const Expr Lit,
uint64_t  Index 
)
static

Extract the value of a character from a string literal.

Definition at line 2929 of file ExprConstant.cpp.

Referenced by handleLValueToRValueConversion().

◆ extractSubobject()

static bool extractSubobject ( EvalInfo &  Info,
const Expr E,
const CompleteObject &  Obj,
const SubobjectDesignator &  Sub,
APValue Result,
AccessKinds  AK = AK_Read 
)
static

◆ FastEvaluateAsRValue()

static bool FastEvaluateAsRValue ( const Expr Exp,
Expr::EvalResult Result,
const ASTContext Ctx,
bool IsConst 
)
static

◆ findCompleteObject()

static CompleteObject findCompleteObject ( EvalInfo &  Info,
const Expr E,
AccessKinds  AK,
const LValue &  LVal,
QualType  LValType 
)
static

◆ FindDesignatorMismatch()

static unsigned FindDesignatorMismatch ( QualType  ObjType,
const SubobjectDesignator &  A,
const SubobjectDesignator &  B,
bool WasArrayIndex 
)
static

Find the position where two subobject designators diverge, or equivalently the length of the common initial subsequence.

Definition at line 3450 of file ExprConstant.cpp.

References clang::Type::castAs(), clang::Type::castAsArrayTypeUnsafe(), clang::ComplexType::getElementType(), clang::ArrayType::getElementType(), clang::Type::isAnyComplexType(), clang::Type::isArrayType(), clang::QualType::isNull(), and min().

Referenced by AreElementsOfSameArray(), and EvaluateComparisonBinaryOperator().

◆ findSubobject()

template<typename SubobjectHandler >
SubobjectHandler::result_type findSubobject ( EvalInfo &  Info,
const Expr E,
const CompleteObject &  Obj,
const SubobjectDesignator &  Sub,
SubobjectHandler &  handler 
)

◆ GetAlignOfExpr()

static CharUnits GetAlignOfExpr ( EvalInfo &  Info,
const Expr E,
UnaryExprOrTypeTrait  ExprKind 
)
static

Definition at line 8084 of file ExprConstant.cpp.

References clang::AK_Construct, clang::AK_Read, clang::Type::castAs(), clang::Error, EvaluateArrayNewInitList(), EvaluateInPlace(), EvaluateInteger(), EvaluateLValue(), EvaluatePointer(), findCompleteObject(), findSubobject(), clang::CharUnits::fromQuantity(), GetAlignOfType(), clang::CXXNewExpr::getAllocatedType(), clang::CallExpr::getArg(), clang::CXXNewExpr::getArraySize(), clang::Type::getAsArrayTypeUnsafe(), clang::APValue::getAsString(), clang::CallExpr::getBuiltinCallee(), getDefaultInitValue(), clang::CXXNewExpr::getInitializer(), clang::APValue::getInt(), clang::ConstantArrayType::getMaxSizeBits(), clang::ConstantArrayType::getNumAddressingBits(), clang::CallExpr::getNumArgs(), clang::CXXNewExpr::getNumPlacementArgs(), clang::CXXNewExpr::getOperatorNew(), clang::CXXNewExpr::getPlacementArg(), clang::Type::getPointeeType(), clang::CharUnits::getQuantity(), clang::Expr::getType(), handleAssignment(), HandleIntToIntCast(), HandleLValueArrayAdjustment(), handleLValueToRValueConversion(), HandleOperatorNewCall(), HasSameBase(), clang::Expr::IgnoreParens(), clang::CXXNewExpr::isArray(), clang::Type::isArrayType(), clang::Type::isIncompleteType(), clang::APValue::isInt(), clang::Type::isNothrowT(), clang::FunctionDecl::isReplaceableGlobalAllocationFunction(), clang::FunctionDecl::isReservedGlobalPlacementOperator(), IsStringLiteralCall(), clang::QualType::isTriviallyCopyableType(), max(), clang::diff::Move, clang::ArrayType::Normal, Offset, clang::CharUnits::One(), clang::Result, clang::UETT_AlignOf, and V.

Referenced by EvaluateComparisonBinaryOperator().

◆ GetAlignOfType()

static CharUnits GetAlignOfType ( EvalInfo &  Info,
QualType  T,
UnaryExprOrTypeTrait  ExprKind 
)
static

◆ getBaseClassType()

static const CXXRecordDecl* getBaseClassType ( SubobjectDesignator &  Designator,
unsigned  PathLength 
)
static

Definition at line 5016 of file ExprConstant.cpp.

Referenced by ComputeDynamicType(), and HandleVirtualDispatch().

◆ getBaseIndex()

static unsigned getBaseIndex ( const CXXRecordDecl Derived,
const CXXRecordDecl Base 
)
static

Get the base index of the given base class within an APValue representing the given derived class.

Definition at line 2915 of file ExprConstant.cpp.

References clang::CXXRecordDecl::getCanonicalDecl().

◆ getBytesReturnedByAllocSizeCall() [1/2]

static bool getBytesReturnedByAllocSizeCall ( const ASTContext Ctx,
const CallExpr Call,
llvm::APInt &  Result 
)
static

Attempts to compute the number of bytes available at the pointer returned by a function with the alloc_size attribute.

Returns true if we were successful. Places an unsigned number into Result.

This expects the given CallExpr to be a call to a function with an alloc_size attribute.

Definition at line 7693 of file ExprConstant.cpp.

References clang::Expr::EvaluateAsInt(), clang::CallExpr::getArg(), clang::APValue::getInt(), clang::CallExpr::getNumArgs(), clang::ASTContext::getSizeType(), clang::ASTContext::getTypeSize(), clang::Expr::SE_AllowSideEffects, and clang::Expr::EvalResult::Val.

Referenced by determineEndOffset(), and getBytesReturnedByAllocSizeCall().

◆ getBytesReturnedByAllocSizeCall() [2/2]

static bool getBytesReturnedByAllocSizeCall ( const ASTContext Ctx,
const LValue &  LVal,
llvm::APInt &  Result 
)
static

Convenience function.

LVal's base must be a call to an alloc_size function.

Definition at line 7740 of file ExprConstant.cpp.

References getBytesReturnedByAllocSizeCall().

◆ getDefaultInitValue()

static APValue getDefaultInitValue ( QualType  T)
static

Get the value to use for a default-initialized object of type T.

Definition at line 4234 of file ExprConstant.cpp.

References distance(), and clang::Type::getAsCXXRecordDecl().

Referenced by EvaluateVarDecl(), GetAlignOfExpr(), and HandleConstructorCall().

◆ GetLValueBaseDecl()

static const ValueDecl* GetLValueBaseDecl ( const LValue &  LVal)
static

Definition at line 1916 of file ExprConstant.cpp.

Referenced by HasSameBase(), IsWeakLValue(), and isZeroSized().

◆ getObjectType()

static QualType getObjectType ( APValue::LValueBase  B)
static

◆ getSubobjectType()

static QualType getSubobjectType ( QualType  ObjType,
QualType  SubobjType,
bool  IsMutable = false 
)
static

◆ getVirtualOperatorDelete()

static const FunctionDecl* getVirtualOperatorDelete ( QualType  T)
static

Definition at line 6022 of file ExprConstant.cpp.

References clang::Type::getAsCXXRecordDecl().

Referenced by EvaluateAtomic().

◆ handleAssignment()

static bool handleAssignment ( EvalInfo &  Info,
const Expr E,
const LValue &  LVal,
QualType  LValType,
APValue Val 
)
static

◆ HandleBaseToDerivedCast()

static bool HandleBaseToDerivedCast ( EvalInfo &  Info,
const CastExpr E,
LValue &  Result 
)
static

HandleBaseToDerivedCast - Apply the given base-to-derived cast operation on the provided lvalue, which currently refers to the base object.

Definition at line 4197 of file ExprConstant.cpp.

References CastToDerivedClass(), clang::CSK_Derived, clang::Type::getAs(), clang::Type::getAsCXXRecordDecl(), clang::CXXRecordDecl::getCanonicalDecl(), clang::Type::getPointeeType(), clang::Expr::getType(), and clang::CastExpr::path_size().

Referenced by EvaluatePointer().

◆ HandleClassZeroInitialization()

static bool HandleClassZeroInitialization ( EvalInfo &  Info,
const Expr E,
const RecordDecl RD,
const LValue &  This,
APValue Result 
)
static

Perform zero-initialization on an object of non-union class type.

C++11 [dcl.init]p5: To zero-initialize an object or reference of type T means: [...] – if T is a (possibly cv-qualified) non-union class type, each non-static data member and each base-class subobject is zero-initialized

Definition at line 8785 of file ExprConstant.cpp.

References distance(), clang::RecordDecl::field_begin(), clang::RecordDecl::field_end(), clang::Decl::isInvalidDecl(), and clang::TagDecl::isUnion().

◆ handleCompoundAssignment()

static bool handleCompoundAssignment ( EvalInfo &  Info,
const Expr E,
const LValue &  LVal,
QualType  LValType,
QualType  PromotedLValType,
BinaryOperatorKind  Opcode,
const APValue RVal 
)
static

◆ HandleConstructorCall() [1/2]

static bool HandleConstructorCall ( const Expr E,
const LValue &  This,
APValue ArgValues,
const CXXConstructorDecl Definition,
EvalInfo &  Info,
APValue Result 
)
static

◆ HandleConstructorCall() [2/2]

static bool HandleConstructorCall ( const Expr E,
const LValue &  This,
ArrayRef< const Expr *>  Args,
const CXXConstructorDecl Definition,
EvalInfo &  Info,
APValue Result 
)
static

Definition at line 5726 of file ExprConstant.cpp.

References EvaluateArgs(), HandleConstructorCall(), and clang::Result.

◆ HandleConversionToBool()

static bool HandleConversionToBool ( const APValue Val,
bool Result 
)
static

◆ HandleCovariantReturnAdjustment()

static bool HandleCovariantReturnAdjustment ( EvalInfo &  Info,
const Expr E,
APValue Result,
ArrayRef< QualType Path 
)
static

Perform the adjustment from a value returned by a virtual function to a value of the statically expected type, which may be a pointer or reference to a base class of the returned type.

Definition at line 5145 of file ExprConstant.cpp.

References CastToBaseClass(), clang::APValue::isLValue(), and clang::APValue::isNullPointer().

◆ HandleDestruction() [1/2]

static bool HandleDestruction ( EvalInfo &  Info,
const Expr E,
const LValue &  This,
QualType  ThisType 
)
static

Perform a destructor or pseudo-destructor call on the given object, which might in general not be a complete object.

Definition at line 5930 of file ExprConstant.cpp.

References clang::AK_Destroy, findCompleteObject(), findSubobject(), and clang::interp::This().

Referenced by EvaluateAtomic(), and clang::VarDecl::evaluateDestruction().

◆ HandleDestruction() [2/2]

static bool HandleDestruction ( EvalInfo &  Info,
SourceLocation  Loc,
APValue::LValueBase  LVBase,
APValue Value,
QualType  T 
)
static

Destroy and end the lifetime of the given complete object.

Definition at line 5938 of file ExprConstant.cpp.

References HandleDestructionImpl().

◆ HandleDestructionImpl()

static bool HandleDestructionImpl ( EvalInfo &  Info,
SourceLocation  CallLoc,
const LValue &  This,
APValue Value,
QualType  T 
)
static

◆ HandleDynamicCast()

static bool HandleDynamicCast ( EvalInfo &  Info,
const ExplicitCastExpr E,
LValue &  Ptr 
)
static

Apply the given dynamic cast operation on the provided lvalue.

This implements the hard case of dynamic_cast, requiring a "runtime check" to find a suitable target subobject.

Definition at line 5186 of file ExprConstant.cpp.

References clang::AK_DynamicCast, clang::C, CastToDerivedClass(), ComputeDynamicType(), clang::Type::getPointeeCXXRecordDecl(), clang::Expr::getType(), clang::ExplicitCastExpr::getTypeAsWritten(), clang::Expr::isGLValue(), and clang::Type::isVoidPointerType().

Referenced by EvaluatePointer().

◆ handleFloatFloatBinOp()

static bool handleFloatFloatBinOp ( EvalInfo &  Info,
const Expr E,
APFloat &  LHS,
BinaryOperatorKind  Opcode,
const APFloat &  RHS 
)
static

Perform the given binary floating-point operation, in-place, on LHS.

Definition at line 2586 of file ExprConstant.cpp.

Referenced by handleAssignment().

◆ HandleFloatToFloatCast()

static bool HandleFloatToFloatCast ( EvalInfo &  Info,
const Expr E,
QualType  SrcType,
QualType  DestType,
APFloat &  Result 
)
static

Definition at line 2357 of file ExprConstant.cpp.

References clang::Result.

Referenced by EvaluateComplex(), and handleAssignment().

◆ HandleFloatToIntCast()

static bool HandleFloatToIntCast ( EvalInfo &  Info,
const Expr E,
QualType  SrcType,
const APFloat &  Value,
QualType  DestType,
APSInt Result 
)
static

◆ HandleFunctionCall()

static bool HandleFunctionCall ( SourceLocation  CallLoc,
const FunctionDecl Callee,
const LValue *  This,
ArrayRef< const Expr *>  Args,
const Stmt Body,
EvalInfo &  Info,
APValue Result,
const LValue *  ResultSlot 
)
static

◆ handleIncDec()

static bool handleIncDec ( EvalInfo &  Info,
const Expr E,
const LValue &  LVal,
QualType  LValType,
bool  IsIncrement,
APValue Old 
)
static

Perform an increment or decrement on LVal.

Definition at line 4052 of file ExprConstant.cpp.

References clang::AK_Decrement, clang::AK_Increment, findCompleteObject(), and findSubobject().

◆ handleIntIntBinOp()

static bool handleIntIntBinOp ( EvalInfo &  Info,
const Expr E,
const APSInt LHS,
BinaryOperatorKind  Opcode,
APSInt  RHS,
APSInt Result 
)
static

Perform the given binary integer operation.

Definition at line 2484 of file ExprConstant.cpp.

References CheckedIntArithmetic(), clang::Expr::getType(), and HandleOverflow().

Referenced by handleAssignment().

◆ HandleIntToFloatCast()

static bool HandleIntToFloatCast ( EvalInfo &  Info,
const Expr E,
QualType  SrcType,
const APSInt Value,
QualType  DestType,
APFloat &  Result 
)
static

Definition at line 2380 of file ExprConstant.cpp.

Referenced by EvaluateComplex(), and handleAssignment().

◆ HandleIntToIntCast()

static APSInt HandleIntToIntCast ( EvalInfo &  Info,
const Expr E,
QualType  DestType,
QualType  SrcType,
const APSInt Value 
)
static

◆ HandleLValueArrayAdjustment() [1/2]

static bool HandleLValueArrayAdjustment ( EvalInfo &  Info,
const Expr E,
LValue &  LVal,
QualType  EltTy,
APSInt  Adjustment 
)
static

Update a pointer value to model pointer arithmetic.

Parameters
Info- Information about the ongoing evaluation.
E- The expression being evaluated, for diagnostic purposes.
LVal- The pointer value to be updated.
EltTy- The pointee type represented by LVal.
Adjustment- The adjustment, in objects of type EltTy, to add.

Definition at line 2778 of file ExprConstant.cpp.

References clang::Expr::getExprLoc(), and HandleSizeof().

Referenced by EvaluatePointer(), GetAlignOfExpr(), handleAssignment(), handleCompoundAssignment(), HandleDestructionImpl(), HandleLValueArrayAdjustment(), and tryEvaluateBuiltinObjectSize().

◆ HandleLValueArrayAdjustment() [2/2]

static bool HandleLValueArrayAdjustment ( EvalInfo &  Info,
const Expr E,
LValue &  LVal,
QualType  EltTy,
int64_t  Adjustment 
)
static

Definition at line 2789 of file ExprConstant.cpp.

References HandleLValueArrayAdjustment().

◆ HandleLValueBase()

static bool HandleLValueBase ( EvalInfo &  Info,
const Expr E,
LValue &  Obj,
const CXXRecordDecl DerivedDecl,
const CXXBaseSpecifier Base 
)
static

◆ HandleLValueBasePath()

static bool HandleLValueBasePath ( EvalInfo &  Info,
const CastExpr E,
QualType  Type,
LValue &  Result 
)
static

◆ HandleLValueComplexElement()

static bool HandleLValueComplexElement ( EvalInfo &  Info,
const Expr E,
LValue &  LVal,
QualType  EltTy,
bool  Imag 
)
static

Update an lvalue to refer to a component of a complex number.

Parameters
Info- Information about the ongoing evaluation.
LVal- The lvalue to be updated.
EltTy- The complex number's component type.
Imag- False for the real component, true for the imaginary.

Definition at line 2801 of file ExprConstant.cpp.

References clang::Expr::getExprLoc(), and HandleSizeof().

◆ HandleLValueDirectBase()

static bool HandleLValueDirectBase ( EvalInfo &  Info,
const Expr E,
LValue &  Obj,
const CXXRecordDecl Derived,
const CXXRecordDecl Base,
const ASTRecordLayout RL = nullptr 
)
static

◆ HandleLValueIndirectMember()

static bool HandleLValueIndirectMember ( EvalInfo &  Info,
const Expr E,
LValue &  LVal,
const IndirectFieldDecl IFD 
)
static

Update LVal to refer to the given indirect field.

Definition at line 2737 of file ExprConstant.cpp.

References clang::C, clang::IndirectFieldDecl::chain(), and HandleLValueMember().

◆ HandleLValueMember()

static bool HandleLValueMember ( EvalInfo &  Info,
const Expr E,
LValue &  LVal,
const FieldDecl FD,
const ASTRecordLayout RL = nullptr 
)
static

Update LVal to refer to the given field, which must be a member of the type currently described by LVal.

Definition at line 2722 of file ExprConstant.cpp.

References clang::FieldDecl::getFieldIndex(), clang::FieldDecl::getParent(), and clang::Decl::isInvalidDecl().

Referenced by EvaluateLValue(), evaluateLValueAsAllocSize(), HandleConstructorCall(), HandleDestructionImpl(), and HandleLValueIndirectMember().

◆ handleLValueToRValueConversion()

static bool handleLValueToRValueConversion ( EvalInfo &  Info,
const Expr Conv,
QualType  Type,
const LValue &  LVal,
APValue RVal,
bool  WantObjectRepresentation = false 
)
static

Perform an lvalue-to-rvalue conversion on the given glvalue.

This can also be used for 'lvalue-to-lvalue' conversions for looking up the glvalue referred to by an entity of reference type.

Parameters
Info- Information about the ongoing evaluation.
Conv- The expression for which we are performing the conversion. Used for diagnostics.
Type- The type of the glvalue (before stripping cv-qualifiers in the case of a non-class type).
LVal- The glvalue on which we are attempting to perform this action.
RVal- The produced value will be placed here.
WantObjectRepresentation- If true, we're looking for the object representation rather than the value, and in particular, there is no requirement that the result be fully initialized.

Definition at line 3727 of file ExprConstant.cpp.

References clang::AK_Read, clang::AK_ReadObjectRepresentation, Evaluate(), extractStringLiteralCharacter(), extractSubobject(), findCompleteObject(), clang::Expr::getType(), and clang::QualType::isVolatileQualified().

Referenced by EvaluateAsRValue(), EvaluateComparisonBinaryOperator(), EvaluateLValue(), evaluateLValueAsAllocSize(), EvaluatePointer(), GetAlignOfExpr(), HandleConstructorCall(), HandleFunctionCall(), and tryEvaluateBuiltinObjectSize().

◆ HandleMemberPointerAccess() [1/2]

static const ValueDecl* HandleMemberPointerAccess ( EvalInfo &  Info,
QualType  LVType,
LValue &  LV,
const Expr RHS,
bool  IncludeMember = true 
)
static

HandleMemberPointerAccess - Evaluate a member access operation and build an lvalue referring to the result.

Parameters
Info- Information about the ongoing evaluation.
LV- An lvalue referring to the base of the member pointer.
RHS- The member pointer expression.
IncludeMember- Specifies whether the member itself is included in the resulting LValue subobject designator. This is not possible when creating a bound member function.
Returns
The field or method declaration to which the member pointer refers, or 0 if evaluation fails.

Definition at line 4095 of file ExprConstant.cpp.

References CastToDerivedClass(), EvaluateMemberPointer(), clang::Type::getAs(), clang::Type::getAsCXXRecordDecl(), clang::CXXRecordDecl::getCanonicalDecl(), clang::Type::getPointeeType(), and HandleLValueDirectBase().

Referenced by HandleMemberPointerAccess().

◆ HandleMemberPointerAccess() [2/2]

static const ValueDecl* HandleMemberPointerAccess ( EvalInfo &  Info,
const BinaryOperator BO,
LValue &  LV,
bool  IncludeMember = true 
)
static

◆ HandleOperatorDeleteCall()

bool HandleOperatorDeleteCall ( EvalInfo &  Info,
const CallExpr E 
)

◆ HandleOperatorNewCall()

static bool HandleOperatorNewCall ( EvalInfo &  Info,
const CallExpr E,
LValue &  Result 
)
static

◆ HandleOverflow()

template<typename T >
static bool HandleOverflow ( EvalInfo &  Info,
const Expr E,
const T &  SrcValue,
QualType  DestType 
)
static

◆ HandleSizeof()

static bool HandleSizeof ( EvalInfo &  Info,
SourceLocation  Loc,
QualType  Type,
CharUnits Size 
)
static

◆ HandleUnionActiveMemberChange()

static bool HandleUnionActiveMemberChange ( EvalInfo &  Info,
const Expr LHSExpr,
const LValue &  LHS 
)
static

Handle a builtin simple-assignment or a call to a trivial assignment operator whose left-hand side might involve a union member access.

If it does, implicitly start the lifetime of any accessed union elements per C++20 [class.union]5.

Definition at line 5318 of file ExprConstant.cpp.

References clang::declaresSameEntity().

Referenced by HandleFunctionCall().

◆ HandleVirtualDispatch()

static const CXXMethodDecl* HandleVirtualDispatch ( EvalInfo &  Info,
const Expr E,
LValue &  This,
const CXXMethodDecl Found,
llvm::SmallVectorImpl< QualType > &  CovariantAdjustmentPath 
)
static

◆ hasFields()

static bool hasFields ( const CXXRecordDecl RD)
static

Determine if a class has any fields that might need to be copied by a trivial copy or move operation.

Definition at line 5406 of file ExprConstant.cpp.

References clang::CXXRecordDecl::bases(), clang::RecordDecl::fields(), and clang::CXXRecordDecl::isEmpty().

Referenced by HandleConstructorCall(), and HandleFunctionCall().

◆ HasSameBase()

static bool HasSameBase ( const LValue &  A,
const LValue &  B 
)
static

◆ hasUnacceptableSideEffect()

static bool hasUnacceptableSideEffect ( Expr::EvalStatus Result,
Expr::SideEffectsKind  SEK 
)
static

◆ hasVirtualDestructor()

static bool hasVirtualDestructor ( QualType  T)
static

Definition at line 6015 of file ExprConstant.cpp.

References clang::Type::getAsCXXRecordDecl().

Referenced by EvaluateAtomic().

◆ ignorePointerCastsAndParens()

static const Expr* ignorePointerCastsAndParens ( const Expr E)
static

A more selective version of E->IgnoreParenCasts for tryEvaluateBuiltinObjectSize.

This ignores some casts/parens that serve only to change the type of E. Ex. For E = (short*)((char*)(&foo)), returns &foo

Always returns an RValue with a pointer representation.

Definition at line 10191 of file ExprConstant.cpp.

References clang::interp::Cast(), clang::Expr::getType(), clang::Type::hasPointerRepresentation(), clang::Expr::IgnoreParens(), and clang::Expr::isRValue().

Referenced by tryEvaluateBuiltinObjectSize().

◆ isAnyAccess()

static bool isAnyAccess ( AccessKinds  AK)
static

Definition at line 1412 of file ExprConstant.cpp.

References isModification(), and isRead().

Referenced by findCompleteObject(), and isFormalAccess().

◆ isBaseClassPublic()

static bool isBaseClassPublic ( const CXXRecordDecl Derived,
const CXXRecordDecl Base 
)
static

Determine whether Base, which is known to be a direct base class of Derived, is a public base class.

Definition at line 5172 of file ExprConstant.cpp.

References clang::AS_public, clang::CXXRecordDecl::bases(), and clang::declaresSameEntity().

◆ IsConstNonVolatile()

static bool IsConstNonVolatile ( QualType  T)
static

◆ isDesignatorAtObjectEnd()

static bool isDesignatorAtObjectEnd ( const ASTContext Ctx,
const LValue &  LVal 
)
static

Checks to see if the given LValue's Designator is at the end of the LValue's record layout.

e.g. struct { struct { int a, b; } fst, snd; } obj; obj.fst // no obj.snd // yes obj.fst.a // no obj.fst.b // no obj.snd.a // no obj.snd.b // yes

Please note: this function is specialized for how __builtin_object_size views "objects".

If this encounters an invalid RecordDecl or otherwise cannot determine the correct result, it will always return true.

Definition at line 10227 of file ExprConstant.cpp.

References clang::Type::castAs(), clang::ASTContext::getAsArrayType(), clang::ASTContext::getASTRecordLayout(), clang::ArrayType::getElementType(), clang::ASTRecordLayout::getFieldCount(), clang::FieldDecl::getFieldIndex(), clang::FieldDecl::getParent(), clang::Type::isArrayType(), clang::Type::isIncompleteArrayType(), clang::Decl::isInvalidDecl(), clang::TagDecl::isUnion(), and Parent.

Referenced by isUserWritingOffTheEnd().

◆ isFormalAccess()

static bool isFormalAccess ( AccessKinds  AK)
static

◆ IsGlobalLValue()

static bool IsGlobalLValue ( APValue::LValueBase  B)
static

◆ IsLiteralLValue()

static bool IsLiteralLValue ( const LValue &  Value)
static

Definition at line 1920 of file ExprConstant.cpp.

Referenced by EvaluateComparisonBinaryOperator().

◆ isModification()

static bool isModification ( AccessKinds  AK)
static

◆ isOnePastTheEndOfCompleteObject()

static bool isOnePastTheEndOfCompleteObject ( const ASTContext Ctx,
const LValue &  LV 
)
static

◆ isRead()

static bool isRead ( AccessKinds  AK)
static

◆ isReadByLvalueToRvalueConversion()

static bool isReadByLvalueToRvalueConversion ( QualType  T)
static

Determine whether a type would actually be read by an lvalue-to-rvalue conversion.

If it's of class type, we may assume that the copy operation is trivial. Note that this is never true for a union type with fields (because the copy always "reads" the active member) and always true for a non-class type.

Definition at line 3010 of file ExprConstant.cpp.

References clang::CXXRecordDecl::bases(), clang::RecordDecl::field_empty(), clang::RecordDecl::fields(), clang::Type::getAsCXXRecordDecl(), clang::Type::getBaseElementTypeUnsafe(), clang::CXXRecordDecl::isEmpty(), and clang::TagDecl::isUnion().

Referenced by diagnoseMutableFields().

◆ IsStringLiteralCall()

static bool IsStringLiteralCall ( const CallExpr E)
static

Should this call expression be treated as a string literal?

Definition at line 1850 of file ExprConstant.cpp.

References clang::CallExpr::getBuiltinCallee().

Referenced by GetAlignOfExpr(), and IsGlobalLValue().

◆ isUserWritingOffTheEnd()

static bool isUserWritingOffTheEnd ( const ASTContext Ctx,
const LValue &  LVal 
)
static

Attempts to detect a user writing into a piece of memory that's impossible to figure out the size of by just using types.

Definition at line 10319 of file ExprConstant.cpp.

References isDesignatorAtObjectEnd().

Referenced by determineEndOffset().

◆ IsWeakLValue()

static bool IsWeakLValue ( const LValue &  Value)
static

Definition at line 1927 of file ExprConstant.cpp.

References GetLValueBaseDecl(), and clang::ValueDecl::isWeak().

Referenced by EvaluateComparisonBinaryOperator().

◆ isZeroSized()

static bool isZeroSized ( const LValue &  Value)
static

◆ lifetimeStartedInEvaluation()

static bool lifetimeStartedInEvaluation ( EvalInfo &  Info,
APValue::LValueBase  Base,
bool  MutableSubobject = false 
)
static

◆ MaybeElementDependentArrayFiller()

static bool MaybeElementDependentArrayFiller ( const Expr FillerExpr)
static

◆ modifySubobject()

static bool modifySubobject ( EvalInfo &  Info,
const Expr E,
const CompleteObject &  Obj,
const SubobjectDesignator &  Sub,
APValue NewVal 
)
static

Update the designated sub-object of an rvalue to the given value.

Definition at line 3440 of file ExprConstant.cpp.

References findSubobject().

Referenced by handleAssignment().

◆ negateAsSigned()

static void negateAsSigned ( APSInt Int)
static

Negate an APSInt in place, converting it to a signed form if necessary, and preserving its value (by extending by up to one bit as needed).

Definition at line 1757 of file ExprConstant.cpp.

Referenced by EvaluatePointer(), and handleAssignment().

◆ NoDiag()

static ICEDiag NoDiag ( )
static

Definition at line 13797 of file ExprConstant.cpp.

Referenced by CheckICE().

◆ NoteLValueLocation()

static void NoteLValueLocation ( EvalInfo &  Info,
APValue::LValueBase  Base 
)
static

◆ refersToCompleteObject()

static bool refersToCompleteObject ( const LValue &  LVal)
static

Tests to see if the LValue has a user-specified designator (that isn't necessarily valid).

Note that this always returns 'true' if the LValue has an unsized array as its first designator entry, because there's currently no way to tell if the user typed *foo or foo[0].

Definition at line 10301 of file ExprConstant.cpp.

Referenced by determineEndOffset().

◆ truncateBitfieldValue()

static bool truncateBitfieldValue ( EvalInfo &  Info,
const Expr E,
APValue Value,
const FieldDecl FD 
)
static

◆ TryEvaluateBuiltinNaN()

static bool TryEvaluateBuiltinNaN ( const ASTContext Context,
QualType  ResultTy,
const Expr Arg,
bool  SNaN,
llvm::APFloat &  Result 
)
static

Definition at line 12401 of file ExprConstant.cpp.

◆ tryEvaluateBuiltinObjectSize()

static bool tryEvaluateBuiltinObjectSize ( const Expr E,
unsigned  Type,
EvalInfo &  Info,
uint64_t &  Size 
)
static

◆ Worst()

static ICEDiag Worst ( ICEDiag  A,
ICEDiag  B 
)
static

Definition at line 13799 of file ExprConstant.cpp.

Referenced by CheckICE().