Lines Matching +full:manufacture +full:- +full:date
1 //===--- ExprConstant.cpp - Expression Constant Evaluator -----------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
20 // * A flag indicating if evaluation encountered (unevaluated) side-effects.
29 // fold a potential constant sub-expression will be indicated by a 'false'
31 // expression is not necessarily non-constant).
33 //===----------------------------------------------------------------------===//
108 if (E->isPRValue()) in getStorageType()
109 return E->getType(); in getStorageType()
110 return Ctx.getLValueReferenceType(E->getType()); in getStorageType()
115 if (const FunctionDecl *DirectCallee = CE->getDirectCallee()) in getAllocSizeAttr()
116 return DirectCallee->getAttr<AllocSizeAttr>(); in getAllocSizeAttr()
117 if (const Decl *IndirectCallee = CE->getCalleeDecl()) in getAllocSizeAttr()
118 return IndirectCallee->getAttr<AllocSizeAttr>(); in getAllocSizeAttr()
127 if (!E->getType()->isPointerType()) in tryUnwrapAllocSizeCall()
130 E = E->IgnoreParens(); in tryUnwrapAllocSizeCall()
133 // top-level ExprWithCleanups. Ignore them either way. in tryUnwrapAllocSizeCall()
135 E = FE->getSubExpr()->IgnoreParens(); in tryUnwrapAllocSizeCall()
138 E = Cast->getSubExpr()->IgnoreParens(); in tryUnwrapAllocSizeCall()
149 return E && E->getType()->isPointerType() && tryUnwrapAllocSizeCall(E); in isBaseAnAllocSizeCall()
160 // Note that non-type template arguments of class type are emitted as in isForManglingOnly()
191 /// Find the path length and type of the most-derived subobject in the given
206 if (Type->isArrayType()) { in findMostDerivedSubobject()
208 Type = AT->getElementType(); in findMostDerivedSubobject()
213 ArraySize = CAT->getZExtSize(); in findMostDerivedSubobject()
219 } else if (Type->isAnyComplexType()) { in findMostDerivedSubobject()
220 const ComplexType *CT = Type->castAs<ComplexType>(); in findMostDerivedSubobject()
221 Type = CT->getElementType(); in findMostDerivedSubobject()
226 Type = FD->getType(); in findMostDerivedSubobject()
243 /// and we cannot perform lvalue-to-rvalue conversions on them.
255 /// Indicator of whether the most-derived object is an array element.
259 /// The length of the path to the most-derived object of which this is a
263 /// The size of the array of which the most-derived object is an element.
264 /// This will always be 0 if the most-derived object is not an array
265 /// element. 0 is not an indicator of whether or not the most-derived object
266 /// is an array, however, because 0-length arrays are allowed.
292 assert(V.isLValue() && "Non-LValue used to make an LValue designator?"); in SubobjectDesignator()
349 /// Determine whether this is a one-past-the-end pointer.
355 Entries[MostDerivedPathLength - 1].getAsArrayIndex() == in isOnePastTheEnd()
377 return {ArrayIndex, ArraySize - ArrayIndex}; in validIndexAdjustments()
402 // This is a most-derived object. in addArrayUnchecked()
403 MostDerivedType = CAT->getElementType(); in addArrayUnchecked()
405 MostDerivedArraySize = CAT->getZExtSize(); in addArrayUnchecked()
426 // If this isn't a base class, it's a new most-derived object. in addDeclUnchecked()
428 MostDerivedType = FD->getType(); in addDeclUnchecked()
438 // This is technically a most-derived object, though in practice this in addComplexUnchecked()
454 // Can't verify -- trust that the user is doing the right thing (or if in adjustIndex()
472 if (N < -(int64_t)ArrayIndex || N > ArraySize - ArrayIndex) { in adjustIndex()
477 assert(N.ugt(ArraySize) && "bounds check failed for in-bounds index"); in adjustIndex()
485 "bounds check succeeded for out-of-bounds index"); in adjustIndex()
512 return OrigCallee ? OrigCallee->getParamDecl(PVD->getFunctionScopeIndex()) in getOrigParam()
532 /// Parent - The caller of this stack frame.
535 /// Callee - The function which was called.
538 /// This - The binding for the this pointer in this call, if any.
541 /// CallExpr - The syntactical structure of member function calls
557 /// Temporaries - Temporary lvalues materialized within this stack frame.
560 /// CallRange - The source range of the call expression for this call.
563 /// Index - The call index of this call.
585 // on the overall stack usage of deeply-recursing constexpr evaluations.
590 /// LambdaCaptureFields - Mapping from captured variables/this to
604 if (LB != Temporaries.end() && LB->first == KV) in getTemporary()
605 return &LB->second; in getTemporary()
612 if (UB != Temporaries.begin() && std::prev(UB)->first.first == Key) in getCurrentTemporary()
613 return &std::prev(UB)->second; in getCurrentTemporary()
620 if (UB != Temporaries.begin() && std::prev(UB)->first.first == Key) in getCurrentTemporaryVersion()
621 return std::prev(UB)->first.second; in getCurrentTemporaryVersion()
643 for (const DeclContext *DC = Callee; DC; DC = DC->getParent()) in isStdFunction()
644 if (DC->isStdNamespace()) in isStdFunction()
680 return E->getSourceRange().printToString(Ctx.getSourceManager()); in ExprTimeTraceScope()
708 /// A cleanup, and a flag indicating whether it is lifetime-extended.
728 Loc = VD->getLocation(); in endLifetime()
730 Loc = E->getExprLoc(); in endLifetime()
783 /// A dynamically-allocated heap object.
785 /// The value of this heap-allocated object.
802 return NE->isArray() ? ArrayNew : New; in getKind()
814 /// EvalInfo - This is a private struct used by the evaluator to capture
832 /// EvalStatus - Contains information about the evaluation.
835 /// CurrentCall - The top of the constexpr call stack.
838 /// CallStackDepth - The number of calls in the call stack right now.
841 /// NextCallIndex - The next call index to assign.
844 /// StepsLeft - The remaining number of evaluation steps we're permitted
853 /// BottomFrame - The frame in which evaluation started. This must be
861 /// EvaluatingDecl - This is the declaration whose initializer is being
874 /// EvaluatingDeclValue - This is the value being constructed for the
946 uint64_t ArrayInitIndex = -1;
948 /// HasActiveDiagnostic - Was the previous diagnostic stored? If so, further
981 /// Fold the expression to a constant. Stop if we hit a side-effect that
985 /// Evaluate in any way we know how. Don't worry about side-effects that
1080 while (Frame->Index > CallIndex) { in getCallFrameAndDepth()
1081 Frame = Frame->Caller; in getCallFrameAndDepth()
1082 --Depth; in getCallFrameAndDepth()
1084 if (Frame->Index == CallIndex) in getCallFrameAndDepth()
1091 FFDiag(S->getBeginLoc(), diag::note_constexpr_step_limit_exceeded); in nextStep()
1094 --StepsLeft; in nextStep()
1104 Result = &It->second; in lookupDynamicAlloc()
1111 return Frame ? Frame->getTemporary(Call.getOrigParam(PVD), Call.Version) in getParamSlot()
1124 Call = Call->Caller) { in getStdAllocatorCaller()
1125 const auto *MD = dyn_cast_or_null<CXXMethodDecl>(Call->Callee); in getStdAllocatorCaller()
1128 const IdentifierInfo *FnII = MD->getIdentifier(); in getStdAllocatorCaller()
1129 if (!FnII || !FnII->isStr(FnName)) in getStdAllocatorCaller()
1133 dyn_cast<ClassTemplateSpecializationDecl>(MD->getParent()); in getStdAllocatorCaller()
1137 const IdentifierInfo *ClassII = CTSD->getIdentifier(); in getStdAllocatorCaller()
1138 const TemplateArgumentList &TAL = CTSD->getTemplateArgs(); in getStdAllocatorCaller()
1139 if (CTSD->isInStdNamespace() && ClassII && in getStdAllocatorCaller()
1140 ClassII->isStr("allocator") && TAL.size() >= 1 && in getStdAllocatorCaller()
1142 return {Call->Index, TAL[0].getAsType()}; in getStdAllocatorCaller()
1149 // Disable the cleanups for lifetime-extended temporaries. in performLifetimeExtension()
1156 /// cleanups would have had a side-effect, note that as an unmodeled
1157 /// side-effect and return false. Otherwise, return true.
1189 if (!EvalStatus.Diag->empty()) { in hasPriorDiagnostic()
1209 /// Should we continue evaluation after encountering a side-effect that we
1227 /// Note that we have had a side-effect, and determine whether we should
1249 /// that we can evaluate past it (such as signed overflow or floating-point
1288 // subexpression implies that a side-effect has potentially happened. We in noteFailure()
1322 Info.EvalStatus.Diag->empty() && in FoldConstant()
1330 if (Enabled && HadNoPriorDiags && !Info.EvalStatus.Diag->empty() && in ~FoldConstant()
1332 Info.EvalStatus.Diag->clear(); in ~FoldConstant()
1338 /// side-effects.
1350 /// RAII object used to optionally suppress diagnostics and side-effects from
1368 Info->EvalStatus = OldStatus; in maybeRestoreState()
1369 Info->SpeculativeEvaluationDepth = OldSpeculativeEvaluationDepth; in maybeRestoreState()
1397 /// RAII object wrapping a full-expression or block scope, and handling
1408 Info.CurrentCall->pushTempVersion(); in ScopeRAII()
1412 OldStackSize = -1U; in destroy()
1416 if (OldStackSize != -1U) in ~ScopeRAII()
1420 Info.CurrentCall->popTempVersion(); in ~ScopeRAII()
1428 // Run all cleanups for a block scope, and non-lifetime-extended cleanups in cleanup()
1429 // for a full-expression scope. in cleanup()
1431 for (unsigned I = Info.CleanupStack.size(); I > OldStackSize; --I) { in cleanup()
1432 if (Info.CleanupStack[I - 1].isDestroyedAtEndOf(Kind)) { in cleanup()
1433 if (!Info.CleanupStack[I - 1].endLifetime(Info, RunDestructors)) { in cleanup()
1490 << N << /*non-array*/ 1; in diagnosePointerArithmetic()
1506 --Info.CallStackDepth; in ~CallStackFrame()
1634 assert(V.isLValue() && "Setting LValue from a non-LValue?"); in setFrom()
1664 Designator = SubobjectDesignator(PointerTy->getPointeeType()); in setNull()
1727 assert(getType(Base)->isPointerType() || getType(Base)->isArrayType()); in addUnsizedArray()
1751 // FIXME: When compiling for a 32-bit target, we should use 32-bit in adjustOffsetAndIndex()
1786 DeclAndIsDerivedMember.getPointer()->getDeclContext()); in getContainingRecord()
1801 /// DeclAndIsDerivedMember - The member declaration, and a flag indicating
1805 /// Path - The path of base/derived classes from the member declaration's
1815 Expected = Path[Path.size() - 2]; in castBack()
1818 if (Expected->getCanonicalDecl() != Class->getCanonicalDecl()) { in castBack()
1830 /// Perform a base-to-derived member pointer cast.
1844 /// Perform a derived-to-base member pointer cast.
1862 if (LHS.getDecl()->getCanonicalDecl() != RHS.getDecl()->getCanonicalDecl()) in operator ==()
1899 //===----------------------------------------------------------------------===//
1901 //===----------------------------------------------------------------------===//
1910 Int = -Int; in negateAsSigned()
1929 // them to live to the end of the full-expression at runtime, in order to in createParam()
1931 return createLocal(Base, PVD, PVD->getType(), ScopeKind::Call); in createParam()
1965 Result.first->second.AllocExpr = E; in createHeapAlloc()
1966 return &Result.first->second.Value; in createHeapAlloc()
1974 cast<CXXMethodDecl>(Callee)->isImplicitObjectMemberFunction(); in describe()
1977 Callee->getNameForDiagnostic(Out, Info.Ctx.getPrintingPolicy(), in describe()
1982 const Expr *Object = MCE->getImplicitObjectArgument(); in describe()
1983 Object->printPretty(Out, /*Helper=*/nullptr, Info.Ctx.getPrintingPolicy(), in describe()
1985 if (Object->getType()->isPointerType()) in describe()
1986 Out << "->"; in describe()
1991 OCE->getArg(0)->printPretty(Out, /*Helper=*/nullptr, in describe()
1997 This->moveInto(Val); in describe()
2000 Info.Ctx.getLValueReferenceType(This->Designator.MostDerivedType)); in describe()
2003 Callee->getNameForDiagnostic(Out, Info.Ctx.getPrintingPolicy(), in describe()
2010 for (FunctionDecl::param_const_iterator I = Callee->param_begin(), in describe()
2011 E = Callee->param_end(); I != E; ++I, ++ArgIndex) { in describe()
2018 V->printPretty(Out, Info.Ctx, Param->getType()); in describe()
2023 Out << "->" << *Callee << '('; in describe()
2029 /// Evaluate an expression to see if it had side-effects, and discard its
2033 assert(!E->isValueDependent()); in EvaluateIgnoredValue()
2041 /// Should this call expression be treated as a no-op?
2043 unsigned Builtin = E->getBuiltinCallee(); in IsNoOpCall()
2062 return VD->hasGlobalStorage(); in IsGlobalLValue()
2075 switch (E->getStmtClass()) { in IsGlobalLValue()
2080 return CLE->isFileScope() && CLE->isLValue(); in IsGlobalLValue()
2083 // A materialized temporary might have been lifetime-extended to static in IsGlobalLValue()
2085 return cast<MaterializeTemporaryExpr>(E)->getStorageDuration() == SD_Static; in IsGlobalLValue()
2093 return cast<ObjCBoxedExpr>(E)->isExpressibleAsConstantInitializer(); in IsGlobalLValue()
2102 return !cast<BlockExpr>(E)->getBlockDecl()->hasCaptures(); in IsGlobalLValue()
2131 return Decl && Decl->isWeak(); in IsWeakLValue()
2137 QualType Ty = Decl->getType(); in isZeroSized()
2138 if (Ty->isArrayType()) in isZeroSized()
2139 return Ty->isIncompleteType() || in isZeroSized()
2140 Decl->getASTContext().getTypeSize(Ty) == 0; in isZeroSized()
2167 unsigned Idx = PVD->getFunctionScopeIndex(); in NoteLValueLocation()
2168 for (CallStackFrame *F = Info.CurrentCall; F; F = F->Caller) { in NoteLValueLocation()
2169 if (F->Arguments.CallIndex == Base.getCallIndex() && in NoteLValueLocation()
2170 F->Arguments.Version == Base.getVersion() && F->Callee && in NoteLValueLocation()
2171 Idx < F->Callee->getNumParams()) { in NoteLValueLocation()
2172 VD = F->Callee->getParamDecl(Idx); in NoteLValueLocation()
2179 Info.Note(VD->getLocation(), diag::note_declared_at); in NoteLValueLocation()
2181 Info.Note(E->getExprLoc(), diag::note_constexpr_temporary_here); in NoteLValueLocation()
2185 Info.Note((*Alloc)->AllocExpr->getExprLoc(), in NoteLValueLocation()
2216 bool IsReferenceType = Type->isReferenceType(); in CheckLValueConstantExpression()
2228 int InvalidBaseKind = -1; in CheckLValueConstantExpression()
2239 Ident = PE->getIdentKindName(); in CheckLValueConstantExpression()
2242 if (InvalidBaseKind != -1) { in CheckLValueConstantExpression()
2251 FD && FD->isImmediateFunction()) { in CheckLValueConstantExpression()
2253 << !Type->isAnyPointerType(); in CheckLValueConstantExpression()
2254 Info.Note(FD->getLocation(), diag::note_declared_at); in CheckLValueConstantExpression()
2259 // manufacture when checking potential constant expressions is conservatively in CheckLValueConstantExpression()
2267 if (VarD && VarD->isConstexpr()) { in CheckLValueConstantExpression()
2268 // Non-static local constexpr variables have unintuitive semantics: in CheckLValueConstantExpression()
2273 Info.Note(VarD->getLocation(), diag::note_constexpr_not_static) in CheckLValueConstantExpression()
2275 << FixItHint::CreateInsertion(VarD->getBeginLoc(), "static "); in CheckLValueConstantExpression()
2298 // Check if this is a thread-local variable. in CheckLValueConstantExpression()
2299 if (Var->getTLSKind()) in CheckLValueConstantExpression()
2305 if (!isForManglingOnly(Kind) && Var->hasAttr<DLLImportAttr>()) in CheckLValueConstantExpression()
2314 if ((!Var->hasAttr<CUDADeviceAttr>() && in CheckLValueConstantExpression()
2315 !Var->hasAttr<CUDAConstantAttr>() && in CheckLValueConstantExpression()
2316 !Var->getType()->isCUDADeviceBuiltinSurfaceType() && in CheckLValueConstantExpression()
2317 !Var->getType()->isCUDADeviceBuiltinTextureType()) || in CheckLValueConstantExpression()
2318 Var->hasAttr<HIPManagedAttr>()) in CheckLValueConstantExpression()
2325 // Doing otherwise would allow the same id-expression to yield in CheckLValueConstantExpression()
2334 FD->hasAttr<DLLImportAttr>()) in CheckLValueConstantExpression()
2343 Info.FFDiag(MTE->getExprLoc(), in CheckLValueConstantExpression()
2349 APValue *V = MTE->getOrCreateValue(false); in CheckLValueConstantExpression()
2352 Info, MTE->getExprLoc(), TempType, *V, Kind, in CheckLValueConstantExpression()
2358 // Allow address constant expressions to be past-the-end pointers. This is in CheckLValueConstantExpression()
2381 /// non-virtual dllimport member function.
2391 if (FD->isImmediateFunction()) { in CheckMemberPointerConstantExpression()
2393 Info.Note(FD->getLocation(), diag::note_declared_at); in CheckMemberPointerConstantExpression()
2396 return isForManglingOnly(Kind) || FD->isVirtual() || in CheckMemberPointerConstantExpression()
2397 !FD->hasAttr<DLLImportAttr>(); in CheckMemberPointerConstantExpression()
2404 if (!E->isPRValue() || E->getType()->isLiteralType(Info.Ctx)) in CheckLiteralType()
2409 // are of non-literal class types. in CheckLiteralType()
2416 // because "i" is a subobject with non-literal initialization (due to the in CheckLiteralType()
2418 // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1677 in CheckLiteralType()
2420 if (This && Info.EvaluatingDecl == This->getLValueBase()) in CheckLiteralType()
2426 << E->getType(); in CheckLiteralType()
2442 Info.Note(SubobjectDecl->getLocation(), in CheckEvaluationResult()
2453 if (const AtomicType *AT = Type->getAs<AtomicType>()) in CheckEvaluationResult()
2454 Type = AT->getValueType(); in CheckEvaluationResult()
2460 QualType EltTy = Type->castAsArrayTypeUnsafe()->getElementType(); in CheckEvaluationResult()
2475 CERK, Info, DiagLoc, Value.getUnionField()->getType(), in CheckEvaluationResult()
2479 RecordDecl *RD = Type->castAs<RecordType>()->getDecl(); in CheckEvaluationResult()
2482 for (const CXXBaseSpecifier &BS : CD->bases()) { in CheckEvaluationResult()
2497 for (const auto *I : RD->fields()) { in CheckEvaluationResult()
2498 if (I->isUnnamedBitField()) in CheckEvaluationResult()
2501 if (!CheckEvaluationResult(CERK, Info, DiagLoc, I->getType(), in CheckEvaluationResult()
2502 Value.getStructField(I->getFieldIndex()), Kind, in CheckEvaluationResult()
2531 if (Type->isVoidType()) in CheckConstantExpression()
2540 /// Check that this evaluated value is fully-initialized and can be loaded by
2541 /// an lvalue-to-rvalue conversion.
2550 /// Enforce C++2a [expr.const]/4.17, which disallows new-expressions unless
2554 // We can still fold to a constant despite a compile-time memory leak, in CheckMemoryLeaks()
2557 Info.CCEDiag(Info.HeapAllocs.begin()->second.AllocExpr, in CheckMemoryLeaks()
2559 << unsigned(Info.HeapAllocs.size() - 1); in CheckMemoryLeaks()
2568 // TODO: Should a non-null pointer with an offset of zero evaluate to true? in EvalPointerValueAsBool()
2573 // We have a non-null base. These are generally known to be true, but if it's in EvalPointerValueAsBool()
2577 return !Decl || !Decl->isWeak(); in EvalPointerValueAsBool()
2606 if (Val.getMemberPointerDecl() && Val.getMemberPointerDecl()->isWeak()) { in HandleConversionToBool()
2624 assert(!E->isValueDependent()); in EvaluateAsBooleanCondition()
2625 assert(E->isPRValue() && "missing lvalue-to-rvalue conv in bool condition"); in EvaluateAsBooleanCondition()
2645 bool DestSigned = DestType->isSignedIntegerOrEnumerationType(); in HandleFloatToIntCast()
2662 E->getFPFeaturesInEffect(Info.Ctx.getLangOpts()).getRoundingMode(); in getActiveRoundingMode()
2672 // exception state matches the default floating-point environment. in checkFloatingPointResult()
2676 FPOptions FPO = E->getFPFeaturesInEffect(Info.Ctx.getLangOpts()); in checkFloatingPointResult()
2701 // - evaluation triggered other FP exception, and in checkFloatingPointResult()
2702 // - exception mode is not "ignore", and in checkFloatingPointResult()
2703 // - the expression being evaluated is not a part of global variable in checkFloatingPointResult()
2732 Result.setIsUnsigned(DestType->isUnsignedIntegerOrEnumerationType()); in HandleIntToIntCast()
2733 if (DestType->isBooleanType()) in HandleIntToIntCast()
2750 assert(FD->isBitField() && "truncateBitfieldValue on non-bitfield"); in truncateBitfieldValue()
2753 // Trying to store a pointer-cast-to-integer into a bitfield. in truncateBitfieldValue()
2763 unsigned NewBitWidth = FD->getBitWidthValue(Info.Ctx); in truncateBitfieldValue()
2786 Info.Ctx.getDiagnostics().Report(E->getExprLoc(), in CheckedIntArithmetic()
2790 << E->getType() << E->getSourceRange(); in CheckedIntArithmetic()
2791 return HandleOverflow(Info, E, Value, E->getType()); in CheckedIntArithmetic()
2821 << E->getRHS()->getSourceRange(); in handleIntIntBinOp()
2824 // Check for overflow case: INT_MIN / -1 or INT_MIN % -1. APSInt supports in handleIntIntBinOp()
2829 Info, E, -LHS.extend(LHS.getBitWidth() + 1), E->getType()); in handleIntIntBinOp()
2836 static_cast<uint64_t>(LHS.getBitWidth() - 1)), in handleIntIntBinOp()
2839 // During constant-folding, a negative shift is an opposite shift. Such in handleIntIntBinOp()
2844 RHS = -RHS; in handleIntIntBinOp()
2850 unsigned SA = (unsigned) RHS.getLimitedValue(LHS.getBitWidth()-1); in handleIntIntBinOp()
2853 << RHS << E->getType() << LHS.getBitWidth(); in handleIntIntBinOp()
2857 // C++11 [expr.shift]p2: A signed left shift must have a non-negative in handleIntIntBinOp()
2878 static_cast<uint64_t>(LHS.getBitWidth() - 1)), in handleIntIntBinOp()
2881 // During constant-folding, a negative shift is an opposite shift. Such a in handleIntIntBinOp()
2886 RHS = -RHS; in handleIntIntBinOp()
2892 unsigned SA = (unsigned) RHS.getLimitedValue(LHS.getBitWidth()-1); in handleIntIntBinOp()
2895 << RHS << E->getType() << LHS.getBitWidth(); in handleIntIntBinOp()
2915 /// Perform the given binary floating-point operation, in-place, on LHS.
3020 // results in a mask of '-1' for the 'truth' value. Ensure that we negate 1 in handleCompareOpForVectorHelper()
3021 // to -1 to make sure that we produce the correct value. in handleCompareOpForVectorHelper()
3047 const auto *VT = E->getType()->castAs<VectorType>(); in handleVectorVectorBinOp()
3048 unsigned NumElements = VT->getNumElements(); in handleVectorVectorBinOp()
3049 QualType EltTy = VT->getElementType(); in handleVectorVectorBinOp()
3070 if (EltTy->isIntegerType()) { in handleVectorVectorBinOp()
3072 EltTy->isUnsignedIntegerType()}; in handleVectorVectorBinOp()
3089 } else if (EltTy->isFloatingType()) { in handleVectorVectorBinOp()
3124 // Truncate the path to the subobject, and remove any derived-to-base offsets. in CastToDerivedClass()
3127 if (RD->isInvalidDecl()) return false; in CastToDerivedClass()
3131 Result.Offset -= Layout.getVBaseClassOffset(Base); in CastToDerivedClass()
3133 Result.Offset -= Layout.getBaseClassOffset(Base); in CastToDerivedClass()
3145 if (Derived->isInvalidDecl()) return false; in HandleLValueDirectBase()
3149 Obj.getLValueOffset() += RL->getBaseClassOffset(Base); in HandleLValueDirectBase()
3157 const CXXRecordDecl *BaseDecl = Base->getType()->getAsCXXRecordDecl(); in HandleLValueBase()
3159 if (!Base->isVirtual()) in HandleLValueBase()
3166 // Extract most-derived object and corresponding type. in HandleLValueBase()
3167 DerivedDecl = D.MostDerivedType->getAsCXXRecordDecl(); in HandleLValueBase()
3172 if (DerivedDecl->isInvalidDecl()) return false; in HandleLValueBase()
3181 for (CastExpr::path_const_iterator PathI = E->path_begin(), in HandleLValueBasePath()
3182 PathE = E->path_end(); in HandleLValueBasePath()
3184 if (!HandleLValueBase(Info, E, Result, Type->getAsCXXRecordDecl(), in HandleLValueBasePath()
3187 Type = (*PathI)->getType(); in HandleLValueBasePath()
3198 if (!DerivedRD->isDerivedFrom(BaseRD, Paths)) in CastToBaseClass()
3213 if (FD->getParent()->isInvalidDecl()) return false; in HandleLValueMember()
3214 RL = &Info.Ctx.getASTRecordLayout(FD->getParent()); in HandleLValueMember()
3217 unsigned I = FD->getFieldIndex(); in HandleLValueMember()
3218 LVal.adjustOffset(Info.Ctx.toCharUnitsFromBits(RL->getFieldOffset(I))); in HandleLValueMember()
3227 for (const auto *C : IFD->chain()) in HandleLValueIndirectMember()
3243 if (Type->isVoidType() || Type->isFunctionType()) { in HandleSizeof()
3248 if (Type->isDependentType()) { in HandleSizeof()
3253 if (!Type->isConstantSizeType()) { in HandleSizeof()
3268 /// \param Info - Information about the ongoing evaluation.
3269 /// \param E - The expression being evaluated, for diagnostic purposes.
3270 /// \param LVal - The pointer value to be updated.
3271 /// \param EltTy - The pointee type represented by LVal.
3272 /// \param Adjustment - The adjustment, in objects of type EltTy, to add.
3277 if (!HandleSizeof(Info, E->getExprLoc(), EltTy, SizeOfPointee)) in HandleLValueArrayAdjustment()
3292 /// \param Info - Information about the ongoing evaluation.
3293 /// \param LVal - The lvalue to be updated.
3294 /// \param EltTy - The complex number's component type.
3295 /// \param Imag - False for the real component, true for the imaginary.
3301 if (!HandleSizeof(Info, E->getExprLoc(), EltTy, SizeOfComponent)) in HandleLValueComplexElement()
3321 APValue::LValueBase Base(VD, Frame ? Frame->Index : 0, Version); in evaluateVarDeclInit()
3325 Result = Frame->getTemporary(VD, Version); in evaluateVarDeclInit()
3334 assert(isLambdaCallOperator(Frame->Callee) && in evaluateVarDeclInit()
3335 (VD->getDeclContext() != Frame->Callee || VD->isInitCapture()) && in evaluateVarDeclInit()
3341 Info.FFDiag(E->getBeginLoc(), in evaluateVarDeclInit()
3349 // in-flight value. in evaluateVarDeclInit()
3359 !Info.CurrentCall->Callee || in evaluateVarDeclInit()
3360 !Info.CurrentCall->Callee->Equals(VD->getDeclContext())) { in evaluateVarDeclInit()
3372 if (E->isValueDependent()) in evaluateVarDeclInit()
3378 const Expr *Init = VD->getAnyInitializer(VD); in evaluateVarDeclInit()
3390 if (Init->isValueDependent()) { in evaluateVarDeclInit()
3391 // The DeclRefExpr is not value-dependent, but the variable it refers to in evaluateVarDeclInit()
3392 // has a value-dependent initializer. This should only happen in in evaluateVarDeclInit()
3393 // constant-folding cases, where the variable is not actually of a suitable in evaluateVarDeclInit()
3395 // have been value-dependent too), so diagnose that. in evaluateVarDeclInit()
3396 assert(!VD->mightBeUsableInConstantExpressions(Info.Ctx)); in evaluateVarDeclInit()
3401 << VD << VD->getType(); in evaluateVarDeclInit()
3409 if (!VD->evaluateValue()) { in evaluateVarDeclInit()
3416 // const integral variable or a reference, we might have a non-constant in evaluateVarDeclInit()
3424 if ((Info.getLangOpts().CPlusPlus && !VD->hasConstantInitialization() && in evaluateVarDeclInit()
3425 VD->mightBeUsableInConstantExpressions(Info.Ctx)) || in evaluateVarDeclInit()
3427 !Info.getLangOpts().CPlusPlus11 && !VD->hasICEInitializer(Info.Ctx))) { in evaluateVarDeclInit()
3434 if (VD->isWeak()) { in evaluateVarDeclInit()
3440 Result = VD->getEvaluatedValue(); in evaluateVarDeclInit()
3448 Base = Base->getCanonicalDecl(); in getBaseIndex()
3450 for (CXXRecordDecl::base_class_const_iterator I = Derived->bases_begin(), in getBaseIndex()
3451 E = Derived->bases_end(); I != E; ++I, ++Index) { in getBaseIndex()
3452 if (I->getType()->getAsCXXRecordDecl()->getCanonicalDecl() == Base) in getBaseIndex()
3468 Info.Ctx.getObjCEncodingForType(ObjCEnc->getEncodedType(), Str); in extractStringLiteralCharacter()
3474 Lit = PE->getFunctionName(); in extractStringLiteralCharacter()
3477 Info.Ctx.getAsConstantArrayType(S->getType()); in extractStringLiteralCharacter()
3479 QualType CharType = CAT->getElementType(); in extractStringLiteralCharacter()
3480 assert(CharType->isIntegerType() && "unexpected character type"); in extractStringLiteralCharacter()
3482 CharType->isUnsignedIntegerType()); in extractStringLiteralCharacter()
3483 if (Index < S->getLength()) in extractStringLiteralCharacter()
3484 Value = S->getCodeUnit(Index); in extractStringLiteralCharacter()
3496 AllocType.isNull() ? S->getType() : AllocType); in expandStringLiteral()
3498 QualType CharType = CAT->getElementType(); in expandStringLiteral()
3499 assert(CharType->isIntegerType() && "unexpected character type"); in expandStringLiteral()
3501 unsigned Elts = CAT->getZExtSize(); in expandStringLiteral()
3503 std::min(S->getLength(), Elts), Elts); in expandStringLiteral()
3505 CharType->isUnsignedIntegerType()); in expandStringLiteral()
3509 Value = S->getCodeUnit(I); in expandStringLiteral()
3535 /// Determine whether a type would actually be read by an lvalue-to-rvalue
3539 /// a non-class type.
3542 CXXRecordDecl *RD = T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl(); in isReadByLvalueToRvalueConversion()
3548 if (RD->isUnion()) in isReadByLvalueToRvalueConversion()
3549 return !RD->field_empty(); in isReadByLvalueToRvalueConversion()
3550 if (RD->isEmpty()) in isReadByLvalueToRvalueConversion()
3553 for (auto *Field : RD->fields()) in isReadByLvalueToRvalueConversion()
3554 if (!Field->isUnnamedBitField() && in isReadByLvalueToRvalueConversion()
3555 isReadByLvalueToRvalueConversion(Field->getType())) in isReadByLvalueToRvalueConversion()
3558 for (auto &BaseSpec : RD->bases()) in isReadByLvalueToRvalueConversion()
3569 CXXRecordDecl *RD = T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl(); in diagnoseMutableFields()
3573 if (!RD->hasMutableFields()) in diagnoseMutableFields()
3576 for (auto *Field : RD->fields()) { in diagnoseMutableFields()
3581 if (Field->isMutable() && in diagnoseMutableFields()
3582 (RD->isUnion() || isReadByLvalueToRvalueConversion(Field->getType()))) { in diagnoseMutableFields()
3584 Info.Note(Field->getLocation(), diag::note_declared_at); in diagnoseMutableFields()
3588 if (diagnoseMutableFields(Info, E, AK, Field->getType())) in diagnoseMutableFields()
3592 for (auto &BaseSpec : RD->bases()) in diagnoseMutableFields()
3616 // A temporary lifetime-extended by the variable whose initializer we're in lifetimeStartedInEvaluation()
3620 return Info.EvaluatingDecl == BaseMTE->getExtendingDecl(); in lifetimeStartedInEvaluation()
3625 // [during constant destruction] the lifetime of a and its non-mutable in lifetimeStartedInEvaluation()
3630 // FIXME: We can meaningfully extend this to cover non-const objects, but in lifetimeStartedInEvaluation()
3634 return T.isConstQualified() || T->isReferenceType(); in lifetimeStartedInEvaluation()
3643 CAT->getSizeExpr() ? CAT->getSizeExpr()->getBeginLoc() : CallLoc,
3644 CAT->getNumAddressingBits(Info.Ctx), CAT->getZExtSize(),
3686 // - A const object is an object of type const T or a non-mutable subobject in getSubobjectType()
3690 // - A volatile object is an object of type const T or a subobject of a in getSubobjectType()
3697 /// Find the designated sub-object of an rvalue.
3724 if ((O->isAbsent() && !(handler.AccessKind == AK_Construct && I == N)) || in findSubobject()
3725 (O->isIndeterminate() && in findSubobject()
3729 << handler.AccessKind << O->isIndeterminate() in findSubobject()
3730 << E->getSourceRange(); in findSubobject()
3738 ObjType->isRecordType() && in findSubobject()
3749 if (I == N || (I == N - 1 && ObjType->isAnyComplexType())) { in findSubobject()
3758 Loc = VolatileField->getLocation(); in findSubobject()
3762 Loc = VD->getLocation(); in findSubobject()
3767 Loc = E->getExprLoc(); in findSubobject()
3782 if (ObjType->isRecordType() && in findSubobject()
3792 // If we modified a bit-field, truncate it to the right width. in findSubobject()
3794 LastField && LastField->isBitField() && in findSubobject()
3802 if (ObjType->isArrayType()) { in findSubobject()
3807 if (CAT->getSize().ule(Index)) { in findSubobject()
3818 ObjType = CAT->getElementType(); in findSubobject()
3820 if (O->getArrayInitializedElts() > Index) in findSubobject()
3821 O = &O->getArrayInitializedElt(Index); in findSubobject()
3823 if (!CheckArraySize(Info, CAT, E->getExprLoc())) in findSubobject()
3827 O = &O->getArrayInitializedElt(Index); in findSubobject()
3829 O = &O->getArrayFiller(); in findSubobject()
3830 } else if (ObjType->isAnyComplexType()) { in findSubobject()
3843 ObjType, ObjType->castAs<ComplexType>()->getElementType()); in findSubobject()
3845 assert(I == N - 1 && "extracting subobject of scalar?"); in findSubobject()
3846 if (O->isComplexInt()) { in findSubobject()
3847 return handler.found(Index ? O->getComplexIntImag() in findSubobject()
3848 : O->getComplexIntReal(), ObjType); in findSubobject()
3850 assert(O->isComplexFloat()); in findSubobject()
3851 return handler.found(Index ? O->getComplexFloatImag() in findSubobject()
3852 : O->getComplexFloatReal(), ObjType); in findSubobject()
3855 if (Field->isMutable() && in findSubobject()
3859 Info.Note(Field->getLocation(), diag::note_declared_at); in findSubobject()
3864 RecordDecl *RD = ObjType->castAs<RecordType>()->getDecl(); in findSubobject()
3865 if (RD->isUnion()) { in findSubobject()
3866 const FieldDecl *UnionField = O->getUnionField(); in findSubobject()
3868 UnionField->getCanonicalDecl() != Field->getCanonicalDecl()) { in findSubobject()
3869 if (I == N - 1 && handler.AccessKind == AK_Construct) { in findSubobject()
3871 O->setUnion(Field, APValue()); in findSubobject()
3873 // FIXME: If O->getUnionValue() is absent, report that there's no in findSubobject()
3882 O = &O->getUnionValue(); in findSubobject()
3884 O = &O->getStructField(Field->getFieldIndex()); in findSubobject()
3886 ObjType = getSubobjectType(ObjType, Field->getType(), Field->isMutable()); in findSubobject()
3888 if (Field->getType().isVolatileQualified()) in findSubobject()
3892 const CXXRecordDecl *Derived = ObjType->getAsCXXRecordDecl(); in findSubobject()
3894 O = &O->getStructBase(getBaseIndex(Derived, Base)); in findSubobject()
3914 return CheckFullyInitialized(Info, E->getExprLoc(), SubobjType, Result); in found()
3927 /// Extract the designated sub-object of an rvalue.
3985 /// Update the designated sub-object of an rvalue to the given value.
4003 (ObjType->isArrayType() || ObjType->isAnyComplexType())) { in FindDesignatorMismatch()
4009 if (ObjType->isAnyComplexType()) in FindDesignatorMismatch()
4010 ObjType = ObjType->castAs<ComplexType>()->getElementType(); in FindDesignatorMismatch()
4012 ObjType = ObjType->castAsArrayTypeUnsafe()->getElementType(); in FindDesignatorMismatch()
4021 ObjType = FD->getType(); in FindDesignatorMismatch()
4049 return CommonLength >= A.Entries.size() - IsArray; in AreElementsOfSameArray()
4081 // C++11 DR1311: An lvalue-to-rvalue conversion on a volatile-qualified type in findCompleteObject()
4082 // is not a constant expression (even if the object is non-volatile). We also in findCompleteObject()
4111 APValue &V = GD->getAsAPValue(); in findCompleteObject()
4114 << GD->getType(); in findCompleteObject()
4117 return CompleteObject(LVal.Base, &V, GD->getType()); in findCompleteObject()
4126 return CompleteObject(LVal.Base, const_cast<APValue *>(&GCD->getValue()), in findCompleteObject()
4127 GCD->getType()); in findCompleteObject()
4136 return CompleteObject(LVal.Base, const_cast<APValue *>(&TPO->getValue()), in findCompleteObject()
4137 TPO->getType()); in findCompleteObject()
4140 // In C++98, const, non-volatile integers initialized with ICEs are ICEs. in findCompleteObject()
4141 // In C++11, constexpr, non-volatile variables initialized with constant in findCompleteObject()
4143 // parameters are constant expressions even if they're non-const. in findCompleteObject()
4149 if (const VarDecl *VDef = VD->getDefinition(Info.Ctx)) in findCompleteObject()
4152 if (!VD || VD->isInvalidDecl()) { in findCompleteObject()
4161 ConstexprVar = VD->isConstexpr(); in findCompleteObject()
4179 } else if (VD->isConstexpr()) { in findCompleteObject()
4184 } else if (BaseType->isIntegralOrEnumerationType()) { in findCompleteObject()
4190 Info.Note(VD->getLocation(), diag::note_declared_at); in findCompleteObject()
4199 BaseType->isLiteralType(Info.Ctx) && !VD->hasDefinition()) { in findCompleteObject()
4203 // folding of const floating-point types, in order to make static const in findCompleteObject()
4210 Info.Note(VD->getLocation(), diag::note_declared_at); in findCompleteObject()
4215 // Never allow reading a non-const value. in findCompleteObject()
4221 Info.Note(VD->getLocation(), diag::note_declared_at); in findCompleteObject()
4237 return CompleteObject(LVal.Base, &(*Alloc)->Value, in findCompleteObject()
4245 assert(MTE->getStorageDuration() == SD_Static && in findCompleteObject()
4246 "should have a frame for a non-global materialized temporary"); in findCompleteObject()
4250 // - a temporary object of non-volatile const-qualified literal type in findCompleteObject()
4255 // an lvalue-to-rvalue conversion [is not allowed unless it applies to] in findCompleteObject()
4256 // - a non-volatile glvalue that refers to an object that is usable in findCompleteObject()
4258 // - a non-volatile glvalue of literal type that refers to a in findCompleteObject()
4259 // non-volatile object whose lifetime began within the evaluation in findCompleteObject()
4267 // Therefore we use the C++14-onwards rules in C++11 too. in findCompleteObject()
4271 // corresponding destructor, not even if they're of const-qualified in findCompleteObject()
4273 if (!MTE->isUsableInConstantExpressions(Info.Ctx) && in findCompleteObject()
4278 Info.Note(MTE->getExprLoc(), diag::note_constexpr_temporary_here); in findCompleteObject()
4282 BaseVal = MTE->getOrCreateValue(false); in findCompleteObject()
4297 BaseVal = Frame->getTemporary(Base, LVal.Base.getVersion()); in findCompleteObject()
4305 // modified in a speculatively-evaluated call. in findCompleteObject()
4321 /// Perform an lvalue-to-rvalue conversion on the given glvalue. This
4322 /// can also be used for 'lvalue-to-lvalue' conversions for looking up the
4325 /// \param Info - Information about the ongoing evaluation.
4326 /// \param Conv - The expression for which we are performing the conversion.
4328 /// \param Type - The type of the glvalue (before stripping cv-qualifiers in the
4329 /// case of a non-class type).
4330 /// \param LVal - The glvalue on which we are attempting to perform this action.
4331 /// \param RVal - The produced value will be placed here.
4332 /// \param WantObjectRepresentation - If true, we're looking for the object
4359 if (!Evaluate(Lit, Info, CLE->getInitializer())) in handleLValueToRValueConversion()
4368 // const-qualified type. If foo and its initializer had elements of type in handleLValueToRValueConversion()
4375 QualType CLETy = CLE->getType(); in handleLValueToRValueConversion()
4376 if (CLETy->isArrayType() && !Type->isArrayType()) { in handleLValueToRValueConversion()
4379 Info.Note(CLE->getExprLoc(), diag::note_declared_at); in handleLValueToRValueConversion()
4384 CompleteObject LitObj(LVal.Base, &Lit, Base->getType()); in handleLValueToRValueConversion()
4387 // Special-case character extraction so we don't have to construct an in handleLValueToRValueConversion()
4470 << E->getLHS()->getSourceRange(); in found()
4483 if (!SubobjType->isVectorType()) { in foundVector()
4494 if (!SubobjType->isIntegerType()) { in found()
4495 // We don't support compound assignment on integer-cast-to-pointer in found()
4509 const FPOptions FPO = E->getFPFeaturesInEffect( in found()
4534 if (const PointerType *PT = SubobjType->getAs<PointerType>()) in foundPointer()
4535 PointeeType = PT->getPointeeType(); in foundPointer()
4601 // if we're post-incrementing a complex. in found()
4614 SubobjType->castAs<ComplexType>()->getElementType() in found()
4618 SubobjType->castAs<ComplexType>()->getElementType() in found()
4632 if (!SubobjType->isIntegerType()) { in found()
4633 // We don't support increment / decrement on integer-cast-to-pointer in found()
4642 // doesn't reduce mod 2^n, so special-case it. in found()
4643 if (SubobjType->isBooleanType()) { in found()
4655 if (!WasNegative && Value.isNegative() && E->canOverflow()) { in found()
4660 --Value; in found()
4662 if (WasNegative && !Value.isNegative() && E->canOverflow()) { in found()
4691 if (const PointerType *PT = SubobjType->getAs<PointerType>()) in foundPointer()
4692 PointeeType = PT->getPointeeType(); in foundPointer()
4701 AccessKind == AK_Increment ? 1 : -1)) in foundPointer()
4729 if (Object->getType()->isPointerType() && Object->isPRValue()) in EvaluateObjectArgument()
4732 if (Object->isGLValue()) in EvaluateObjectArgument()
4735 if (Object->getType()->isLiteralType(Info.Ctx)) in EvaluateObjectArgument()
4738 if (Object->getType()->isRecordType() && Object->isPRValue()) in EvaluateObjectArgument()
4741 Info.FFDiag(Object, diag::note_constexpr_nonliteral) << Object->getType(); in EvaluateObjectArgument()
4745 /// HandleMemberPointerAccess - Evaluate a member access operation and build an
4748 /// \param Info - Information about the ongoing evaluation.
4749 /// \param LV - An lvalue referring to the base of the member pointer.
4750 /// \param RHS - The member pointer expression.
4751 /// \param IncludeMember - Specifies whether the member itself is included in
4775 // The end of the derived-to-base path for the base object must match the in HandleMemberPointerAccess()
4776 // derived-to-base path for the member pointer. in HandleMemberPointerAccess()
4783 LV.Designator.Entries.size() - MemPtr.Path.size(); in HandleMemberPointerAccess()
4788 if (LVDecl->getCanonicalDecl() != MPDecl->getCanonicalDecl()) { in HandleMemberPointerAccess()
4804 if (const PointerType *PT = LVType->getAs<PointerType>()) in HandleMemberPointerAccess()
4805 LVType = PT->getPointeeType(); in HandleMemberPointerAccess()
4806 const CXXRecordDecl *RD = LVType->getAsCXXRecordDecl(); in HandleMemberPointerAccess()
4807 assert(RD && "member pointer access on non-class-type expression"); in HandleMemberPointerAccess()
4810 const CXXRecordDecl *Base = MemPtr.Path[N - I - 1]; in HandleMemberPointerAccess()
4842 assert(BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI); in HandleMemberPointerAccess()
4844 if (!EvaluateObjectArgument(Info, BO->getLHS(), LV)) { in HandleMemberPointerAccess()
4847 EvaluateMemberPointer(BO->getRHS(), MemPtr, Info); in HandleMemberPointerAccess()
4852 return HandleMemberPointerAccess(Info, BO->getLHS()->getType(), LV, in HandleMemberPointerAccess()
4853 BO->getRHS(), IncludeMember); in HandleMemberPointerAccess()
4856 /// HandleBaseToDerivedCast - Apply the given base-to-derived cast operation on
4864 QualType TargetQT = E->getType(); in HandleBaseToDerivedCast()
4865 if (const PointerType *PT = TargetQT->getAs<PointerType>()) in HandleBaseToDerivedCast()
4866 TargetQT = PT->getPointeeType(); in HandleBaseToDerivedCast()
4868 // Check this cast lands within the final derived-to-base subobject path. in HandleBaseToDerivedCast()
4869 if (D.MostDerivedPathLength + E->path_size() > D.Entries.size()) { in HandleBaseToDerivedCast()
4877 unsigned NewEntriesSize = D.Entries.size() - E->path_size(); in HandleBaseToDerivedCast()
4878 const CXXRecordDecl *TargetType = TargetQT->getAsCXXRecordDecl(); in HandleBaseToDerivedCast()
4881 FinalType = D.MostDerivedType->getAsCXXRecordDecl(); in HandleBaseToDerivedCast()
4883 FinalType = getAsBaseClass(D.Entries[NewEntriesSize - 1]); in HandleBaseToDerivedCast()
4884 if (FinalType->getCanonicalDecl() != TargetType->getCanonicalDecl()) { in HandleBaseToDerivedCast()
4894 /// Get the value to use for a default-initialized object of type T.
4903 if (auto *RD = T->getAsCXXRecordDecl()) { in handleDefaultInitValue()
4904 if (RD->isInvalidDecl()) { in handleDefaultInitValue()
4908 if (RD->isUnion()) { in handleDefaultInitValue()
4912 Result = APValue(APValue::UninitStruct(), RD->getNumBases(), in handleDefaultInitValue()
4913 std::distance(RD->field_begin(), RD->field_end())); in handleDefaultInitValue()
4916 for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(), in handleDefaultInitValue()
4917 End = RD->bases_end(); in handleDefaultInitValue()
4920 handleDefaultInitValue(I->getType(), Result.getStructBase(Index)); in handleDefaultInitValue()
4922 for (const auto *I : RD->fields()) { in handleDefaultInitValue()
4923 if (I->isUnnamedBitField()) in handleDefaultInitValue()
4926 I->getType(), Result.getStructField(I->getFieldIndex())); in handleDefaultInitValue()
4932 dyn_cast_or_null<ConstantArrayType>(T->getAsArrayTypeUnsafe())) { in handleDefaultInitValue()
4933 Result = APValue(APValue::UninitArray(), 0, AT->getZExtSize()); in handleDefaultInitValue()
4936 handleDefaultInitValue(AT->getElementType(), Result.getArrayFiller()); in handleDefaultInitValue()
4963 if (VD->isInvalidDecl()) in EvaluateVarDecl()
4966 if (!VD->hasLocalStorage()) in EvaluateVarDecl()
4970 APValue &Val = Info.CurrentCall->createTemporary(VD, VD->getType(), in EvaluateVarDecl()
4973 const Expr *InitE = VD->getInit(); in EvaluateVarDecl()
4975 if (VD->getType()->isDependentType()) in EvaluateVarDecl()
4977 return handleDefaultInitValue(VD->getType(), Val); in EvaluateVarDecl()
4979 if (InitE->isValueDependent()) in EvaluateVarDecl()
4983 // Wipe out any partially-computed value, to allow tracking that this in EvaluateVarDecl()
4999 for (auto *BD : DD->bindings()) in EvaluateDecl()
5000 if (auto *VD = BD->getHoldingVar()) in EvaluateDecl()
5007 assert(E->isValueDependent()); in EvaluateDependentExpr()
5010 assert(E->containsErrors() && "valid value-dependent expression should never " in EvaluateDependentExpr()
5018 if (Cond->isValueDependent()) in EvaluateCond()
5088 if (const Stmt *Init = SS->getInit()) { in EvaluateSwitch()
5098 if (SS->getConditionVariable() && in EvaluateSwitch()
5099 !EvaluateDecl(Info, SS->getConditionVariable())) in EvaluateSwitch()
5101 if (SS->getCond()->isValueDependent()) { in EvaluateSwitch()
5103 EvaluateDependentExpr(SS->getCond(), Info); in EvaluateSwitch()
5106 if (!EvaluateInteger(SS->getCond(), Value, Info)) in EvaluateSwitch()
5116 for (const SwitchCase *SC = SS->getSwitchCaseList(); SC; in EvaluateSwitch()
5117 SC = SC->getNextSwitchCase()) { in EvaluateSwitch()
5124 APSInt LHS = CS->getLHS()->EvaluateKnownConstInt(Info.Ctx); in EvaluateSwitch()
5125 APSInt RHS = CS->getRHS() ? CS->getRHS()->EvaluateKnownConstInt(Info.Ctx) in EvaluateSwitch()
5137 EvalStmtResult ESR = EvaluateStmt(Result, Info, SS->getBody(), Found); in EvaluateSwitch()
5152 Info.FFDiag(Found->getBeginLoc(), in EvaluateSwitch()
5161 // would evaluate one of the following: [C++23] - a control flow that passes in CheckLocalVariableDeclaration()
5164 if (VD->isLocalVarDecl() && VD->isStaticLocal() && in CheckLocalVariableDeclaration()
5165 !VD->isUsableInConstantExpressions(Info.Ctx)) { in CheckLocalVariableDeclaration()
5166 Info.CCEDiag(VD->getLocation(), diag::note_constexpr_static_local) in CheckLocalVariableDeclaration()
5167 << (VD->getTSCSpec() == TSCS_unspecified ? 0 : 1) << VD; in CheckLocalVariableDeclaration()
5182 switch (S->getStmtClass()) { in EvaluateStmt()
5209 if (const Stmt *Init = IS->getInit()) { in EvaluateStmt()
5222 EvalStmtResult ESR = EvaluateStmt(Result, Info, IS->getThen(), Case); in EvaluateStmt()
5227 if (!IS->getElse()) in EvaluateStmt()
5230 ESR = EvaluateStmt(Result, Info, IS->getElse(), Case); in EvaluateStmt()
5240 EvaluateLoopBody(Result, Info, cast<WhileStmt>(S)->getBody(), Case); in EvaluateStmt()
5252 if (const Stmt *Init = FS->getInit()) { in EvaluateStmt()
5261 EvaluateLoopBody(Result, Info, FS->getBody(), Case); in EvaluateStmt()
5264 if (const auto *Inc = FS->getInc()) { in EvaluateStmt()
5265 if (Inc->isValueDependent()) { in EvaluateStmt()
5281 for (const auto *D : DS->decls()) { in EvaluateStmt()
5285 if (VD->hasLocalStorage() && !VD->getInit()) in EvaluateStmt()
5289 // over, bail out of any immediately-surrounding compound-statement in EvaluateStmt()
5301 switch (S->getStmtClass()) { in EvaluateStmt()
5304 if (E->isValueDependent()) { in EvaluateStmt()
5308 // Don't bother evaluating beyond an expression-statement which couldn't in EvaluateStmt()
5319 Info.FFDiag(S->getBeginLoc()) << S->getSourceRange(); in EvaluateStmt()
5327 for (const auto *D : DS->decls()) { in EvaluateStmt()
5331 // Each declaration initialization is its own full-expression. in EvaluateStmt()
5342 const Expr *RetExpr = cast<ReturnStmt>(S)->getRetValue(); in EvaluateStmt()
5344 if (RetExpr && RetExpr->isValueDependent()) { in EvaluateStmt()
5361 for (const auto *BI : CS->body()) { in EvaluateStmt()
5381 if (const Stmt *Init = IS->getInit()) { in EvaluateStmt()
5390 if (IS->isConsteval()) { in EvaluateStmt()
5391 Cond = IS->isNonNegatedConsteval(); in EvaluateStmt()
5396 } else if (!EvaluateCond(Info, IS->getConditionVariable(), IS->getCond(), in EvaluateStmt()
5400 if (const Stmt *SubStmt = Cond ? IS->getThen() : IS->getElse()) { in EvaluateStmt()
5416 if (!EvaluateCond(Info, WS->getConditionVariable(), WS->getCond(), in EvaluateStmt()
5422 EvalStmtResult ESR = EvaluateLoopBody(Result, Info, WS->getBody()); in EvaluateStmt()
5438 EvalStmtResult ESR = EvaluateLoopBody(Result, Info, DS->getBody(), Case); in EvaluateStmt()
5443 if (DS->getCond()->isValueDependent()) { in EvaluateStmt()
5444 EvaluateDependentExpr(DS->getCond(), Info); in EvaluateStmt()
5449 if (!EvaluateAsBooleanCondition(DS->getCond(), Continue, Info) || in EvaluateStmt()
5459 if (FS->getInit()) { in EvaluateStmt()
5460 EvalStmtResult ESR = EvaluateStmt(Result, Info, FS->getInit()); in EvaluateStmt()
5470 if (FS->getCond() && !EvaluateCond(Info, FS->getConditionVariable(), in EvaluateStmt()
5471 FS->getCond(), Continue)) in EvaluateStmt()
5476 EvalStmtResult ESR = EvaluateLoopBody(Result, Info, FS->getBody()); in EvaluateStmt()
5483 if (const auto *Inc = FS->getInc()) { in EvaluateStmt()
5484 if (Inc->isValueDependent()) { in EvaluateStmt()
5504 // Evaluate the init-statement if present. in EvaluateStmt()
5505 if (FS->getInit()) { in EvaluateStmt()
5506 EvalStmtResult ESR = EvaluateStmt(Result, Info, FS->getInit()); in EvaluateStmt()
5515 EvalStmtResult ESR = EvaluateStmt(Result, Info, FS->getRangeStmt()); in EvaluateStmt()
5522 // In error-recovery cases it's possible to get here even if we failed to in EvaluateStmt()
5524 if (!FS->getBeginStmt() || !FS->getEndStmt() || !FS->getCond()) in EvaluateStmt()
5528 ESR = EvaluateStmt(Result, Info, FS->getBeginStmt()); in EvaluateStmt()
5534 ESR = EvaluateStmt(Result, Info, FS->getEndStmt()); in EvaluateStmt()
5544 if (FS->getCond()->isValueDependent()) { in EvaluateStmt()
5545 EvaluateDependentExpr(FS->getCond(), Info); in EvaluateStmt()
5551 if (!EvaluateAsBooleanCondition(FS->getCond(), Continue, Info)) in EvaluateStmt()
5559 ESR = EvaluateStmt(Result, Info, FS->getLoopVarStmt()); in EvaluateStmt()
5567 ESR = EvaluateLoopBody(Result, Info, FS->getBody()); in EvaluateStmt()
5573 if (FS->getInc()->isValueDependent()) { in EvaluateStmt()
5574 if (!EvaluateDependentExpr(FS->getInc(), Info)) in EvaluateStmt()
5578 if (!EvaluateIgnoredValue(Info, FS->getInc())) in EvaluateStmt()
5599 return EvaluateStmt(Result, Info, cast<LabelStmt>(S)->getSubStmt(), Case); in EvaluateStmt()
5603 const auto *SS = AS->getSubStmt(); in EvaluateStmt()
5605 *Info.CurrentCall, hasSpecificAttr<MSConstexprAttr>(AS->getAttrs()) && in EvaluateStmt()
5610 for (auto *Attr : AS->getAttrs()) { in EvaluateStmt()
5615 auto *Assumption = AA->getAssumption(); in EvaluateStmt()
5616 if (Assumption->isValueDependent()) in EvaluateStmt()
5619 if (Assumption->HasSideEffects(Info.getCtx())) in EvaluateStmt()
5626 Info.CCEDiag(Assumption->getExprLoc(), in EvaluateStmt()
5638 return EvaluateStmt(Result, Info, cast<SwitchCase>(S)->getSubStmt(), Case); in EvaluateStmt()
5641 return EvaluateStmt(Result, Info, cast<CXXTryStmt>(S)->getTryBlock(), Case); in EvaluateStmt()
5645 /// CheckTrivialDefaultConstructor - Check whether a constructor is a trivial
5652 if (!CD->isTrivial() || !CD->isDefaultConstructor()) in CheckTrivialDefaultConstructor()
5655 // Value-initialization does not call a trivial default constructor, so such a in CheckTrivialDefaultConstructor()
5658 if (!CD->isConstexpr() && !IsValueInitialization) { in CheckTrivialDefaultConstructor()
5660 // FIXME: If DiagDecl is an implicitly-declared special member function, in CheckTrivialDefaultConstructor()
5664 Info.Note(CD->getLocation(), diag::note_declared_at); in CheckTrivialDefaultConstructor()
5672 /// CheckConstexprFunction - Check that a function can be called in a constant
5681 Declaration->isConstexpr()) in CheckConstexprFunction()
5686 // note the problematic sub-expression. in CheckConstexprFunction()
5687 if (Declaration->isInvalidDecl()) { in CheckConstexprFunction()
5693 // constant expression (prior to C++20). We can still constant-fold such a in CheckConstexprFunction()
5696 cast<CXXMethodDecl>(Declaration)->isVirtual()) in CheckConstexprFunction()
5699 if (Definition && Definition->isInvalidDecl()) { in CheckConstexprFunction()
5706 (Definition->isConstexpr() || (Info.CurrentCall->CanEvalMSConstexpr && in CheckConstexprFunction()
5707 Definition->hasAttr<MSConstexprAttr>()))) in CheckConstexprFunction()
5714 // non-constexpr constructor, diagnose that directly. in CheckConstexprFunction()
5716 if (CD && CD->isInheritingConstructor()) { in CheckConstexprFunction()
5717 auto *Inherited = CD->getInheritedConstructor().getConstructor(); in CheckConstexprFunction()
5718 if (!Inherited->isConstexpr()) in CheckConstexprFunction()
5722 // FIXME: If DiagDecl is an implicitly-declared special member function in CheckConstexprFunction()
5725 if (CD && CD->isInheritingConstructor()) in CheckConstexprFunction()
5727 << CD->getInheritedConstructor().getConstructor()->getParent(); in CheckConstexprFunction()
5730 << DiagDecl->isConstexpr() << (bool)CD << DiagDecl; in CheckConstexprFunction()
5731 Info.Note(DiagDecl->getLocation(), diag::note_declared_at); in CheckConstexprFunction()
5763 // its value to see if it's in-lifetime or what the active union members in checkDynamicType()
5764 // are. We can still check for a one-past-the-end lvalue. in checkDynamicType()
5813 ? Designator.MostDerivedType->getAsCXXRecordDecl() in getBaseClassType()
5814 : getAsBaseClass(Designator.Entries[PathLength - 1]); in getBaseClassType()
5823 // meaningful dynamic type. (We consider objects of non-class type to have no in ComputeDynamicType()
5829 // shouldn't happen other than in constant-folding situations, since literal in ComputeDynamicType()
5835 This.Designator.MostDerivedType->getAsCXXRecordDecl(); in ComputeDynamicType()
5836 if (!Class || Class->getNumVBases()) { in ComputeDynamicType()
5889 unsigned PathLength = DynType->PathLength; in HandleVirtualDispatch()
5893 Found->getCorrespondingMethodDeclaredInClass(Class, false); in HandleVirtualDispatch()
5903 if (Callee->isPureVirtual()) { in HandleVirtualDispatch()
5905 Info.Note(Callee->getLocation(), diag::note_declared_at); in HandleVirtualDispatch()
5911 if (!Info.Ctx.hasSameUnqualifiedType(Callee->getReturnType(), in HandleVirtualDispatch()
5912 Found->getReturnType())) { in HandleVirtualDispatch()
5913 CovariantAdjustmentPath.push_back(Callee->getReturnType()); in HandleVirtualDispatch()
5920 Found->getCorrespondingMethodDeclaredInClass(NextClass, false); in HandleVirtualDispatch()
5922 Next->getReturnType(), CovariantAdjustmentPath.back())) in HandleVirtualDispatch()
5923 CovariantAdjustmentPath.push_back(Next->getReturnType()); in HandleVirtualDispatch()
5925 if (!Info.Ctx.hasSameUnqualifiedType(Found->getReturnType(), in HandleVirtualDispatch()
5927 CovariantAdjustmentPath.push_back(Found->getReturnType()); in HandleVirtualDispatch()
5931 if (!CastToDerivedClass(Info, E, This, Callee->getParent(), PathLength)) in HandleVirtualDispatch()
5951 const CXXRecordDecl *OldClass = Path[0]->getPointeeCXXRecordDecl(); in HandleCovariantReturnAdjustment()
5953 const CXXRecordDecl *NewClass = Path[I]->getPointeeCXXRecordDecl(); in HandleCovariantReturnAdjustment()
5969 for (const CXXBaseSpecifier &BaseSpec : Derived->bases()) { in isBaseClassPublic()
5970 auto *BaseClass = BaseSpec.getType()->getAsCXXRecordDecl(); in isBaseClassPublic()
5983 // We can't do anything with a non-symbolic pointer value. in HandleDynamicCast()
5990 if (Ptr.isNullPointer() && !E->isGLValue()) in HandleDynamicCast()
6004 if (E->getType()->isVoidPointerType()) in HandleDynamicCast()
6005 return CastToDerivedClass(Info, E, Ptr, DynType->Type, DynType->PathLength); in HandleDynamicCast()
6007 const CXXRecordDecl *C = E->getTypeAsWritten()->getPointeeCXXRecordDecl(); in HandleDynamicCast()
6013 if (!E->isGLValue()) { in HandleDynamicCast()
6016 Ptr.setNull(Info.Ctx, E->getType()); in HandleDynamicCast()
6022 if (!Paths && (declaresSameEntity(DynType->Type, C) || in HandleDynamicCast()
6023 DynType->Type->isDerivedFrom(C))) in HandleDynamicCast()
6025 else if (!Paths || Paths->begin() == Paths->end()) in HandleDynamicCast()
6027 else if (Paths->isAmbiguous(CQT)) in HandleDynamicCast()
6030 assert(Paths->front().Access != AS_public && "why did the cast fail?"); in HandleDynamicCast()
6035 << Info.Ctx.getRecordType(DynType->Type) in HandleDynamicCast()
6036 << E->getType().getUnqualifiedType(); in HandleDynamicCast()
6044 PathLength >= (int)DynType->PathLength; --PathLength) { in HandleDynamicCast()
6049 if (PathLength > (int)DynType->PathLength && in HandleDynamicCast()
6050 !isBaseClassPublic(getBaseClassType(Ptr.Designator, PathLength - 1), in HandleDynamicCast()
6059 if (DynType->Type->isDerivedFrom(C, Paths) && !Paths.isAmbiguous(CQT) && in HandleDynamicCast()
6062 if (!CastToDerivedClass(Info, E, Ptr, DynType->Type, DynType->PathLength)) in HandleDynamicCast()
6091 // * All base, non-variant member, and array element subobjects' lifetimes in found()
6095 assert(SubobjType->isUnionType()); in found()
6097 // This union member is already active. If it's also in-lifetime, there's in found()
6110 Failed = !handleDefaultInitValue(Field->getType(), Result); in found()
6125 /// Handle a builtin simple-assignment or a call to a trivial assignment
6126 /// operator whose left-hand side might involve a union member access. If it
6140 // -- If E is of the form A.B, S(E) contains the elements of S(A)... in MaybeHandleUnionActiveMemberChange()
6142 auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl()); in MaybeHandleUnionActiveMemberChange()
6145 if (!FD || FD->getType()->isReferenceType()) in MaybeHandleUnionActiveMemberChange()
6149 if (FD->getParent()->isUnion()) { in MaybeHandleUnionActiveMemberChange()
6150 // ... of a non-class, non-array type, or of a class type with a in MaybeHandleUnionActiveMemberChange()
6154 FD->getType()->getBaseElementTypeUnsafe()->getAsCXXRecordDecl(); in MaybeHandleUnionActiveMemberChange()
6155 if (!RD || RD->hasTrivialDefaultConstructor()) in MaybeHandleUnionActiveMemberChange()
6156 UnionPathLengths.push_back({PathLength - 1, FD}); in MaybeHandleUnionActiveMemberChange()
6159 E = ME->getBase(); in MaybeHandleUnionActiveMemberChange()
6160 --PathLength; in MaybeHandleUnionActiveMemberChange()
6165 // -- If E is of the form A[B] and is interpreted as a built-in array in MaybeHandleUnionActiveMemberChange()
6169 auto *Base = ASE->getBase()->IgnoreImplicit(); in MaybeHandleUnionActiveMemberChange()
6170 if (!Base->getType()->isArrayType()) in MaybeHandleUnionActiveMemberChange()
6174 --PathLength; in MaybeHandleUnionActiveMemberChange()
6177 // Step over a derived-to-base conversion. in MaybeHandleUnionActiveMemberChange()
6178 E = ICE->getSubExpr(); in MaybeHandleUnionActiveMemberChange()
6179 if (ICE->getCastKind() == CK_NoOp) in MaybeHandleUnionActiveMemberChange()
6181 if (ICE->getCastKind() != CK_DerivedToBase && in MaybeHandleUnionActiveMemberChange()
6182 ICE->getCastKind() != CK_UncheckedDerivedToBase) in MaybeHandleUnionActiveMemberChange()
6185 for (const CXXBaseSpecifier *Elt : llvm::reverse(ICE->path())) { in MaybeHandleUnionActiveMemberChange()
6186 if (Elt->isVirtual()) { in MaybeHandleUnionActiveMemberChange()
6193 --PathLength; in MaybeHandleUnionActiveMemberChange()
6194 assert(declaresSameEntity(Elt->getType()->getAsCXXRecordDecl(), in MaybeHandleUnionActiveMemberChange()
6199 // -- Otherwise, S(E) is empty. in MaybeHandleUnionActiveMemberChange()
6212 findCompleteObject(Info, LHSExpr, AK_Assign, LHS, LHSExpr->getType()); in MaybeHandleUnionActiveMemberChange()
6241 APValue &V = PVD ? Info.CurrentCall->createParam(Call, PVD, LV) in EvaluateCallArg()
6242 : Info.CurrentCall->createTemporary(Arg, Arg->getType(), in EvaluateCallArg()
6248 // undefined behavior, so is non-constant. in EvaluateCallArg()
6263 if (Callee->hasAttr<NonNullAttr>()) { in EvaluateArgs()
6265 for (const auto *Attr : Callee->specific_attrs<NonNullAttr>()) { in EvaluateArgs()
6266 if (!Attr->args_size()) { in EvaluateArgs()
6270 for (auto Idx : Attr->args()) { in EvaluateArgs()
6279 unsigned Idx = RightToLeft ? Args.size() - I - 1 : I; in EvaluateArgs()
6281 Idx < Callee->getNumParams() ? Callee->getParamDecl(Idx) : nullptr; in EvaluateArgs()
6301 APValue *RefValue = Info.getParamSlot(Frame->Arguments, Param); in handleTrivialCopy()
6311 Info, E, Param->getType().getNonReferenceType(), RefLValue, Result, in handleTrivialCopy()
6324 CallStackFrame Frame(Info, E->getSourceRange(), Callee, This, E, Call); in HandleFunctionCall()
6330 // Skip this for non-union classes with no fields; in that case, the defaulted in HandleFunctionCall()
6333 if (MD && MD->isDefaulted() && in HandleFunctionCall()
6334 (MD->getParent()->isUnion() || in HandleFunctionCall()
6335 (MD->isTrivial() && in HandleFunctionCall()
6336 isReadByLvalueToRvalueConversion(MD->getParent())))) { in HandleFunctionCall()
6338 (MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())); in HandleFunctionCall()
6340 if (!handleTrivialCopy(Info, MD->getParamDecl(0), Args[0], RHSValue, in HandleFunctionCall()
6341 MD->getParent()->isUnion())) in HandleFunctionCall()
6343 if (!handleAssignment(Info, Args[0], *This, MD->getThisType(), in HandleFunctionCall()
6346 This->moveInto(Result); in HandleFunctionCall()
6352 // we're inferring constexpr-ness), so we don't have access to them in this in HandleFunctionCall()
6356 MD->getParent()->getCaptureFields(Frame.LambdaCaptureFields, in HandleFunctionCall()
6363 if (Callee->getReturnType()->isVoidType()) in HandleFunctionCall()
6365 Info.FFDiag(Callee->getEndLoc(), diag::note_constexpr_no_return); in HandleFunctionCall()
6375 SourceLocation CallLoc = E->getExprLoc(); in HandleConstructorCall()
6379 const CXXRecordDecl *RD = Definition->getParent(); in HandleConstructorCall()
6380 if (RD->getNumVBases()) { in HandleConstructorCall()
6388 RD->getNumBases()); in HandleConstructorCall()
6389 CallStackFrame Frame(Info, E->getSourceRange(), Definition, &This, E, Call); in HandleConstructorCall()
6397 if (Definition->isDelegatingConstructor()) { in HandleConstructorCall()
6398 CXXConstructorDecl::init_const_iterator I = Definition->init_begin(); in HandleConstructorCall()
6399 if ((*I)->getInit()->isValueDependent()) { in HandleConstructorCall()
6400 if (!EvaluateDependentExpr((*I)->getInit(), Info)) in HandleConstructorCall()
6404 if (!EvaluateInPlace(Result, Info, This, (*I)->getInit()) || in HandleConstructorCall()
6408 return EvaluateStmt(Ret, Info, Definition->getBody()) != ESR_Failed; in HandleConstructorCall()
6414 // ctor-initializers. in HandleConstructorCall()
6416 // Skip this for empty non-union classes; we should not perform an in HandleConstructorCall()
6417 // lvalue-to-rvalue conversion on them because their copy constructor does not in HandleConstructorCall()
6419 if (Definition->isDefaulted() && Definition->isCopyOrMoveConstructor() && in HandleConstructorCall()
6420 (Definition->getParent()->isUnion() || in HandleConstructorCall()
6421 (Definition->isTrivial() && in HandleConstructorCall()
6422 isReadByLvalueToRvalueConversion(Definition->getParent())))) { in HandleConstructorCall()
6423 return handleTrivialCopy(Info, Definition->getParamDecl(0), E, Result, in HandleConstructorCall()
6424 Definition->getParent()->isUnion()); in HandleConstructorCall()
6429 if (!RD->isUnion()) in HandleConstructorCall()
6430 Result = APValue(APValue::UninitStruct(), RD->getNumBases(), in HandleConstructorCall()
6431 std::distance(RD->field_begin(), RD->field_end())); in HandleConstructorCall()
6437 if (RD->isInvalidDecl()) return false; in HandleConstructorCall()
6440 // A scope for temporaries lifetime-extended by reference members. in HandleConstructorCall()
6446 CXXRecordDecl::base_class_const_iterator BaseIt = RD->bases_begin(); in HandleConstructorCall()
6448 CXXRecordDecl::field_iterator FieldIt = RD->field_begin(); in HandleConstructorCall()
6452 if (FieldIt == RD->field_end() || in HandleConstructorCall()
6453 FieldIt->getFieldIndex() > FD->getFieldIndex()) { in HandleConstructorCall()
6458 // Default-initialize any fields with no explicit initializer. in HandleConstructorCall()
6460 assert(FieldIt != RD->field_end() && "missing field?"); in HandleConstructorCall()
6461 if (!FieldIt->isUnnamedBitField()) in HandleConstructorCall()
6463 FieldIt->getType(), in HandleConstructorCall()
6464 Result.getStructField(FieldIt->getFieldIndex())); in HandleConstructorCall()
6468 for (const auto *I : Definition->inits()) { in HandleConstructorCall()
6475 if (I->isBaseInitializer()) { in HandleConstructorCall()
6476 QualType BaseType(I->getBaseClass(), 0); in HandleConstructorCall()
6478 // Non-virtual base classes are initialized in the order in the class in HandleConstructorCall()
6480 assert(!BaseIt->isVirtual() && "virtual base for literal type"); in HandleConstructorCall()
6481 assert(Info.Ctx.hasSameUnqualifiedType(BaseIt->getType(), BaseType) && in HandleConstructorCall()
6485 if (!HandleLValueDirectBase(Info, I->getInit(), Subobject, RD, in HandleConstructorCall()
6486 BaseType->getAsCXXRecordDecl(), &Layout)) in HandleConstructorCall()
6489 } else if ((FD = I->getMember())) { in HandleConstructorCall()
6490 if (!HandleLValueMember(Info, I->getInit(), Subobject, FD, &Layout)) in HandleConstructorCall()
6492 if (RD->isUnion()) { in HandleConstructorCall()
6497 Value = &Result.getStructField(FD->getFieldIndex()); in HandleConstructorCall()
6499 } else if (IndirectFieldDecl *IFD = I->getIndirectMember()) { in HandleConstructorCall()
6502 auto IndirectFieldChain = IFD->chain(); in HandleConstructorCall()
6505 CXXRecordDecl *CD = cast<CXXRecordDecl>(FD->getParent()); in HandleConstructorCall()
6507 // preceding zero-initialization, and we're now initializing a union in HandleConstructorCall()
6510 // specified, since zero-initialization sets all padding bits to zero. in HandleConstructorCall()
6511 if (!Value->hasValue() || in HandleConstructorCall()
6512 (Value->isUnion() && Value->getUnionField() != FD)) { in HandleConstructorCall()
6513 if (CD->isUnion()) in HandleConstructorCall()
6526 if (!HandleLValueMember(Info, I->getInit(), Subobject, FD)) in HandleConstructorCall()
6528 if (CD->isUnion()) in HandleConstructorCall()
6529 Value = &Value->getUnionValue(); in HandleConstructorCall()
6531 if (C == IndirectFieldChain.front() && !RD->isUnion()) in HandleConstructorCall()
6533 Value = &Value->getStructField(FD->getFieldIndex()); in HandleConstructorCall()
6543 const Expr *Init = I->getInit(); in HandleConstructorCall()
6544 if (Init->isValueDependent()) { in HandleConstructorCall()
6552 (FD && FD->isBitField() && in HandleConstructorCall()
6564 if (I->isBaseInitializer() && BasesSeen == RD->getNumBases()) in HandleConstructorCall()
6568 // Default-initialize any remaining fields. in HandleConstructorCall()
6569 if (!RD->isUnion()) { in HandleConstructorCall()
6570 for (; FieldIt != RD->field_end(); ++FieldIt) { in HandleConstructorCall()
6571 if (!FieldIt->isUnnamedBitField()) in HandleConstructorCall()
6573 FieldIt->getType(), in HandleConstructorCall()
6574 Result.getStructField(FieldIt->getFieldIndex())); in HandleConstructorCall()
6581 EvaluateStmt(Ret, Info, Definition->getBody()) != ESR_Failed && in HandleConstructorCall()
6590 CallRef Call = Info.CurrentCall->createCall(Definition); in HandleConstructorCall()
6605 if (Value.isAbsent() && !T->isNullPtrType()) { in HandleDestructionImpl()
6618 // For arrays, destroy elements right-to-left. in HandleDestructionImpl()
6620 uint64_t Size = CAT->getZExtSize(); in HandleDestructionImpl()
6621 QualType ElemT = CAT->getElementType(); in HandleDestructionImpl()
6635 expandArray(Value, Value.getArraySize() - 1); in HandleDestructionImpl()
6637 for (; Size != 0; --Size) { in HandleDestructionImpl()
6638 APValue &Elem = Value.getArrayInitializedElt(Size - 1); in HandleDestructionImpl()
6639 if (!HandleLValueArrayAdjustment(Info, &LocE, ElemLV, ElemT, -1) || in HandleDestructionImpl()
6649 const CXXRecordDecl *RD = T->getAsCXXRecordDecl(); in HandleDestructionImpl()
6662 if (RD->getNumVBases()) { in HandleDestructionImpl()
6667 const CXXDestructorDecl *DD = RD->getDestructor(); in HandleDestructionImpl()
6668 if (!DD && !RD->hasTrivialDestructor()) { in HandleDestructionImpl()
6673 if (!DD || DD->isTrivial() || in HandleDestructionImpl()
6674 (RD->isAnonymousStructOrUnion() && RD->isUnion())) { in HandleDestructionImpl()
6692 const Stmt *Body = DD->getBody(Definition); in HandleDestructionImpl()
6701 unsigned BasesLeft = RD->getNumBases(); in HandleDestructionImpl()
6720 if (EvaluateStmt(Ret, Info, Definition->getBody()) == ESR_Failed) in HandleDestructionImpl()
6724 if (RD->isUnion()) in HandleDestructionImpl()
6731 SmallVector<FieldDecl*, 16> Fields(RD->fields()); in HandleDestructionImpl()
6733 if (FD->isUnnamedBitField()) in HandleDestructionImpl()
6740 APValue *SubobjectValue = &Value.getStructField(FD->getFieldIndex()); in HandleDestructionImpl()
6742 FD->getType())) in HandleDestructionImpl()
6750 for (const CXXBaseSpecifier &Base : llvm::reverse(RD->bases())) { in HandleDestructionImpl()
6751 --BasesLeft; in HandleDestructionImpl()
6756 BaseType->getAsCXXRecordDecl(), &Layout)) in HandleDestructionImpl()
6781 return HandleDestructionImpl(Info, E->getSourceRange(), This, Subobj, in found()
6795 /// Perform a destructor or pseudo-destructor call on the given object, which
6808 // If we've had an unmodeled side-effect, we can't rely on mutable state in HandleDestruction()
6828 Info.FFDiag(E->getExprLoc(), Info.getLangOpts().CPlusPlus20 in HandleOperatorNewCall()
6835 if (ElemType->isIncompleteType() || ElemType->isFunctionType()) { in HandleOperatorNewCall()
6836 Info.FFDiag(E->getExprLoc(), in HandleOperatorNewCall()
6838 << (ElemType->isIncompleteType() ? 0 : 1) << ElemType; in HandleOperatorNewCall()
6843 if (!EvaluateInteger(E->getArg(0), ByteSize, Info)) in HandleOperatorNewCall()
6846 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) { in HandleOperatorNewCall()
6847 EvaluateIgnoredValue(Info, E->getArg(I)); in HandleOperatorNewCall()
6848 IsNothrow |= E->getType()->isNothrowT(); in HandleOperatorNewCall()
6852 if (!HandleSizeof(Info, E->getExprLoc(), ElemType, ElemSize)) in HandleOperatorNewCall()
6859 Info.FFDiag(E->getExprLoc(), diag::note_constexpr_operator_new_bad_size) in HandleOperatorNewCall()
6864 if (!Info.CheckArraySize(E->getBeginLoc(), ByteSize.getActiveBits(), in HandleOperatorNewCall()
6867 Result.setNull(Info.Ctx, E->getType()); in HandleOperatorNewCall()
6882 if (CXXRecordDecl *RD = T->getAsCXXRecordDecl()) in hasVirtualDestructor()
6883 if (CXXDestructorDecl *DD = RD->getDestructor()) in hasVirtualDestructor()
6884 return DD->isVirtual(); in hasVirtualDestructor()
6889 if (CXXRecordDecl *RD = T->getAsCXXRecordDecl()) in getVirtualOperatorDelete()
6890 if (CXXDestructorDecl *DD = RD->getDestructor()) in getVirtualOperatorDelete()
6891 return DD->isVirtual() ? DD->getOperatorDelete() : nullptr; in getVirtualOperatorDelete()
6922 if (DeallocKind != (*Alloc)->getKind()) { in CheckDeleteKind()
6925 << DeallocKind << (*Alloc)->getKind() << AllocType; in CheckDeleteKind()
6955 Info.FFDiag(E->getExprLoc()); in HandleOperatorDeleteCall()
6960 if (!EvaluatePointer(E->getArg(0), Pointer, Info)) in HandleOperatorDeleteCall()
6962 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) in HandleOperatorDeleteCall()
6963 EvaluateIgnoredValue(Info, E->getArg(I)); in HandleOperatorDeleteCall()
6971 Info.CCEDiag(E->getExprLoc(), diag::note_constexpr_deallocate_null); in HandleOperatorDeleteCall()
6982 //===----------------------------------------------------------------------===//
6984 //===----------------------------------------------------------------------===//
6988 // FIXME: We're going to need bit-level granularity when we support
6989 // bit-fields.
7056 if (Ty->isNullPtrType()) in visit()
7084 Info.FFDiag(BCE->getBeginLoc(), in visit()
7097 const RecordDecl *RD = Ty->getAsRecordDecl(); in visitRecord()
7102 for (size_t I = 0, E = CXXRD->getNumBases(); I != E; ++I) { in visitRecord()
7103 const CXXBaseSpecifier &BS = CXXRD->bases_begin()[I]; in visitRecord()
7104 CXXRecordDecl *BaseDecl = BS.getType()->getAsCXXRecordDecl(); in visitRecord()
7114 for (FieldDecl *FD : RD->fields()) { in visitRecord()
7115 if (FD->isBitField()) { in visitRecord()
7116 Info.FFDiag(BCE->getBeginLoc(), in visitRecord()
7124 "only bit-fields can have sub-char alignment"); in visitRecord()
7127 QualType FieldTy = FD->getType(); in visitRecord()
7138 dyn_cast_or_null<ConstantArrayType>(Ty->getAsArrayTypeUnsafe()); in visitArray()
7142 CharUnits ElemWidth = Info.Ctx.getTypeSizeInChars(CAT->getElementType()); in visitArray()
7148 if (!visit(SubObj, CAT->getElementType(), Offset + I * ElemWidth)) in visitArray()
7156 if (!visit(Filler, CAT->getElementType(), Offset + I * ElemWidth)) in visitArray()
7165 const VectorType *VTy = Ty->castAs<VectorType>(); in visitVector()
7166 QualType EltTy = VTy->getElementType(); in visitVector()
7167 unsigned NElts = VTy->getNumElements(); in visitVector()
7169 VTy->isExtVectorBoolType() ? 1 : Info.Ctx.getTypeSize(EltTy); in visitVector()
7176 Info.FFDiag(BCE->getBeginLoc(), in visitVector()
7183 if (EltTy->isRealFloatingType() && &Info.Ctx.getFloatTypeSemantics(EltTy) == in visitVector()
7188 Info.FFDiag(BCE->getBeginLoc(), in visitVector()
7194 if (VTy->isExtVectorBoolType()) { in visitVector()
7209 "bool vector element must be 1-bit unsigned integer!"); in visitVector()
7211 Res.insertBits(EltAsInt, BigEndian ? (NElts - I - 1) : I); in visitVector()
7233 if (Ty->isBooleanType()) { in visitInt()
7252 CharUnits DstSize = Info.Ctx.getTypeSizeInChars(BCE->getType()); in convert()
7254 if (!Converter.visit(Src, BCE->getSubExpr()->getType())) in convert()
7274 Info.FFDiag(BCE->getBeginLoc(), in unsupportedType()
7281 Info.FFDiag(BCE->getBeginLoc(), in unrepresentableValue()
7289 if (T->isNullPtrType()) { in visit()
7301 if (T->isRealFloatingType()) { in visit()
7315 bool IsStdByte = EnumSugar && EnumSugar->isStdByteType(); in visit()
7317 !EnumSugar && (T->isSpecificBuiltinType(BuiltinType::UChar) || in visit()
7318 T->isSpecificBuiltinType(BuiltinType::Char_U)); in visit()
7321 Info.FFDiag(BCE->getExprLoc(), in visit()
7333 if (T->isIntegralOrEnumerationType()) { in visit()
7334 Val.setIsSigned(T->isSignedIntegerOrEnumerationType()); in visit()
7347 if (T->isRealFloatingType()) { in visit()
7357 const RecordDecl *RD = RTy->getAsRecordDecl(); in visit()
7362 NumBases = CXXRD->getNumBases(); in visit()
7365 std::distance(RD->field_begin(), RD->field_end())); in visit()
7369 for (size_t I = 0, E = CXXRD->getNumBases(); I != E; ++I) { in visit()
7370 const CXXBaseSpecifier &BS = CXXRD->bases_begin()[I]; in visit()
7371 CXXRecordDecl *BaseDecl = BS.getType()->getAsCXXRecordDecl(); in visit()
7383 for (FieldDecl *FD : RD->fields()) { in visit()
7384 // FIXME: We don't currently support bit-fields. A lot of the logic for in visit()
7386 if (FD->isBitField()) { in visit()
7387 Info.FFDiag(BCE->getBeginLoc(), in visit()
7398 QualType FieldTy = FD->getType(); in visit()
7410 QualType RepresentationType = Ty->getDecl()->getIntegerType(); in visit()
7414 RepresentationType.getCanonicalType()->castAs<BuiltinType>(); in visit()
7421 size_t Size = Ty->getLimitedSize(); in visit()
7422 CharUnits ElementWidth = Info.Ctx.getTypeSizeInChars(Ty->getElementType()); in visit()
7427 visitType(Ty->getElementType(), Offset + I * ElementWidth); in visit()
7437 QualType EltTy = VTy->getElementType(); in visit()
7438 unsigned NElts = VTy->getNumElements(); in visit()
7440 VTy->isExtVectorBoolType() ? 1 : Info.Ctx.getTypeSize(EltTy); in visit()
7447 Info.FFDiag(BCE->getBeginLoc(), in visit()
7453 if (EltTy->isRealFloatingType() && &Info.Ctx.getFloatTypeSemantics(EltTy) == in visit()
7458 Info.FFDiag(BCE->getBeginLoc(), in visit()
7466 if (VTy->isExtVectorBoolType()) { in visit()
7487 SValInt.extractBits(1, (BigEndian ? NElts - I - 1 : I) * EltSize); in visit()
7489 APSInt(std::move(Elt), !EltTy->isSignedIntegerType())); in visit()
7514 switch (Can->getTypeClass()) { in visitType()
7521 llvm_unreachable("non-canonical type should be impossible!"); in visitType()
7539 return Converter.visitType(BCE->getType(), CharUnits::fromQuantity(0)); in convert()
7551 Info->FFDiag(Loc, diag::note_constexpr_bit_cast_invalid_type) in checkBitCastConstexprEligibilityType()
7557 Info->Note(NoteLoc, diag::note_constexpr_bit_cast_invalid_subtype) in checkBitCastConstexprEligibilityType()
7562 if (Ty->isUnionType()) in checkBitCastConstexprEligibilityType()
7564 if (Ty->isPointerType()) in checkBitCastConstexprEligibilityType()
7566 if (Ty->isMemberPointerType()) in checkBitCastConstexprEligibilityType()
7571 if (RecordDecl *Record = Ty->getAsRecordDecl()) { in checkBitCastConstexprEligibilityType()
7573 for (CXXBaseSpecifier &BS : CXXRD->bases()) in checkBitCastConstexprEligibilityType()
7578 for (FieldDecl *FD : Record->fields()) { in checkBitCastConstexprEligibilityType()
7579 if (FD->getType()->isReferenceType()) in checkBitCastConstexprEligibilityType()
7581 if (!checkBitCastConstexprEligibilityType(Loc, FD->getType(), Info, Ctx, in checkBitCastConstexprEligibilityType()
7583 return note(0, FD->getType(), FD->getBeginLoc()); in checkBitCastConstexprEligibilityType()
7587 if (Ty->isArrayType() && in checkBitCastConstexprEligibilityType()
7599 BCE->getBeginLoc(), BCE->getType(), Info, Ctx, true); in checkBitCastConstexprEligibility()
7601 BCE->getBeginLoc(), in checkBitCastConstexprEligibility()
7602 BCE->getSubExpr()->getType(), Info, Ctx, false); in checkBitCastConstexprEligibility()
7610 "no host or target supports non 8-bit chars"); in handleRValueToRValueBitCast()
7635 "no host or target supports non 8-bit chars"); in handleLValueToRValueBitCast()
7643 Info, BCE, BCE->getSubExpr()->getType().withConst(), SourceLValue, in handleLValueToRValueBitCast()
7662 // Check whether a conditional operator with a non-constant condition is a
7673 StmtVisitorTy::Visit(E->getFalseExpr()); in CheckPotentialConstantConditional()
7681 StmtVisitorTy::Visit(E->getTrueExpr()); in CheckPotentialConstantConditional()
7693 if (!EvaluateAsBooleanCondition(E->getCond(), BoolResult, Info)) { in HandleConditionalOperator()
7699 StmtVisitorTy::Visit(E->getTrueExpr()); in HandleConditionalOperator()
7700 StmtVisitorTy::Visit(E->getFalseExpr()); in HandleConditionalOperator()
7705 Expr *EvalExpr = BoolResult ? E->getTrueExpr() : E->getFalseExpr(); in HandleConditionalOperator()
7721 unsigned BuiltinOp = E->getBuiltinCallee(); in IsConstantEvaluatedBuiltinCall()
7734 Info.FFDiag(E, D) << E->getSourceRange(); in Error()
7749 const auto It = E->begin(); in VisitEmbedExpr()
7754 return StmtVisitorTy::Visit(E->getFunctionName()); in VisitPredefinedExpr()
7757 if (E->hasAPValueResult()) in VisitConstantExpr()
7758 return DerivedSuccess(E->getAPValueResult(), E); in VisitConstantExpr()
7760 return StmtVisitorTy::Visit(E->getSubExpr()); in VisitConstantExpr()
7764 { return StmtVisitorTy::Visit(E->getSubExpr()); } in VisitParenExpr()
7766 { return StmtVisitorTy::Visit(E->getSubExpr()); } in VisitUnaryExtension()
7768 { return StmtVisitorTy::Visit(E->getSubExpr()); } in VisitUnaryPlus()
7770 { return StmtVisitorTy::Visit(E->getChosenSubExpr()); } in VisitChooseExpr()
7772 { return StmtVisitorTy::Visit(E->getResultExpr()); } in VisitGenericSelectionExpr()
7774 { return StmtVisitorTy::Visit(E->getReplacement()); } in VisitSubstNonTypeTemplateParmExpr()
7777 SourceLocExprScopeGuard Guard(E, Info.CurrentCall->CurSourceLocExprScope); in VisitCXXDefaultArgExpr()
7778 return StmtVisitorTy::Visit(E->getExpr()); in VisitCXXDefaultArgExpr()
7783 if (!E->getExpr()) in VisitCXXDefaultInitExpr()
7785 SourceLocExprScopeGuard Guard(E, Info.CurrentCall->CurSourceLocExprScope); in VisitCXXDefaultInitExpr()
7786 return StmtVisitorTy::Visit(E->getExpr()); in VisitCXXDefaultInitExpr()
7791 return StmtVisitorTy::Visit(E->getSubExpr()) && Scope.destroy(); in VisitExprWithCleanups()
7797 return StmtVisitorTy::Visit(E->getSubExpr()); in VisitCXXBindTemporaryExpr()
7802 return static_cast<Derived*>(this)->VisitCastExpr(E); in VisitCXXReinterpretCastExpr()
7807 return static_cast<Derived*>(this)->VisitCastExpr(E); in VisitCXXDynamicCastExpr()
7810 return static_cast<Derived*>(this)->VisitCastExpr(E); in VisitBuiltinBitCastExpr()
7814 switch (E->getOpcode()) { in VisitBinaryOperator()
7819 VisitIgnoredValue(E->getLHS()); in VisitBinaryOperator()
7820 return StmtVisitorTy::Visit(E->getRHS()); in VisitBinaryOperator()
7828 if (!handleLValueToRValueConversion(Info, E, E->getType(), Obj, Result)) in VisitBinaryOperator()
7836 return StmtVisitorTy::Visit(E->getSemanticForm()); in VisitCXXRewrittenBinaryOperator()
7843 if (!Evaluate(Info.CurrentCall->createTemporary( in VisitBinaryConditionalOperator()
7844 E->getOpaqueValue(), in VisitBinaryConditionalOperator()
7845 getStorageType(Info.Ctx, E->getOpaqueValue()), in VisitBinaryConditionalOperator()
7847 Info, E->getCommon())) in VisitBinaryConditionalOperator()
7857 // side-effects. This is an important GNU extension. See GCC PR38377 in VisitConditionalOperator()
7860 dyn_cast<CallExpr>(E->getCond()->IgnoreParenCasts())) in VisitConditionalOperator()
7861 if (CallCE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) in VisitConditionalOperator()
7866 // FIXME: We should instead treat __builtin_constant_p as non-constant if in VisitConditionalOperator()
7881 if (APValue *Value = Info.CurrentCall->getCurrentTemporary(E); in VisitOpaqueValueExpr()
7882 Value && !Value->isAbsent()) in VisitOpaqueValueExpr()
7885 const Expr *Source = E->getSourceExpr(); in VisitOpaqueValueExpr()
7896 for (const Expr *SemE : E->semantics()) { in VisitPseudoObjectExpr()
7901 if (SemE == E->getResultExpr()) in VisitPseudoObjectExpr()
7906 if (OVE->isUnique()) in VisitPseudoObjectExpr()
7910 if (!Evaluate(Info.CurrentCall->createTemporary( in VisitPseudoObjectExpr()
7913 Info, OVE->getSourceExpr())) in VisitPseudoObjectExpr()
7915 } else if (SemE == E->getResultExpr()) { in VisitPseudoObjectExpr()
7937 const Expr *Callee = E->getCallee()->IgnoreParens(); in handleCallExpr()
7938 QualType CalleeType = Callee->getType(); in handleCallExpr()
7942 auto Args = llvm::ArrayRef(E->getArgs(), E->getNumArgs()); in handleCallExpr()
7948 if (CalleeType->isSpecificBuiltinType(BuiltinType::BoundMember)) { in handleCallExpr()
7951 // Explicit bound member calls, such as x.f() or p->g(); in handleCallExpr()
7952 if (!EvaluateObjectArgument(Info, ME->getBase(), ThisVal)) in handleCallExpr()
7954 Member = dyn_cast<CXXMethodDecl>(ME->getMemberDecl()); in handleCallExpr()
7958 HasQualifier = ME->hasQualifier(); in handleCallExpr()
7960 // Indirect bound member calls ('.*' or '->*'). in handleCallExpr()
7972 return EvaluateObjectArgument(Info, PDE->getBase(), ThisVal) && in handleCallExpr()
7973 HandleDestruction(Info, PDE, ThisVal, PDE->getDestroyedType()); in handleCallExpr()
7977 } else if (CalleeType->isFunctionPointerType()) { in handleCallExpr()
7996 CalleeType->getPointeeType(), FD->getType())) { in handleCallExpr()
8003 if (OCE && OCE->isAssignmentOp()) { in handleCallExpr()
8005 Call = Info.CurrentCall->createCall(FD); in handleCallExpr()
8008 HasThis = MD->isImplicitObjectMemberFunction(); in handleCallExpr()
8018 (MD->isImplicitObjectMemberFunction() || (OCE && MD->isStatic()))) { in handleCallExpr()
8030 if (MD->isInstance()) in handleCallExpr()
8037 OCE->getOperator() == OO_Equal && MD->isTrivial() && in handleCallExpr()
8042 } else if (MD && MD->isLambdaStaticInvoker()) { in handleCallExpr()
8045 // being done for the non-static case), since a static member function in handleCallExpr()
8047 const CXXRecordDecl *ClosureClass = MD->getParent(); in handleCallExpr()
8049 ClosureClass->captures_begin() == ClosureClass->captures_end() && in handleCallExpr()
8050 "Number of captures must be zero for conversion to function-ptr"); in handleCallExpr()
8053 ClosureClass->getLambdaCallOperator(); in handleCallExpr()
8059 if (ClosureClass->isGenericLambda()) { in handleCallExpr()
8060 assert(MD->isFunctionTemplateSpecialization() && in handleCallExpr()
8061 "A generic lambda's static-invoker function must be a " in handleCallExpr()
8063 const TemplateArgumentList *TAL = MD->getTemplateSpecializationArgs(); in handleCallExpr()
8065 LambdaCallOp->getDescribedFunctionTemplate(); in handleCallExpr()
8068 CallOpTemplate->findSpecialization(TAL->asArray(), InsertPos); in handleCallExpr()
8076 } else if (FD->isReplaceableGlobalAllocationFunction()) { in handleCallExpr()
8077 if (FD->getDeclName().getCXXOverloadedOperator() == OO_New || in handleCallExpr()
8078 FD->getDeclName().getCXXOverloadedOperator() == OO_Array_New) { in handleCallExpr()
8093 Call = Info.CurrentCall->createCall(FD); in handleCallExpr()
8101 if (NamedMember && NamedMember->isVirtual() && !HasQualifier) { in handleCallExpr()
8107 } else if (NamedMember && NamedMember->isImplicitObjectMemberFunction()) { in handleCallExpr()
8120 Info.Ctx.getRecordType(DD->getParent())) && in handleCallExpr()
8125 Stmt *Body = FD->getBody(Definition); in handleCallExpr()
8127 if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition, Body) || in handleCallExpr()
8128 !HandleFunctionCall(E->getExprLoc(), Definition, This, E, Args, Call, in handleCallExpr()
8141 return StmtVisitorTy::Visit(E->getInitializer()); in VisitCompoundLiteralExpr()
8144 if (E->getNumInits() == 0) in VisitInitListExpr()
8146 if (E->getNumInits() == 1) in VisitInitListExpr()
8147 return StmtVisitorTy::Visit(E->getInit(0)); in VisitInitListExpr()
8164 assert(!E->isArrow() && "missing call to bound member function?"); in VisitMemberExpr()
8167 if (!Evaluate(Val, Info, E->getBase())) in VisitMemberExpr()
8170 QualType BaseTy = E->getBase()->getType(); in VisitMemberExpr()
8172 const FieldDecl *FD = dyn_cast<FieldDecl>(E->getMemberDecl()); in VisitMemberExpr()
8174 assert(!FD->getType()->isReferenceType() && "prvalue reference?"); in VisitMemberExpr()
8175 assert(BaseTy->castAs<RecordType>()->getDecl()->getCanonicalDecl() == in VisitMemberExpr()
8176 FD->getParent()->getCanonicalDecl() && "record / field mismatch"); in VisitMemberExpr()
8192 if (!Evaluate(Val, Info, E->getBase())) in VisitExtVectorElementExpr()
8197 E->getEncodedElementAccess(Indices); in VisitExtVectorElementExpr()
8216 switch (E->getCastKind()) { in VisitCastExpr()
8223 // atomic-to-non-atomic conversion implies copying the object in VisitCastExpr()
8225 if (!Evaluate(AtomicVal, Info, E->getSubExpr())) in VisitCastExpr()
8232 return StmtVisitorTy::Visit(E->getSubExpr()); in VisitCastExpr()
8236 if (!EvaluateLValue(E->getSubExpr(), LVal, Info)) in VisitCastExpr()
8239 // Note, we use the subexpression's type in order to retain cv-qualifiers. in VisitCastExpr()
8240 if (!handleLValueToRValueConversion(Info, E, E->getSubExpr()->getType(), in VisitCastExpr()
8247 if (!Evaluate(SourceValue, Info, E->getSubExpr())) in VisitCastExpr()
8256 if (!Evaluate(Value, Info, E->getSubExpr())) in VisitCastExpr()
8276 if (!EvaluateLValue(UO->getSubExpr(), LVal, Info)) in VisitUnaryPostIncDec()
8279 if (!handleIncDec(this->Info, UO, LVal, UO->getSubExpr()->getType(), in VisitUnaryPostIncDec()
8280 UO->isIncrementOp(), &RVal)) in VisitUnaryPostIncDec()
8286 // We will have checked the full-expressions inside the statement expression in VisitStmtExpr()
8291 const CompoundStmt *CS = E->getSubStmt(); in VisitStmtExpr()
8292 if (CS->body_empty()) in VisitStmtExpr()
8296 for (CompoundStmt::const_body_iterator BI = CS->body_begin(), in VisitStmtExpr()
8297 BE = CS->body_end(); in VisitStmtExpr()
8302 Info.FFDiag((*BI)->getBeginLoc(), in VisitStmtExpr()
8306 return this->Visit(FinalExpr) && Scope.destroy(); in VisitStmtExpr()
8313 // FIXME: If the statement-expression terminated due to 'return', in VisitStmtExpr()
8317 Info.FFDiag((*BI)->getBeginLoc(), in VisitStmtExpr()
8327 return StmtVisitorTy::Visit(E->getSelectedExpr()); in VisitPackIndexingExpr()
8338 // presence of side-effecting behavior. in VisitIgnoredBaseExpression()
8339 if (Info.getLangOpts().MSVCCompat && !E->HasSideEffects(Info.Ctx)) in VisitIgnoredBaseExpression()
8347 //===----------------------------------------------------------------------===//
8349 //===----------------------------------------------------------------------===//
8366 return EvaluatePointer(E, Result, this->Info, InvalidBaseOK); in evaluatePointer()
8375 Result.setFrom(this->Info.Ctx, V); in Success()
8380 // Handle non-static data members. in VisitMemberExpr()
8383 if (E->isArrow()) { in VisitMemberExpr()
8384 EvalOK = evaluatePointer(E->getBase(), Result); in VisitMemberExpr()
8385 BaseTy = E->getBase()->getType()->castAs<PointerType>()->getPointeeType(); in VisitMemberExpr()
8386 } else if (E->getBase()->isPRValue()) { in VisitMemberExpr()
8387 assert(E->getBase()->getType()->isRecordType()); in VisitMemberExpr()
8388 EvalOK = EvaluateTemporary(E->getBase(), Result, this->Info); in VisitMemberExpr()
8389 BaseTy = E->getBase()->getType(); in VisitMemberExpr()
8391 EvalOK = this->Visit(E->getBase()); in VisitMemberExpr()
8392 BaseTy = E->getBase()->getType(); in VisitMemberExpr()
8401 const ValueDecl *MD = E->getMemberDecl(); in VisitMemberExpr()
8402 if (const FieldDecl *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { in VisitMemberExpr()
8403 assert(BaseTy->castAs<RecordType>()->getDecl()->getCanonicalDecl() == in VisitMemberExpr()
8404 FD->getParent()->getCanonicalDecl() && "record / field mismatch"); in VisitMemberExpr()
8406 if (!HandleLValueMember(this->Info, E, Result, FD)) in VisitMemberExpr()
8409 if (!HandleLValueIndirectMember(this->Info, E, Result, IFD)) in VisitMemberExpr()
8412 return this->Error(E); in VisitMemberExpr()
8414 if (MD->getType()->isReferenceType()) { in VisitMemberExpr()
8416 if (!handleLValueToRValueConversion(this->Info, E, MD->getType(), Result, in VisitMemberExpr()
8425 switch (E->getOpcode()) { in VisitBinaryOperator()
8431 return HandleMemberPointerAccess(this->Info, E, Result); in VisitBinaryOperator()
8436 switch (E->getCastKind()) { in VisitCastExpr()
8442 if (!this->Visit(E->getSubExpr())) in VisitCastExpr()
8447 return HandleLValueBasePath(this->Info, E, E->getSubExpr()->getType(), in VisitCastExpr()
8454 //===----------------------------------------------------------------------===//
8459 // temporaries (if building with -Wno-address-of-temporary).
8463 // - Declarations
8466 // - Literals
8475 // - typeid(T) expressions, as TypeInfoLValues
8476 // - Locals and temporaries
8482 // CallIndex, for a lifetime-extended temporary.
8486 //===----------------------------------------------------------------------===//
8521 switch (E->getCastKind()) { in VisitCastExpr()
8526 this->CCEDiag(E, diag::note_constexpr_invalid_cast) in VisitCastExpr()
8528 if (!Visit(E->getSubExpr())) in VisitCastExpr()
8534 if (!Visit(E->getSubExpr())) in VisitCastExpr()
8539 if (!Visit(E->getSubExpr())) in VisitCastExpr()
8553 if (MD->isStatic()) { in HandleLambdaCapture()
8554 assert(Info.CurrentCall->This == nullptr && in HandleLambdaCapture()
8560 if (MD->isExplicitObjectMemberFunction()) { in HandleLambdaCapture()
8562 const ParmVarDecl *Self = MD->getParamDecl(0); in HandleLambdaCapture()
8563 if (Self->getType()->isReferenceType()) { in HandleLambdaCapture()
8564 APValue *RefValue = Info.getParamSlot(Info.CurrentCall->Arguments, Self); in HandleLambdaCapture()
8567 const ParmVarDecl *VD = Info.CurrentCall->Arguments.getOrigParam(Self); in HandleLambdaCapture()
8569 Info.getCallFrameAndDepth(Info.CurrentCall->Arguments.CallIndex) in HandleLambdaCapture()
8571 unsigned Version = Info.CurrentCall->Arguments.Version; in HandleLambdaCapture()
8572 Result.set({VD, Frame->Index, Version}); in HandleLambdaCapture()
8575 Result = *Info.CurrentCall->This; in HandleLambdaCapture()
8587 if (!handleLValueToRValueConversion(Info, E, FD->getType(), Result, RVal)) in HandleLambdaCapture()
8598 /// * @selector() expressions in Objective-C
8601 assert(!E->isValueDependent()); in EvaluateLValue()
8602 assert(E->isGLValue() || E->getType()->isFunctionType() || in EvaluateLValue()
8603 E->getType()->isVoidType() || isa<ObjCSelectorExpr>(E->IgnoreParens())); in EvaluateLValue()
8608 const NamedDecl *D = E->getDecl(); in VisitDeclRefExpr()
8615 return Visit(BD->getBinding()); in VisitDeclRefExpr()
8623 // to within 'E' actually represents a lambda-capture that maps to a in VisitVarDecl()
8624 // data-member/field within the closure object, and if so, evaluate to the in VisitVarDecl()
8626 if (Info.CurrentCall && isLambdaCallOperator(Info.CurrentCall->Callee) && in VisitVarDecl()
8628 cast<DeclRefExpr>(E)->refersToEnclosingVariableOrCapture()) { in VisitVarDecl()
8629 // We don't always have a complete capture-map when checking or inferring if in VisitVarDecl()
8631 // - but we don't need to evaluate the captures to determine constexprness in VisitVarDecl()
8636 if (auto *FD = Info.CurrentCall->LambdaCaptureFields.lookup(VD)) { in VisitVarDecl()
8637 const auto *MD = cast<CXXMethodDecl>(Info.CurrentCall->Callee); in VisitVarDecl()
8639 FD->getType()->isReferenceType()); in VisitVarDecl()
8645 if (VD->hasLocalStorage()) { in VisitVarDecl()
8650 // variable) or be ill-formed (and trigger an appropriate evaluation in VisitVarDecl()
8653 if (CurrFrame->Callee && CurrFrame->Callee->Equals(VD->getDeclContext())) { in VisitVarDecl()
8658 if (CurrFrame->Arguments) { in VisitVarDecl()
8659 VD = CurrFrame->Arguments.getOrigParam(PVD); in VisitVarDecl()
8661 Info.getCallFrameAndDepth(CurrFrame->Arguments.CallIndex).first; in VisitVarDecl()
8662 Version = CurrFrame->Arguments.Version; in VisitVarDecl()
8666 Version = CurrFrame->getCurrentTemporaryVersion(VD); in VisitVarDecl()
8671 if (!VD->getType()->isReferenceType()) { in VisitVarDecl()
8673 Result.set({VD, Frame->Index, Version}); in VisitVarDecl()
8681 << VD << VD->getType(); in VisitVarDecl()
8682 Info.Note(VD->getLocation(), diag::note_declared_at); in VisitVarDecl()
8688 if (!V->hasValue()) { in VisitVarDecl()
8702 switch (E->getBuiltinCallee()) { in VisitCallExpr()
8710 if (cast<FunctionDecl>(E->getCalleeDecl())->isConstexpr()) in VisitCallExpr()
8711 return Visit(E->getArg(0)); in VisitCallExpr()
8724 E->getSubExpr()->skipRValueSubobjectAdjustments(CommaLHSs, Adjustments); in VisitMaterializeTemporaryExpr()
8735 if (E->getStorageDuration() == SD_Static) { in VisitMaterializeTemporaryExpr()
8739 Value = E->getOrCreateValue(true); in VisitMaterializeTemporaryExpr()
8743 Value = &Info.CurrentCall->createTemporary( in VisitMaterializeTemporaryExpr()
8744 E, Inner->getType(), in VisitMaterializeTemporaryExpr()
8745 E->getStorageDuration() == SD_FullExpression ? ScopeKind::FullExpression in VisitMaterializeTemporaryExpr()
8750 QualType Type = Inner->getType(); in VisitMaterializeTemporaryExpr()
8760 --I; in VisitMaterializeTemporaryExpr()
8766 Type = Adjustments[I].DerivedToBase.BasePath->getType(); in VisitMaterializeTemporaryExpr()
8772 Type = Adjustments[I].Field->getType(); in VisitMaterializeTemporaryExpr()
8776 if (!HandleMemberPointerAccess(this->Info, Type, Result, in VisitMaterializeTemporaryExpr()
8779 Type = Adjustments[I].Ptr.MPT->getPointeeType(); in VisitMaterializeTemporaryExpr()
8789 assert((!Info.getLangOpts().CPlusPlus || E->isFileScope()) && in VisitCompoundLiteralExpr()
8791 // Defer visiting the literal until the lvalue-to-rvalue conversion. We can in VisitCompoundLiteralExpr()
8799 if (!E->isPotentiallyEvaluated()) { in VisitCXXTypeidExpr()
8800 if (E->isTypeOperand()) in VisitCXXTypeidExpr()
8801 TypeInfo = TypeInfoLValue(E->getTypeOperand(Info.Ctx).getTypePtr()); in VisitCXXTypeidExpr()
8803 TypeInfo = TypeInfoLValue(E->getExprOperand()->getType().getTypePtr()); in VisitCXXTypeidExpr()
8807 << E->getExprOperand()->getType() in VisitCXXTypeidExpr()
8808 << E->getExprOperand()->getSourceRange(); in VisitCXXTypeidExpr()
8811 if (!Visit(E->getExprOperand())) in VisitCXXTypeidExpr()
8820 TypeInfoLValue(Info.Ctx.getRecordType(DynType->Type).getTypePtr()); in VisitCXXTypeidExpr()
8823 return Success(APValue::LValueBase::getTypeInfo(TypeInfo, E->getType())); in VisitCXXTypeidExpr()
8827 return Success(E->getGuidDecl()); in VisitCXXUuidofExpr()
8832 if (const VarDecl *VD = dyn_cast<VarDecl>(E->getMemberDecl())) { in VisitMemberExpr()
8833 VisitIgnoredBaseExpression(E->getBase()); in VisitMemberExpr()
8838 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(E->getMemberDecl())) { in VisitMemberExpr()
8839 if (MD->isStatic()) { in VisitMemberExpr()
8840 VisitIgnoredBaseExpression(E->getBase()); in VisitMemberExpr()
8845 // Handle non-static data members. in VisitMemberExpr()
8851 if (E->getBase()->getType()->isVectorType() || in VisitArraySubscriptExpr()
8852 E->getBase()->getType()->isSveVLSBuiltinType()) in VisitArraySubscriptExpr()
8860 for (const Expr *SubExpr : {E->getLHS(), E->getRHS()}) { in VisitArraySubscriptExpr()
8861 if (SubExpr == E->getBase() ? !evaluatePointer(SubExpr, Result) in VisitArraySubscriptExpr()
8870 HandleLValueArrayAdjustment(Info, E, Result, E->getType(), Index); in VisitArraySubscriptExpr()
8874 return evaluatePointer(E->getSubExpr(), Result); in VisitUnaryDeref()
8878 if (!Visit(E->getSubExpr())) in VisitUnaryReal()
8880 // __real is a no-op on scalar lvalues. in VisitUnaryReal()
8881 if (E->getSubExpr()->getType()->isAnyComplexType()) in VisitUnaryReal()
8882 HandleLValueComplexElement(Info, E, Result, E->getType(), false); in VisitUnaryReal()
8887 assert(E->getSubExpr()->getType()->isAnyComplexType() && in VisitUnaryImag()
8889 if (!Visit(E->getSubExpr())) in VisitUnaryImag()
8891 HandleLValueComplexElement(Info, E, Result, E->getType(), true); in VisitUnaryImag()
8899 if (!this->Visit(UO->getSubExpr())) in VisitUnaryPreIncDec()
8903 this->Info, UO, Result, UO->getSubExpr()->getType(), in VisitUnaryPreIncDec()
8904 UO->isIncrementOp(), nullptr); in VisitUnaryPreIncDec()
8916 if (!Evaluate(RHS, this->Info, CAO->getRHS())) { in VisitCompoundAssignOperator()
8923 if (!this->Visit(CAO->getLHS()) || !Success) in VisitCompoundAssignOperator()
8927 this->Info, CAO, in VisitCompoundAssignOperator()
8928 Result, CAO->getLHS()->getType(), CAO->getComputationLHSType(), in VisitCompoundAssignOperator()
8929 CAO->getOpForCompoundAssignment(CAO->getOpcode()), RHS); in VisitCompoundAssignOperator()
8940 if (!Evaluate(NewVal, this->Info, E->getRHS())) { in VisitBinAssign()
8946 if (!this->Visit(E->getLHS()) || !Success) in VisitBinAssign()
8950 !MaybeHandleUnionActiveMemberChange(Info, E->getLHS(), Result)) in VisitBinAssign()
8953 return handleAssignment(this->Info, E, Result, E->getLHS()->getType(), in VisitBinAssign()
8957 //===----------------------------------------------------------------------===//
8959 //===----------------------------------------------------------------------===//
8972 assert(AllocSize && AllocSize->getElemSizeParam().isValid()); in getBytesReturnedByAllocSizeCall()
8973 unsigned SizeArgNo = AllocSize->getElemSizeParam().getASTIndex(); in getBytesReturnedByAllocSizeCall()
8975 if (Call->getNumArgs() <= SizeArgNo) in getBytesReturnedByAllocSizeCall()
8980 if (!E->EvaluateAsInt(ExprResult, Ctx, Expr::SE_AllowSideEffects)) in getBytesReturnedByAllocSizeCall()
8990 if (!EvaluateAsSizeT(Call->getArg(SizeArgNo), SizeOfElem)) in getBytesReturnedByAllocSizeCall()
8993 if (!AllocSize->getNumElemsParam().isValid()) { in getBytesReturnedByAllocSizeCall()
8999 unsigned NumArgNo = AllocSize->getNumElemsParam().getASTIndex(); in getBytesReturnedByAllocSizeCall()
9000 if (!EvaluateAsSizeT(Call->getArg(NumArgNo), NumberOfElems)) in getBytesReturnedByAllocSizeCall()
9036 // variables (in the latter case, use-before-assign isn't UB; in the former, in evaluateLValueAsAllocSize()
9040 if (!VD || !VD->isLocalVarDecl() || !VD->getType().isConstQualified()) in evaluateLValueAsAllocSize()
9043 const Expr *Init = VD->getAnyInitializer(); in evaluateLValueAsAllocSize()
9044 if (!Init || Init->getType().isNull()) in evaluateLValueAsAllocSize()
9047 const Expr *E = Init->IgnoreParens(); in evaluateLValueAsAllocSize()
9055 QualType Pointee = E->getType()->castAs<PointerType>()->getPointeeType(); in evaluateLValueAsAllocSize()
9091 Result.setNull(Info.Ctx, E->getType()); in ZeroInitialization()
9101 if (E->isExpressibleAsConstantInitializer()) in VisitObjCBoxedExpr()
9104 EvaluateIgnoredValue(Info, E->getSubExpr()); in VisitObjCBoxedExpr()
9112 if (!E->getBlockDecl()->hasCaptures()) in VisitBlockExpr()
9119 Info.FFDiag(E, diag::note_constexpr_this) << E->isImplicit(); in VisitCXXThisExpr()
9129 isLambdaCallWithExplicitObjectParameter(Info.CurrentCall->Callee); in VisitCXXThisExpr()
9131 if (!Info.CurrentCall->This) { in VisitCXXThisExpr()
9136 Result = *Info.CurrentCall->This; in VisitCXXThisExpr()
9139 if (isLambdaCallOperator(Info.CurrentCall->Callee)) { in VisitCXXThisExpr()
9144 if (!Info.CurrentCall->LambdaThisCaptureField) { in VisitCXXThisExpr()
9145 if (IsExplicitLambda && !Info.CurrentCall->This) { in VisitCXXThisExpr()
9153 const auto *MD = cast<CXXMethodDecl>(Info.CurrentCall->Callee); in VisitCXXThisExpr()
9155 Info, E, Result, MD, Info.CurrentCall->LambdaThisCaptureField, in VisitCXXThisExpr()
9156 Info.CurrentCall->LambdaThisCaptureField->getType()->isPointerType()); in VisitCXXThisExpr()
9164 assert(!E->isIntType() && "SourceLocExpr isn't a pointer type?"); in VisitSourceLocExpr()
9165 APValue LValResult = E->EvaluateInContext( in VisitSourceLocExpr()
9166 Info.Ctx, Info.CurrentCall->CurSourceLocExprScope.getDefaultExpr()); in VisitSourceLocExpr()
9177 std::string ResultStr = E->ComputeName(Info.Ctx); in VisitSYCLUniqueStableNameExpr()
9187 /*Pascal*/ false, ArrayTy, E->getLocation()); in VisitSYCLUniqueStableNameExpr()
9200 assert(!E->isValueDependent()); in EvaluatePointer()
9201 assert(E->isPRValue() && E->getType()->hasPointerRepresentation()); in EvaluatePointer()
9206 if (E->getOpcode() != BO_Add && in VisitBinaryOperator()
9207 E->getOpcode() != BO_Sub) in VisitBinaryOperator()
9210 const Expr *PExp = E->getLHS(); in VisitBinaryOperator()
9211 const Expr *IExp = E->getRHS(); in VisitBinaryOperator()
9212 if (IExp->getType()->isPointerType()) in VisitBinaryOperator()
9223 if (E->getOpcode() == BO_Sub) in VisitBinaryOperator()
9226 QualType Pointee = PExp->getType()->castAs<PointerType>()->getPointeeType(); in VisitBinaryOperator()
9231 return evaluateLValue(E->getSubExpr(), Result); in VisitUnaryAddrOf()
9238 const IdentifierInfo *FnII = FD->getIdentifier(); in IsDeclSourceLocationCurrent()
9239 if (!FnII || !FnII->isStr("current")) in IsDeclSourceLocationCurrent()
9242 const auto *RD = dyn_cast<RecordDecl>(FD->getParent()); in IsDeclSourceLocationCurrent()
9246 const IdentifierInfo *ClassII = RD->getIdentifier(); in IsDeclSourceLocationCurrent()
9247 return RD->isInStdNamespace() && ClassII && ClassII->isStr("source_location"); in IsDeclSourceLocationCurrent()
9251 const Expr *SubExpr = E->getSubExpr(); in VisitCastExpr()
9253 switch (E->getCastKind()) { in VisitCastExpr()
9266 if (!E->getType()->isVoidPointerType()) { in VisitCastExpr()
9275 E->getType()->getPointeeType())); in VisitCastExpr()
9278 // 2. HACK 2022-03-28: Work around an issue with libstdc++'s in VisitCastExpr()
9279 // <source_location> header. Fixed in GCC 12 and later (2022-04-??). in VisitCastExpr()
9285 IsDeclSourceLocationCurrent(Info.CurrentCall->Callee) || in VisitCastExpr()
9289 if (SubExpr->getType()->isVoidPointerType() && in VisitCastExpr()
9293 << SubExpr->getType() << Info.getLangOpts().CPlusPlus26 in VisitCastExpr()
9295 << E->getType()->getPointeeType(); in VisitCastExpr()
9298 << 3 << SubExpr->getType(); in VisitCastExpr()
9305 if (E->getCastKind() == CK_AddressSpaceConversion && Result.IsNullPtr) in VisitCastExpr()
9311 if (!evaluatePointer(E->getSubExpr(), Result)) in VisitCastExpr()
9318 return HandleLValueBasePath(Info, E, E->getSubExpr()->getType()-> in VisitCastExpr()
9319 castAs<PointerType>()->getPointeeType(), in VisitCastExpr()
9323 if (!Visit(E->getSubExpr())) in VisitCastExpr()
9330 if (!Visit(E->getSubExpr())) in VisitCastExpr()
9335 VisitIgnoredValue(E->getSubExpr()); in VisitCastExpr()
9347 unsigned Size = Info.Ctx.getTypeSize(E->getType()); in VisitCastExpr()
9370 if (SubExpr->isGLValue()) { in VisitCastExpr()
9374 APValue &Value = Info.CurrentCall->createTemporary( in VisitCastExpr()
9375 SubExpr, SubExpr->getType(), ScopeKind::FullExpression, Result); in VisitCastExpr()
9380 auto *AT = Info.Ctx.getAsArrayType(SubExpr->getType()); in VisitCastExpr()
9384 Result.addUnsizedArray(Info, E, AT->getElementType()); in VisitCastExpr()
9393 if (!evaluateLValue(E->getSubExpr(), LVal)) in VisitCastExpr()
9397 // Note, we use the subexpression's type in order to retain cv-qualifiers. in VisitCastExpr()
9398 if (!handleLValueToRValueConversion(Info, E, E->getSubExpr()->getType(), in VisitCastExpr()
9432 llvm_unreachable("GetAlignOfType on a non-alignment ExprKind"); in GetAlignOfType()
9437 E = E->IgnoreParens(); in GetAlignOfExpr()
9439 // The kinds of expressions that we have special-case logic here for in GetAlignOfExpr()
9440 // should be kept up to date with the special checks for those in GetAlignOfExpr()
9446 return Info.Ctx.getDeclAlign(DRE->getDecl(), in GetAlignOfExpr()
9450 return Info.Ctx.getDeclAlign(ME->getMemberDecl(), in GetAlignOfExpr()
9453 return GetAlignOfType(Info, E->getType(), ExprKind); in GetAlignOfExpr()
9475 APSInt MaxValue(APInt::getOneBitSet(SrcWidth, SrcWidth - 1)); in getAlignmentArgument()
9501 QualType PointeeTy = E->getType()->castAs<PointerType>()->getPointeeType(); in visitNonBuiltinCallExpr()
9509 return VisitBuiltinCallExpr(E, E->getBuiltinCallee()); in VisitCallExpr()
9515 return T->isCharType() || T->isChar8Type(); in isOneByteCharacterType()
9527 return evaluateLValue(E->getArg(0), Result); in VisitBuiltinCallExpr()
9531 // behavior is non-constant. in VisitBuiltinCallExpr()
9532 if (!evaluatePointer(E->getArg(0), Result)) in VisitBuiltinCallExpr()
9537 if (!getAlignmentArgument(E->getArg(1), E->getArg(0)->getType(), Info, in VisitBuiltinCallExpr()
9542 if (E->getNumArgs() > 2) { in VisitBuiltinCallExpr()
9544 if (!EvaluateInteger(E->getArg(2), Offset, Info)) in VisitBuiltinCallExpr()
9547 int64_t AdditionalOffset = -Offset.getZExtValue(); in VisitBuiltinCallExpr()
9558 CCEDiag(E->getArg(0), in VisitBuiltinCallExpr()
9571 ? CCEDiag(E->getArg(0), in VisitBuiltinCallExpr()
9573 : CCEDiag(E->getArg(0), in VisitBuiltinCallExpr()
9584 if (!evaluatePointer(E->getArg(0), Result)) in VisitBuiltinCallExpr()
9587 if (!getAlignmentArgument(E->getArg(1), E->getArg(0)->getType(), Info, in VisitBuiltinCallExpr()
9597 // The alignment could be greater than the minimum at run-time, so we cannot in VisitBuiltinCallExpr()
9604 "Cannot handle > 64-bit address-space"); in VisitBuiltinCallExpr()
9610 Result.adjustOffset(NewOffset - Result.Offset); in VisitBuiltinCallExpr()
9611 // TODO: diagnose out-of-bounds values/only allow for arrays? in VisitBuiltinCallExpr()
9614 // Otherwise, we cannot constant-evaluate the result. in VisitBuiltinCallExpr()
9615 Info.FFDiag(E->getArg(0), diag::note_constexpr_alignment_adjust) in VisitBuiltinCallExpr()
9622 return evaluatePointer(E->getArg(0), Result); in VisitBuiltinCallExpr()
9639 if (!Visit(E->getArg(0))) in VisitBuiltinCallExpr()
9642 if (!EvaluateInteger(E->getArg(1), Desired, Info)) in VisitBuiltinCallExpr()
9644 uint64_t MaxLength = uint64_t(-1); in VisitBuiltinCallExpr()
9650 if (!EvaluateInteger(E->getArg(2), N, Info)) in VisitBuiltinCallExpr()
9665 CharTy, E->getArg(0)->getType()->getPointeeType())); in VisitBuiltinCallExpr()
9667 if (IsRawByte && CharTy->isIncompleteType()) { in VisitBuiltinCallExpr()
9671 // Give up on byte-oriented matching against multibyte elements. in VisitBuiltinCallExpr()
9689 E->getArg(1)->getType(), in VisitBuiltinCallExpr()
9715 for (; MaxLength; --MaxLength) { in VisitBuiltinCallExpr()
9756 if (!Visit(E->getArg(0))) in VisitBuiltinCallExpr()
9761 if (!EvaluatePointer(E->getArg(1), Src, Info)) in VisitBuiltinCallExpr()
9765 if (!EvaluateInteger(E->getArg(2), N, Info)) in VisitBuiltinCallExpr()
9769 // If the size is zero, we treat this as always being a valid no-op. in VisitBuiltinCallExpr()
9782 << Val.getAsString(Info.Ctx, E->getArg(0)->getType()); in VisitBuiltinCallExpr()
9789 // trivially-copyable type. (For the wide version, the designator will be in VisitBuiltinCallExpr()
9798 if (T->isIncompleteType()) { in VisitBuiltinCallExpr()
9842 if (DestOffset >= SrcOffset && DestOffset - SrcOffset < NBytes) { in VisitBuiltinCallExpr()
9849 if (!HandleLValueArrayAdjustment(Info, E, Src, T, NElems - 1) || in VisitBuiltinCallExpr()
9850 !HandleLValueArrayAdjustment(Info, E, Dest, T, NElems - 1)) in VisitBuiltinCallExpr()
9852 Direction = -1; in VisitBuiltinCallExpr()
9854 SrcOffset - DestOffset < NBytes) { in VisitBuiltinCallExpr()
9864 // char-like type? in VisitBuiltinCallExpr()
9870 if (--NElems == 0) in VisitBuiltinCallExpr()
9899 FunctionDecl *OperatorNew = E->getOperatorNew(); in VisitCXXNewExpr()
9903 if (OperatorNew->isReservedGlobalPlacementOperator() && in VisitCXXNewExpr()
9904 Info.CurrentCall->isStdFunction() && !E->isArray()) { in VisitCXXNewExpr()
9906 assert(E->getNumPlacementArgs() == 1); in VisitCXXNewExpr()
9907 if (!EvaluatePointer(E->getPlacementArg(0), Result, Info)) in VisitCXXNewExpr()
9912 } else if (!OperatorNew->isReplaceableGlobalAllocationFunction()) { in VisitCXXNewExpr()
9916 } else if (E->getNumPlacementArgs()) { in VisitCXXNewExpr()
9917 // The only new-placement list we support is of the form (std::nothrow). in VisitCXXNewExpr()
9926 // alignof(X) and X has new-extended alignment). in VisitCXXNewExpr()
9927 if (E->getNumPlacementArgs() != 1 || in VisitCXXNewExpr()
9928 !E->getPlacementArg(0)->getType()->isNothrowT()) in VisitCXXNewExpr()
9932 if (!EvaluateLValue(E->getPlacementArg(0), Nothrow, Info)) in VisitCXXNewExpr()
9937 const Expr *Init = E->getInitializer(); in VisitCXXNewExpr()
9942 QualType AllocType = E->getAllocatedType(); in VisitCXXNewExpr()
9943 if (std::optional<const Expr *> ArraySize = E->getArraySize()) { in VisitCXXNewExpr()
9946 Stripped = ICE->getSubExpr()) in VisitCXXNewExpr()
9947 if (ICE->getCastKind() != CK_NoOp && in VisitCXXNewExpr()
9948 ICE->getCastKind() != CK_IntegralCast) in VisitCXXNewExpr()
9957 // -- [...] its value before converting to size_t [or] applying the in VisitCXXNewExpr()
9964 << ArrayBound << (*ArraySize)->getSourceRange(); in VisitCXXNewExpr()
9968 // -- its value is such that the size of the allocated object would in VisitCXXNewExpr()
9969 // exceed the implementation-defined limit in VisitCXXNewExpr()
9970 if (!Info.CheckArraySize(ArraySize.value()->getExprLoc(), in VisitCXXNewExpr()
9979 // -- the new-initializer is a braced-init-list and the number of in VisitCXXNewExpr()
9990 auto *CAT = Info.Ctx.getAsConstantArrayType(Init->getType()); in VisitCXXNewExpr()
9994 std::max(CAT->getSizeBitWidth(), ArrayBound.getBitWidth()); in VisitCXXNewExpr()
9995 llvm::APInt InitBound = CAT->getSize().zext(Bits); in VisitCXXNewExpr()
10004 << (*ArraySize)->getSourceRange(); in VisitCXXNewExpr()
10017 assert(!AllocType->isArrayType() && in VisitCXXNewExpr()
10018 "array allocation with non-array new"); in VisitCXXNewExpr()
10093 if (auto *AT = AllocType->getAsArrayTypeUnsafe()) in VisitCXXNewExpr()
10098 //===----------------------------------------------------------------------===//
10100 //===----------------------------------------------------------------------===//
10131 assert(!E->isValueDependent()); in EvaluateMemberPointer()
10132 assert(E->isPRValue() && E->getType()->isMemberPointerType()); in EvaluateMemberPointer()
10137 switch (E->getCastKind()) { in VisitCastExpr()
10142 VisitIgnoredValue(E->getSubExpr()); in VisitCastExpr()
10146 if (!Visit(E->getSubExpr())) in VisitCastExpr()
10148 if (E->path_empty()) in VisitCastExpr()
10150 // Base-to-derived member pointer casts store the path in derived-to-base in VisitCastExpr()
10152 // the wrong end of the derived->base arc, so stagger the path by one class. in VisitCastExpr()
10154 for (ReverseIter PathI(E->path_end() - 1), PathE(E->path_begin()); in VisitCastExpr()
10156 assert(!(*PathI)->isVirtual() && "memptr cast through vbase"); in VisitCastExpr()
10157 const CXXRecordDecl *Derived = (*PathI)->getType()->getAsCXXRecordDecl(); in VisitCastExpr()
10161 const Type *FinalTy = E->getType()->castAs<MemberPointerType>()->getClass(); in VisitCastExpr()
10162 if (!Result.castToDerived(FinalTy->getAsCXXRecordDecl())) in VisitCastExpr()
10168 if (!Visit(E->getSubExpr())) in VisitCastExpr()
10170 for (CastExpr::path_const_iterator PathI = E->path_begin(), in VisitCastExpr()
10171 PathE = E->path_end(); PathI != PathE; ++PathI) { in VisitCastExpr()
10172 assert(!(*PathI)->isVirtual() && "memptr cast through vbase"); in VisitCastExpr()
10173 const CXXRecordDecl *Base = (*PathI)->getType()->getAsCXXRecordDecl(); in VisitCastExpr()
10184 return Success(cast<DeclRefExpr>(E->getSubExpr())->getDecl()); in VisitUnaryAddrOf()
10187 //===----------------------------------------------------------------------===//
10189 //===----------------------------------------------------------------------===//
10206 return ZeroInitialization(E, E->getType()); in ZeroInitialization()
10216 return VisitCXXConstructExpr(E, E->getType()); in VisitCXXConstructExpr()
10229 /// Perform zero-initialization on an object of non-union class type.
10231 /// To zero-initialize an object or reference of type T means:
10233 /// -- if T is a (possibly cv-qualified) non-union class type,
10234 /// each non-static data member and each base-class subobject is
10235 /// zero-initialized
10239 assert(!RD->isUnion() && "Expected non-union class type"); in HandleClassZeroInitialization()
10241 Result = APValue(APValue::UninitStruct(), CD ? CD->getNumBases() : 0, in HandleClassZeroInitialization()
10242 std::distance(RD->field_begin(), RD->field_end())); in HandleClassZeroInitialization()
10244 if (RD->isInvalidDecl()) return false; in HandleClassZeroInitialization()
10249 for (CXXRecordDecl::base_class_const_iterator I = CD->bases_begin(), in HandleClassZeroInitialization()
10250 End = CD->bases_end(); I != End; ++I, ++Index) { in HandleClassZeroInitialization()
10251 const CXXRecordDecl *Base = I->getType()->getAsCXXRecordDecl(); in HandleClassZeroInitialization()
10261 for (const auto *I : RD->fields()) { in HandleClassZeroInitialization()
10262 // -- if T is a reference type, no initialization is performed. in HandleClassZeroInitialization()
10263 if (I->isUnnamedBitField() || I->getType()->isReferenceType()) in HandleClassZeroInitialization()
10270 ImplicitValueInitExpr VIE(I->getType()); in HandleClassZeroInitialization()
10272 Result.getStructField(I->getFieldIndex()), Info, Subobject, &VIE)) in HandleClassZeroInitialization()
10280 const RecordDecl *RD = T->castAs<RecordType>()->getDecl(); in ZeroInitialization()
10281 if (RD->isInvalidDecl()) return false; in ZeroInitialization()
10282 if (RD->isUnion()) { in ZeroInitialization()
10283 // C++11 [dcl.init]p5: If T is a (possibly cv-qualified) union type, the in ZeroInitialization()
10284 // object's first non-static named data member is zero-initialized in ZeroInitialization()
10285 RecordDecl::field_iterator I = RD->field_begin(); in ZeroInitialization()
10286 while (I != RD->field_end() && (*I)->isUnnamedBitField()) in ZeroInitialization()
10288 if (I == RD->field_end()) { in ZeroInitialization()
10297 ImplicitValueInitExpr VIE(I->getType()); in ZeroInitialization()
10301 if (isa<CXXRecordDecl>(RD) && cast<CXXRecordDecl>(RD)->getNumVBases()) { in ZeroInitialization()
10310 switch (E->getCastKind()) { in VisitCastExpr()
10315 return Visit(E->getSubExpr()); in VisitCastExpr()
10320 if (!Evaluate(DerivedObject, Info, E->getSubExpr())) in VisitCastExpr()
10323 return Error(E->getSubExpr()); in VisitCastExpr()
10325 // Derived-to-base rvalue conversion: just slice off the derived part. in VisitCastExpr()
10327 const CXXRecordDecl *RD = E->getSubExpr()->getType()->getAsCXXRecordDecl(); in VisitCastExpr()
10328 for (CastExpr::path_const_iterator PathI = E->path_begin(), in VisitCastExpr()
10329 PathE = E->path_end(); PathI != PathE; ++PathI) { in VisitCastExpr()
10330 assert(!(*PathI)->isVirtual() && "record rvalue with virtual base"); in VisitCastExpr()
10331 const CXXRecordDecl *Base = (*PathI)->getType()->getAsCXXRecordDecl(); in VisitCastExpr()
10332 Value = &Value->getStructBase(getBaseIndex(RD, Base)); in VisitCastExpr()
10342 if (E->isTransparent()) in VisitInitListExpr()
10343 return Visit(E->getInit(0)); in VisitInitListExpr()
10344 return VisitCXXParenListOrInitListExpr(E, E->inits()); in VisitInitListExpr()
10350 ExprToVisit->getType()->castAs<RecordType>()->getDecl(); in VisitCXXParenListOrInitListExpr()
10351 if (RD->isInvalidDecl()) return false; in VisitCXXParenListOrInitListExpr()
10358 CXXRD && CXXRD->getNumBases()); in VisitCXXParenListOrInitListExpr()
10360 if (RD->isUnion()) { in VisitCXXParenListOrInitListExpr()
10363 Field = ILE->getInitializedFieldInUnion(); in VisitCXXParenListOrInitListExpr()
10365 Field = PLIE->getInitializedFieldInUnion(); in VisitCXXParenListOrInitListExpr()
10376 // first element of the union is value-initialized. in VisitCXXParenListOrInitListExpr()
10380 ImplicitValueInitExpr VIE(Field->getType()); in VisitCXXParenListOrInitListExpr()
10392 if (Field->isBitField()) in VisitCXXParenListOrInitListExpr()
10402 Result = APValue(APValue::UninitStruct(), CXXRD ? CXXRD->getNumBases() : 0, in VisitCXXParenListOrInitListExpr()
10403 std::distance(RD->field_begin(), RD->field_end())); in VisitCXXParenListOrInitListExpr()
10408 if (CXXRD && CXXRD->getNumBases()) { in VisitCXXParenListOrInitListExpr()
10409 for (const auto &Base : CXXRD->bases()) { in VisitCXXParenListOrInitListExpr()
10430 for (const auto *Field : RD->fields()) { in VisitCXXParenListOrInitListExpr()
10431 // Anonymous bit-fields are not considered members of the class for in VisitCXXParenListOrInitListExpr()
10433 if (Field->isUnnamedBitField()) in VisitCXXParenListOrInitListExpr()
10446 // Perform an implicit value-initialization for members beyond the end of in VisitCXXParenListOrInitListExpr()
10448 ImplicitValueInitExpr VIE(HaveInit ? Info.Ctx.IntTy : Field->getType()); in VisitCXXParenListOrInitListExpr()
10451 if (Field->getType()->isIncompleteArrayType()) { in VisitCXXParenListOrInitListExpr()
10452 if (auto *CAT = Info.Ctx.getAsConstantArrayType(Init->getType())) { in VisitCXXParenListOrInitListExpr()
10453 if (!CAT->isZeroSize()) { in VisitCXXParenListOrInitListExpr()
10466 APValue &FieldVal = Result.getStructField(Field->getFieldIndex()); in VisitCXXParenListOrInitListExpr()
10468 (Field->isBitField() && !truncateBitfieldValue(Info, Init, in VisitCXXParenListOrInitListExpr()
10485 const CXXConstructorDecl *FD = E->getConstructor(); in VisitCXXConstructExpr()
10486 if (FD->isInvalidDecl() || FD->getParent()->isInvalidDecl()) return false; in VisitCXXConstructExpr()
10488 bool ZeroInit = E->requiresZeroInitialization(); in VisitCXXConstructExpr()
10489 if (CheckTrivialDefaultConstructor(Info, E->getExprLoc(), FD, ZeroInit)) { in VisitCXXConstructExpr()
10490 // If we've already performed zero-initialization, we're already done. in VisitCXXConstructExpr()
10501 auto Body = FD->getBody(Definition); in VisitCXXConstructExpr()
10503 if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition, Body)) in VisitCXXConstructExpr()
10507 if (E->isElidable() && !ZeroInit) { in VisitCXXConstructExpr()
10513 const Expr *SrcObj = E->getArg(0); in VisitCXXConstructExpr()
10514 assert(SrcObj->isTemporaryObject(Info.Ctx, FD->getParent())); in VisitCXXConstructExpr()
10515 assert(Info.Ctx.hasSameUnqualifiedType(E->getType(), SrcObj->getType())); in VisitCXXConstructExpr()
10518 return Visit(ME->getSubExpr()); in VisitCXXConstructExpr()
10524 auto Args = llvm::ArrayRef(E->getArgs(), E->getNumArgs()); in VisitCXXConstructExpr()
10537 const CXXConstructorDecl *FD = E->getConstructor(); in VisitCXXInheritedCtorInitExpr()
10538 if (FD->isInvalidDecl() || FD->getParent()->isInvalidDecl()) in VisitCXXInheritedCtorInitExpr()
10542 auto Body = FD->getBody(Definition); in VisitCXXInheritedCtorInitExpr()
10544 if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition, Body)) in VisitCXXInheritedCtorInitExpr()
10547 return HandleConstructorCall(E, This, Info.CurrentCall->Arguments, in VisitCXXInheritedCtorInitExpr()
10555 Info.Ctx.getAsConstantArrayType(E->getSubExpr()->getType()); in VisitCXXStdInitializerListExpr()
10558 if (!EvaluateLValue(E->getSubExpr(), Array, Info)) in VisitCXXStdInitializerListExpr()
10570 RecordDecl *Record = E->getType()->castAs<RecordType>()->getDecl(); in VisitCXXStdInitializerListExpr()
10571 RecordDecl::field_iterator Field = Record->field_begin(); in VisitCXXStdInitializerListExpr()
10572 assert(Field != Record->field_end() && in VisitCXXStdInitializerListExpr()
10573 Info.Ctx.hasSameType(Field->getType()->getPointeeType(), in VisitCXXStdInitializerListExpr()
10574 ArrayType->getElementType()) && in VisitCXXStdInitializerListExpr()
10577 assert(Field != Record->field_end() && in VisitCXXStdInitializerListExpr()
10580 if (Info.Ctx.hasSameType(Field->getType(), Info.Ctx.getSizeType())) { in VisitCXXStdInitializerListExpr()
10582 Result.getStructField(1) = APValue(APSInt(ArrayType->getSize())); in VisitCXXStdInitializerListExpr()
10585 assert(Info.Ctx.hasSameType(Field->getType()->getPointeeType(), in VisitCXXStdInitializerListExpr()
10586 ArrayType->getElementType()) && in VisitCXXStdInitializerListExpr()
10589 ArrayType->getElementType(), in VisitCXXStdInitializerListExpr()
10590 ArrayType->getZExtSize())) in VisitCXXStdInitializerListExpr()
10595 assert(++Field == Record->field_end() && in VisitCXXStdInitializerListExpr()
10602 const CXXRecordDecl *ClosureClass = E->getLambdaClass(); in VisitLambdaExpr()
10603 if (ClosureClass->isInvalidDecl()) in VisitLambdaExpr()
10607 std::distance(ClosureClass->field_begin(), ClosureClass->field_end()); in VisitLambdaExpr()
10609 assert(NumFields == (size_t)std::distance(E->capture_init_begin(), in VisitLambdaExpr()
10610 E->capture_init_end()) && in VisitLambdaExpr()
10617 auto *CaptureInitIt = E->capture_init_begin(); in VisitLambdaExpr()
10620 for (const auto *Field : ClosureClass->fields()) { in VisitLambdaExpr()
10621 assert(CaptureInitIt != E->capture_init_end()); in VisitLambdaExpr()
10635 APValue &FieldVal = Result.getStructField(Field->getFieldIndex()); in VisitLambdaExpr()
10647 assert(!E->isValueDependent()); in EvaluateRecord()
10648 assert(E->isPRValue() && E->getType()->isRecordType() && in EvaluateRecord()
10653 //===----------------------------------------------------------------------===//
10657 // lvalues. The full-object of which the temporary is a subobject is implicitly
10659 //===----------------------------------------------------------------------===//
10669 APValue &Value = Info.CurrentCall->createTemporary( in VisitConstructExpr()
10670 E, E->getType(), ScopeKind::FullExpression, Result); in VisitConstructExpr()
10675 switch (E->getCastKind()) { in VisitCastExpr()
10680 return VisitConstructExpr(E->getSubExpr()); in VisitCastExpr()
10703 assert(!E->isValueDependent()); in EvaluateTemporary()
10704 assert(E->isPRValue() && E->getType()->isRecordType()); in EvaluateTemporary()
10708 //===----------------------------------------------------------------------===//
10710 //===----------------------------------------------------------------------===//
10722 assert(V.size() == E->getType()->castAs<VectorType>()->getNumElements()); in Success()
10735 { return Visit(E->getSubExpr()); } in VisitUnaryReal()
10750 assert(E->isPRValue() && E->getType()->isVectorType() && in EvaluateVector()
10756 const VectorType *VTy = E->getType()->castAs<VectorType>(); in VisitCastExpr()
10757 unsigned NElts = VTy->getNumElements(); in VisitCastExpr()
10759 const Expr *SE = E->getSubExpr(); in VisitCastExpr()
10760 QualType SETy = SE->getType(); in VisitCastExpr()
10762 switch (E->getCastKind()) { in VisitCastExpr()
10765 if (SETy->isIntegerType()) { in VisitCastExpr()
10770 } else if (SETy->isRealFloatingType()) { in VisitCastExpr()
10808 const VectorType *VT = E->getType()->castAs<VectorType>(); in VisitInitListExpr()
10809 unsigned NumInits = E->getNumInits(); in VisitInitListExpr()
10810 unsigned NumElements = VT->getNumElements(); in VisitInitListExpr()
10812 QualType EltTy = VT->getElementType(); in VisitInitListExpr()
10823 && E->getInit(CountInits)->getType()->isVectorType()) { in VisitInitListExpr()
10825 if (!EvaluateVector(E->getInit(CountInits), v, Info)) in VisitInitListExpr()
10831 } else if (EltTy->isIntegerType()) { in VisitInitListExpr()
10834 if (!EvaluateInteger(E->getInit(CountInits), sInt, Info)) in VisitInitListExpr()
10843 if (!EvaluateFloat(E->getInit(CountInits), f, Info)) in VisitInitListExpr()
10857 const auto *VT = E->getType()->castAs<VectorType>(); in ZeroInitialization()
10858 QualType EltTy = VT->getElementType(); in ZeroInitialization()
10860 if (EltTy->isIntegerType()) in ZeroInitialization()
10866 SmallVector<APValue, 4> Elements(VT->getNumElements(), ZeroElement); in ZeroInitialization()
10871 VisitIgnoredValue(E->getSubExpr()); in VisitUnaryImag()
10876 BinaryOperatorKind Op = E->getOpcode(); in VisitBinaryOperator()
10883 Expr *LHS = E->getLHS(); in VisitBinaryOperator()
10884 Expr *RHS = E->getRHS(); in VisitBinaryOperator()
10886 assert(LHS->getType()->isVectorType() && RHS->getType()->isVectorType() && in VisitBinaryOperator()
10890 assert(LHS->getType()->castAs<VectorType>()->getNumElements() == in VisitBinaryOperator()
10891 E->getType()->castAs<VectorType>()->getNumElements() && in VisitBinaryOperator()
10892 RHS->getType()->castAs<VectorType>()->getNumElements() == in VisitBinaryOperator()
10893 E->getType()->castAs<VectorType>()->getNumElements() && in VisitBinaryOperator()
10937 // operator ! on vectors returns -1 for 'truth', so negate it. in handleVectorUnaryOperator()
10943 // Float types result in an int of the same size, but -1 for true, or 0 for in handleVectorUnaryOperator()
10946 ResultTy->isUnsignedIntegerType()}; in handleVectorUnaryOperator()
10961 Expr *SubExpr = E->getSubExpr(); in VisitUnaryOperator()
10962 const auto *VD = SubExpr->getType()->castAs<VectorType>(); in VisitUnaryOperator()
10966 const QualType ResultEltTy = VD->getElementType(); in VisitUnaryOperator()
10967 UnaryOperatorKind Op = E->getOpcode(); in VisitUnaryOperator()
10982 assert(SubExprValue.getVectorLength() == VD->getNumElements() && in VisitUnaryOperator()
10986 for (unsigned EltNum = 0; EltNum < VD->getNumElements(); ++EltNum) { in VisitUnaryOperator()
11000 if (SourceTy->isIntegerType()) { in handleVectorElementCast()
11001 if (DestTy->isRealFloatingType()) { in handleVectorElementCast()
11006 if (DestTy->isIntegerType()) { in handleVectorElementCast()
11011 } else if (SourceTy->isRealFloatingType()) { in handleVectorElementCast()
11012 if (DestTy->isRealFloatingType()) { in handleVectorElementCast()
11017 if (DestTy->isIntegerType()) { in handleVectorElementCast()
11031 QualType SourceVecType = E->getSrcExpr()->getType(); in VisitConvertVectorExpr()
11032 if (!EvaluateAsRValue(Info, E->getSrcExpr(), Source)) in VisitConvertVectorExpr()
11035 QualType DestTy = E->getType()->castAs<VectorType>()->getElementType(); in VisitConvertVectorExpr()
11036 QualType SourceTy = SourceVecType->castAs<VectorType>()->getElementType(); in VisitConvertVectorExpr()
11038 const FPOptions FPO = E->getFPFeaturesInEffect(Info.Ctx.getLangOpts()); in VisitConvertVectorExpr()
11061 APSInt IndexVal = E->getShuffleMaskIdx(Info.Ctx, EltNum); in handleVectorShuffle()
11063 // The spec says that -1 should be treated as undef for optimizations, in handleVectorShuffle()
11065 // which is prohibited from being a top-level constant value. Emit a in handleVectorShuffle()
11067 if (index == -1) { in handleVectorShuffle()
11079 Result = VecVal2.getVectorElt(index - TotalElementsInInputVector1); in handleVectorShuffle()
11087 const Expr *Vec1 = E->getExpr(0); in VisitShuffleVectorExpr()
11091 const Expr *Vec2 = E->getExpr(1); in VisitShuffleVectorExpr()
11095 VectorType const *DestVecTy = E->getType()->castAs<VectorType>(); in VisitShuffleVectorExpr()
11096 QualType DestElTy = DestVecTy->getElementType(); in VisitShuffleVectorExpr()
11098 auto TotalElementsInOutputVector = DestVecTy->getNumElements(); in VisitShuffleVectorExpr()
11112 //===----------------------------------------------------------------------===//
11114 //===----------------------------------------------------------------------===//
11134 Info.Ctx.getAsConstantArrayType(E->getType()); in ZeroInitialization()
11136 if (E->getType()->isIncompleteArrayType()) { in ZeroInitialization()
11137 // We can be asked to zero-initialize a flexible array member; this in ZeroInitialization()
11147 Result = APValue(APValue::UninitArray(), 0, CAT->getZExtSize()); in ZeroInitialization()
11151 // Zero-initialize all elements. in ZeroInitialization()
11154 ImplicitValueInitExpr VIE(CAT->getElementType()); in ZeroInitialization()
11183 assert(!E->isValueDependent()); in EvaluateArray()
11184 assert(E->isPRValue() && E->getType()->isArrayType() && in EvaluateArray()
11192 assert(!ILE->isValueDependent()); in EvaluateArrayNewInitList()
11193 assert(ILE->isPRValue() && ILE->getType()->isArrayType() && in EvaluateArrayNewInitList()
11203 assert(!CCE->isValueDependent()); in EvaluateArrayNewConstructExpr()
11204 assert(CCE->isPRValue() && CCE->getType()->isArrayType() && in EvaluateArrayNewConstructExpr()
11212 // For now, just allow non-class value-initialization and initialization in MaybeElementDependentArrayFiller()
11217 for (unsigned I = 0, E = ILE->getNumInits(); I != E; ++I) { in MaybeElementDependentArrayFiller()
11218 if (MaybeElementDependentArrayFiller(ILE->getInit(I))) in MaybeElementDependentArrayFiller()
11222 if (ILE->hasArrayFiller() && in MaybeElementDependentArrayFiller()
11223 MaybeElementDependentArrayFiller(ILE->getArrayFiller())) in MaybeElementDependentArrayFiller()
11234 AllocType.isNull() ? E->getType() : AllocType); in VisitInitListExpr()
11239 // an appropriately-typed string literal enclosed in braces. in VisitInitListExpr()
11240 if (E->isStringLiteralInit()) { in VisitInitListExpr()
11241 auto *SL = dyn_cast<StringLiteral>(E->getInit(0)->IgnoreParenImpCasts()); in VisitInitListExpr()
11250 assert(!E->isTransparent() && in VisitInitListExpr()
11253 return VisitCXXParenListOrInitListExpr(E, E->inits(), E->getArrayFiller(), in VisitInitListExpr()
11261 AllocType.isNull() ? ExprToVisit->getType() : AllocType); in VisitCXXParenListOrInitListExpr()
11266 "zero-initialized array shouldn't have any initialized elts"); in VisitCXXParenListOrInitListExpr()
11272 unsigned NumElts = CAT->getZExtSize(); in VisitCXXParenListOrInitListExpr()
11281 if (auto *EmbedS = dyn_cast<EmbedExpr>(Init->IgnoreParenImpCasts())) in VisitCXXParenListOrInitListExpr()
11282 NumEltsToInit += EmbedS->getDataElementCount() - 1; in VisitCXXParenListOrInitListExpr()
11293 // If the array was previously zero-initialized, preserve the in VisitCXXParenListOrInitListExpr()
11294 // zero-initialized values. in VisitCXXParenListOrInitListExpr()
11308 CAT->getElementType(), 1)) { in VisitCXXParenListOrInitListExpr()
11316 QualType DestTy = CAT->getElementType(); in VisitCXXParenListOrInitListExpr()
11317 APSInt Value(Info.Ctx.getTypeSize(DestTy), DestTy->isUnsignedIntegerType()); in VisitCXXParenListOrInitListExpr()
11322 if (auto *EmbedS = dyn_cast<EmbedExpr>(Init->IgnoreParenImpCasts())) { in VisitCXXParenListOrInitListExpr()
11323 StringLiteral *SL = EmbedS->getDataStringLiteral(); in VisitCXXParenListOrInitListExpr()
11324 for (unsigned I = EmbedS->getStartingElementPos(), in VisitCXXParenListOrInitListExpr()
11325 N = EmbedS->getDataElementCount(); in VisitCXXParenListOrInitListExpr()
11326 I != EmbedS->getStartingElementPos() + N; ++I) { in VisitCXXParenListOrInitListExpr()
11327 Value = SL->getCodeUnit(I); in VisitCXXParenListOrInitListExpr()
11328 if (DestTy->isIntegerType()) { in VisitCXXParenListOrInitListExpr()
11331 assert(DestTy->isFloatingType() && "unexpected type"); in VisitCXXParenListOrInitListExpr()
11333 Init->getFPFeaturesInEffect(Info.Ctx.getLangOpts()); in VisitCXXParenListOrInitListExpr()
11335 if (!HandleIntToFloatCast(Info, Init, FPO, EmbedS->getType(), Value, in VisitCXXParenListOrInitListExpr()
11362 if (E->getCommonExpr() && in VisitArrayInitLoopExpr()
11363 !Evaluate(Info.CurrentCall->createTemporary( in VisitArrayInitLoopExpr()
11364 E->getCommonExpr(), in VisitArrayInitLoopExpr()
11365 getStorageType(Info.Ctx, E->getCommonExpr()), in VisitArrayInitLoopExpr()
11367 Info, E->getCommonExpr()->getSourceExpr())) in VisitArrayInitLoopExpr()
11370 auto *CAT = cast<ConstantArrayType>(E->getType()->castAsArrayTypeUnsafe()); in VisitArrayInitLoopExpr()
11372 uint64_t Elements = CAT->getZExtSize(); in VisitArrayInitLoopExpr()
11382 // point than the end of the full-expression. [...] The second context is in VisitArrayInitLoopExpr()
11391 Info, Subobject, E->getSubExpr()) || in VisitArrayInitLoopExpr()
11393 CAT->getElementType(), 1)) { in VisitArrayInitLoopExpr()
11407 return VisitCXXConstructExpr(E, This, &Result, E->getType()); in VisitCXXConstructExpr()
11414 bool HadZeroInit = Value->hasValue(); in VisitCXXConstructExpr()
11417 unsigned FinalSize = CAT->getZExtSize(); in VisitCXXConstructExpr()
11419 // Preserve the array filler if we had prior zero-initialization. in VisitCXXConstructExpr()
11421 HadZeroInit && Value->hasArrayFiller() ? Value->getArrayFiller() in VisitCXXConstructExpr()
11429 Info, E->getExprLoc(), E->getConstructor(), in VisitCXXConstructExpr()
11430 E->requiresZeroInitialization()); in VisitCXXConstructExpr()
11439 unsigned OldElts = Value->getArrayInitializedElts(); in VisitCXXConstructExpr()
11447 Value->getArrayInitializedElt(I)); in VisitCXXConstructExpr()
11448 Value->swap(NewValue); in VisitCXXConstructExpr()
11452 Value->getArrayInitializedElt(I) = Filler; in VisitCXXConstructExpr()
11457 APValue &FirstResult = Value->getArrayInitializedElt(0); in VisitCXXConstructExpr()
11459 Value->getArrayInitializedElt(I) = FirstResult; in VisitCXXConstructExpr()
11463 &Value->getArrayInitializedElt(I), in VisitCXXConstructExpr()
11464 CAT->getElementType()) || in VisitCXXConstructExpr()
11466 CAT->getElementType(), 1)) in VisitCXXConstructExpr()
11470 if (Info.EvalStatus.Diag && !Info.EvalStatus.Diag->empty() && in VisitCXXConstructExpr()
11480 if (!Type->isRecordType()) in VisitCXXConstructExpr()
11489 assert(E->getType()->isConstantArrayType() && in VisitCXXParenListInitExpr()
11492 return VisitCXXParenListOrInitListExpr(E, E->getInitExprs(), in VisitCXXParenListInitExpr()
11493 E->getArrayFiller()); in VisitCXXParenListInitExpr()
11496 //===----------------------------------------------------------------------===//
11499 // As a GNU extension, we support casting pointers to sufficiently-wide integer
11501 // either as an integer-valued APValue, or as an lvalue-valued APValue.
11502 //===----------------------------------------------------------------------===//
11513 assert(E->getType()->isIntegralOrEnumerationType() && in Success()
11515 assert(SI.isSigned() == E->getType()->isSignedIntegerOrEnumerationType() && in Success()
11517 assert(SI.getBitWidth() == Info.Ctx.getIntWidth(E->getType()) && in Success()
11527 assert(E->getType()->isIntegralOrEnumerationType() && in Success()
11529 assert(I.getBitWidth() == Info.Ctx.getIntWidth(E->getType()) && in Success()
11533 E->getType()->isUnsignedIntegerOrEnumerationType()); in Success()
11541 assert(E->getType()->isIntegralOrEnumerationType() && in Success()
11543 Result = APValue(Info.Ctx.MakeIntValue(Value, E->getType())); in Success()
11564 //===--------------------------------------------------------------------===//
11566 //===--------------------------------------------------------------------===//
11569 return Success(E->getValue(), E); in VisitIntegerLiteral()
11572 return Success(E->getValue(), E); in VisitCharacterLiteral()
11577 if (CheckReferencedDecl(E, E->getDecl())) in VisitDeclRefExpr()
11583 if (CheckReferencedDecl(E, E->getMemberDecl())) { in VisitMemberExpr()
11584 VisitIgnoredBaseExpression(E->getBase()); in VisitMemberExpr()
11601 return Success(E->getValue(), E); in VisitCXXBoolLiteralExpr()
11605 return Success(E->getValue(), E); in VisitObjCBoolLiteralExpr()
11609 if (Info.ArrayInitIndex == uint64_t(-1)) { in VisitArrayInitIndexExpr()
11624 return Success(E->getValue(), E); in VisitTypeTraitExpr()
11628 return Success(E->getValue(), E); in VisitArrayTypeTraitExpr()
11632 return Success(E->getValue(), E); in VisitExpressionTraitExpr()
11656 APFixedPoint(I, Info.Ctx.getFixedPointSemantics(E->getType())), E); in Success()
11661 APFixedPoint(Value, Info.Ctx.getFixedPointSemantics(E->getType())), E); in Success()
11669 assert(E->getType()->isFixedPointType() && "Invalid evaluation result."); in Success()
11670 assert(V.getWidth() == Info.Ctx.getIntWidth(E->getType()) && in Success()
11680 //===--------------------------------------------------------------------===//
11682 //===--------------------------------------------------------------------===//
11685 return Success(E->getValue(), E); in VisitFixedPointLiteral()
11694 /// EvaluateIntegerOrLValue - Evaluate an rvalue integral-typed expression, and
11698 /// pointer-sized integral types. We support this by allowing the evaluation of
11704 assert(!E->isValueDependent()); in EvaluateIntegerOrLValue()
11705 assert(E->isPRValue() && E->getType()->isIntegralOrEnumerationType()); in EvaluateIntegerOrLValue()
11710 assert(!E->isValueDependent()); in EvaluateInteger()
11725 APValue Evaluated = E->EvaluateInContext( in VisitSourceLocExpr()
11726 Info.Ctx, Info.CurrentCall->CurSourceLocExprScope.getDefaultExpr()); in VisitSourceLocExpr()
11732 assert(!E->isValueDependent()); in EvaluateFixedPoint()
11733 if (E->getType()->isFixedPointType()) { in EvaluateFixedPoint()
11748 assert(!E->isValueDependent()); in EvaluateFixedPointOrInteger()
11749 if (E->getType()->isIntegerType()) { in EvaluateFixedPointOrInteger()
11750 auto FXSema = Info.Ctx.getFixedPointSemantics(E->getType()); in EvaluateFixedPointOrInteger()
11756 } else if (E->getType()->isFixedPointType()) { in EvaluateFixedPointOrInteger()
11769 bool SameSign = (ECD->getInitVal().isSigned() in CheckReferencedDecl()
11770 == E->getType()->isSignedIntegerOrEnumerationType()); in CheckReferencedDecl()
11771 bool SameWidth = (ECD->getInitVal().getBitWidth() in CheckReferencedDecl()
11772 == Info.Ctx.getIntWidth(E->getType())); in CheckReferencedDecl()
11774 return Success(ECD->getInitVal(), E); in CheckReferencedDecl()
11778 llvm::APSInt Val = ECD->getInitVal(); in CheckReferencedDecl()
11780 Val.setIsSigned(!ECD->getInitVal().isSigned()); in CheckReferencedDecl()
11782 Val = Val.extOrTrunc(Info.Ctx.getIntWidth(E->getType())); in CheckReferencedDecl()
11789 /// EvaluateBuiltinClassifyType - Evaluate __builtin_classify_type the same way
11793 assert(!T->isDependentType() && "unexpected dependent type"); in EvaluateBuiltinClassifyType()
11797 switch (CanTy->getTypeClass()) { in EvaluateBuiltinClassifyType()
11805 llvm_unreachable("unexpected non-canonical or dependent type"); in EvaluateBuiltinClassifyType()
11808 switch (cast<BuiltinType>(CanTy)->getKind()) { in EvaluateBuiltinClassifyType()
11898 return CanTy->isMemberDataPointerType() in EvaluateBuiltinClassifyType()
11906 return CanTy->isUnionType() ? GCCTypeClass::Union in EvaluateBuiltinClassifyType()
11912 CanTy->castAs<AtomicType>()->getValueType(), LangOpts); in EvaluateBuiltinClassifyType()
11939 /// EvaluateBuiltinClassifyType - Evaluate __builtin_classify_type the same way
11945 if (E->getNumArgs() == 0) in EvaluateBuiltinClassifyType()
11951 return EvaluateBuiltinClassifyType(E->getArg(0)->getType(), LangOpts); in EvaluateBuiltinClassifyType()
11954 /// EvaluateBuiltinConstantPForLValue - Determine the result of
11978 /// EvaluateBuiltinConstantP - Evaluate __builtin_constant_p as similarly to
11981 // This evaluation is not permitted to have side-effects, so evaluate it in in EvaluateBuiltinConstantP()
11985 // Constant-folding is always enabled for the operand of __builtin_constant_p in EvaluateBuiltinConstantP()
11987 // language-specific constant expression). in EvaluateBuiltinConstantP()
11990 QualType ArgType = Arg->getType(); in EvaluateBuiltinConstantP()
11995 // - If the operand is of integral, floating, complex or enumeration type, in EvaluateBuiltinConstantP()
11997 // - If the operand can be folded to a pointer to the first character in EvaluateBuiltinConstantP()
12006 if (ArgType->isIntegralOrEnumerationType() || ArgType->isFloatingType() || in EvaluateBuiltinConstantP()
12007 ArgType->isAnyComplexType() || ArgType->isPointerType() || in EvaluateBuiltinConstantP()
12008 ArgType->isNullPtrType()) { in EvaluateBuiltinConstantP()
12032 return VD->getType(); in getObjectType()
12035 return E->getType(); in getObjectType()
12045 /// A more selective version of E->IgnoreParenCasts for
12052 assert(E->isPRValue() && E->getType()->hasPointerRepresentation()); in ignorePointerCastsAndParens()
12054 const Expr *NoParens = E->IgnoreParens(); in ignorePointerCastsAndParens()
12061 auto CastKind = Cast->getCastKind(); in ignorePointerCastsAndParens()
12066 const auto *SubExpr = Cast->getSubExpr(); in ignorePointerCastsAndParens()
12067 if (!SubExpr->getType()->hasPointerRepresentation() || !SubExpr->isPRValue()) in ignorePointerCastsAndParens()
12091 const RecordDecl *Parent = FD->getParent(); in isDesignatorAtObjectEnd()
12092 Invalid = Parent->isInvalidDecl(); in isDesignatorAtObjectEnd()
12093 if (Invalid || Parent->isUnion()) in isDesignatorAtObjectEnd()
12096 return FD->getFieldIndex() + 1 == Layout.getFieldCount(); in isDesignatorAtObjectEnd()
12101 if (auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) { in isDesignatorAtObjectEnd()
12105 } else if (auto *IFD = dyn_cast<IndirectFieldDecl>(ME->getMemberDecl())) { in isDesignatorAtObjectEnd()
12106 for (auto *FD : IFD->chain()) { in isDesignatorAtObjectEnd()
12120 if (BaseType->isIncompleteArrayType()) in isDesignatorAtObjectEnd()
12121 BaseType = Ctx.getAsArrayType(BaseType)->getElementType(); in isDesignatorAtObjectEnd()
12123 BaseType = BaseType->castAs<PointerType>()->getPointeeType(); in isDesignatorAtObjectEnd()
12128 if (BaseType->isArrayType()) { in isDesignatorAtObjectEnd()
12135 if (Index + 1 != CAT->getZExtSize()) in isDesignatorAtObjectEnd()
12137 BaseType = CAT->getElementType(); in isDesignatorAtObjectEnd()
12138 } else if (BaseType->isAnyComplexType()) { in isDesignatorAtObjectEnd()
12139 const auto *CT = BaseType->castAs<ComplexType>(); in isDesignatorAtObjectEnd()
12143 BaseType = CT->getElementType(); in isDesignatorAtObjectEnd()
12148 BaseType = FD->getType(); in isDesignatorAtObjectEnd()
12157 /// Tests to see if the LValue has a user-specified designator (that isn't
12182 // - Users can only write off of the end when we have an invalid base. Invalid in isUserWritingOffTheEnd()
12184 // - We used to be a bit more aggressive here; we'd only be conservative if in isUserWritingOffTheEnd()
12235 if (!T.isNull() && T->isStructureType() && in addFlexibleArrayMemberInitSize()
12236 T->getAsStructureType()->getDecl()->hasFlexibleArrayMember()) in addFlexibleArrayMemberInitSize()
12239 if (VD->hasInit()) in addFlexibleArrayMemberInitSize()
12240 Size += VD->getFlexibleArrayInitChars(Info.Ctx); in addFlexibleArrayMemberInitSize()
12243 /// Helper for tryEvaluateBuiltinObjectSize -- Given an LValue, this will
12255 if (Ty.isNull() || Ty->isIncompleteType() || Ty->isFunctionType()) in determineEndOffset()
12262 // upper-bound. in determineEndOffset()
12289 // strcpy(&F->c[0], Bar); in determineEndOffset()
12301 // given an accurate upper-bound. However, we are still able to give in determineEndOffset()
12302 // conservative lower-bounds for Type=3. in determineEndOffset()
12312 // denoted by the pointer. But that's not quite right -- what we actually in determineEndOffset()
12313 // want is the size of the immediately-enclosing array, if there is one. in determineEndOffset()
12319 ElemsRemaining = ArraySize <= ArrayIndex ? 0 : ArraySize - ArrayIndex; in determineEndOffset()
12331 /// If @p WasError is non-null, this will report whether the failure to evaluate
12338 // The operand of __builtin_object_size is never evaluated for side-effects. in tryEvaluateBuiltinObjectSize()
12339 // If there are any, but we can determine the pointed-to object anyway, then in tryEvaluateBuiltinObjectSize()
12340 // ignore the side-effects. in tryEvaluateBuiltinObjectSize()
12344 if (E->isGLValue()) { in tryEvaluateBuiltinObjectSize()
12364 if (!determineEndOffset(Info, E->getExprLoc(), Type, LVal, EndOffset)) in tryEvaluateBuiltinObjectSize()
12372 Size = (EndOffset - LVal.getLValueOffset()).getQuantity(); in tryEvaluateBuiltinObjectSize()
12379 return VisitBuiltinCallExpr(E, E->getBuiltinCallee()); in VisitCallExpr()
12384 QualType SrcTy = E->getArg(0)->getType(); in getBuiltinAlignArguments()
12385 if (!getAlignmentArgument(E->getArg(1), SrcTy, Info, Alignment)) in getBuiltinAlignArguments()
12389 if (SrcTy->isPointerType()) { in getBuiltinAlignArguments()
12391 if (!EvaluatePointer(E->getArg(0), Ptr, Info)) in getBuiltinAlignArguments()
12394 } else if (!SrcTy->isIntegralOrEnumerationType()) { in getBuiltinAlignArguments()
12395 Info.FFDiag(E->getArg(0)); in getBuiltinAlignArguments()
12399 if (!EvaluateInteger(E->getArg(0), SrcInt, Info)) in getBuiltinAlignArguments()
12419 E->getArg(1)->EvaluateKnownConstInt(Info.Ctx).getZExtValue(); in VisitBuiltinCallExpr()
12423 if (tryEvaluateBuiltinObjectSize(E->getArg(0), Type, Info, Size)) in VisitBuiltinCallExpr()
12426 if (E->getArg(0)->HasSideEffects(Info.Ctx)) in VisitBuiltinCallExpr()
12427 return Success((Type & 2) ? 0 : -1, E); in VisitBuiltinCallExpr()
12439 return Success((Type & 2) ? 0 : -1, E); in VisitBuiltinCallExpr()
12471 // the run-time value can never be aligned. in VisitBuiltinCallExpr()
12478 Info.FFDiag(E->getArg(0), diag::note_constexpr_alignment_compute) in VisitBuiltinCallExpr()
12483 return Success((Src.getInt() & (Alignment - 1)) == 0 ? 1 : 0, E); in VisitBuiltinCallExpr()
12493 APSInt((Src.getInt() + (Alignment - 1)) & ~(Alignment - 1), in VisitBuiltinCallExpr()
12506 APSInt(Src.getInt() & ~(Alignment - 1), Src.getInt().isUnsigned()); in VisitBuiltinCallExpr()
12516 if (!EvaluateInteger(E->getArg(0), Val, Info)) in VisitBuiltinCallExpr()
12526 if (!EvaluateInteger(E->getArg(0), Val, Info)) in VisitBuiltinCallExpr()
12539 if (!EvaluateInteger(E->getArg(0), Val, Info)) in VisitBuiltinCallExpr()
12542 return Success(Val.getBitWidth() - Val.getSignificantBits(), E); in VisitBuiltinCallExpr()
12550 case Builtin::BI__lzcnt16: // Microsoft variants of count leading-zeroes in VisitBuiltinCallExpr()
12554 if (!EvaluateInteger(E->getArg(0), Val, Info)) in VisitBuiltinCallExpr()
12558 if (BuiltinOp == Builtin::BI__builtin_clzg && E->getNumArgs() > 1) { in VisitBuiltinCallExpr()
12560 if (!EvaluateInteger(E->getArg(1), FallbackTemp, Info)) in VisitBuiltinCallExpr()
12570 // whereas for Microsoft intrinsics, the result is the bit-width of the in VisitBuiltinCallExpr()
12584 const Expr *Arg = E->getArg(0); in VisitBuiltinCallExpr()
12587 if (Info.InConstantContext || Arg->HasSideEffects(Info.Ctx)) { in VisitBuiltinCallExpr()
12589 // of side-effects in order to avoid -Wunsequenced false-positives in in VisitBuiltinCallExpr()
12598 const auto *Callee = Info.CurrentCall->getCallee(); in VisitBuiltinCallExpr()
12601 (Info.CallStackDepth == 2 && Callee->isInStdNamespace() && in VisitBuiltinCallExpr()
12602 Callee->getIdentifier() && in VisitBuiltinCallExpr()
12603 Callee->getIdentifier()->isStr("is_constant_evaluated")))) { in VisitBuiltinCallExpr()
12607 ? E->getExprLoc() in VisitBuiltinCallExpr()
12608 : Info.CurrentCall->getCallRange().getBegin(), in VisitBuiltinCallExpr()
12623 if (!EvaluateInteger(E->getArg(0), Val, Info)) in VisitBuiltinCallExpr()
12627 if (BuiltinOp == Builtin::BI__builtin_ctzg && E->getNumArgs() > 1) { in VisitBuiltinCallExpr()
12629 if (!EvaluateInteger(E->getArg(1), FallbackTemp, Info)) in VisitBuiltinCallExpr()
12645 int Operand = E->getArg(0)->EvaluateKnownConstInt(Info.Ctx).getZExtValue(); in VisitBuiltinCallExpr()
12652 return Visit(E->getArg(0)); in VisitBuiltinCallExpr()
12656 cast<StringLiteral>(E->getArg(0)->IgnoreParenImpCasts()); in VisitBuiltinCallExpr()
12657 uint64_t Result = getPointerAuthStableSipHash(Literal->getString()); in VisitBuiltinCallExpr()
12665 if (!EvaluateInteger(E->getArg(0), Val, Info)) in VisitBuiltinCallExpr()
12674 if (!EvaluateFloat(E->getArg(5), Val, Info)) in VisitBuiltinCallExpr()
12683 return Visit(E->getArg(Arg)); in VisitBuiltinCallExpr()
12688 return EvaluateFloat(E->getArg(0), Val, Info) && in VisitBuiltinCallExpr()
12689 Success(Val.isInfinity() ? (Val.isNegative() ? -1 : 1) : 0, E); in VisitBuiltinCallExpr()
12694 return EvaluateFloat(E->getArg(0), Val, Info) && in VisitBuiltinCallExpr()
12700 return EvaluateFloat(E->getArg(0), Val, Info) && in VisitBuiltinCallExpr()
12706 return EvaluateFloat(E->getArg(0), Val, Info) && in VisitBuiltinCallExpr()
12712 return EvaluateFloat(E->getArg(0), Val, Info) && in VisitBuiltinCallExpr()
12718 return EvaluateFloat(E->getArg(0), Val, Info) && in VisitBuiltinCallExpr()
12724 return EvaluateFloat(E->getArg(0), Val, Info) && in VisitBuiltinCallExpr()
12730 return EvaluateFloat(E->getArg(0), Val, Info) && in VisitBuiltinCallExpr()
12736 if (!EvaluateInteger(E->getArg(1), MaskVal, Info)) in VisitBuiltinCallExpr()
12740 return EvaluateFloat(E->getArg(0), Val, Info) && in VisitBuiltinCallExpr()
12748 if (!EvaluateInteger(E->getArg(0), Val, Info)) in VisitBuiltinCallExpr()
12762 if (!EvaluateInteger(E->getArg(0), Val, Info)) in VisitBuiltinCallExpr()
12778 if (!EvaluateInteger(E->getArg(0), Val, Info) || in VisitBuiltinCallExpr()
12779 !EvaluateInteger(E->getArg(1), Amt, Info)) in VisitBuiltinCallExpr()
12795 if (!EvaluateInteger(E->getArg(0), Val, Info) || in VisitBuiltinCallExpr()
12796 !EvaluateInteger(E->getArg(1), Amt, Info)) in VisitBuiltinCallExpr()
12817 if (EvaluateBuiltinStrLen(E->getArg(0), StrLen, Info)) in VisitBuiltinCallExpr()
12845 if (!EvaluatePointer(E->getArg(0), String1, Info) || in VisitBuiltinCallExpr()
12846 !EvaluatePointer(E->getArg(1), String2, Info)) in VisitBuiltinCallExpr()
12849 uint64_t MaxLength = uint64_t(-1); in VisitBuiltinCallExpr()
12855 if (!EvaluateInteger(E->getArg(2), N, Info)) in VisitBuiltinCallExpr()
12879 CharTy1, E->getArg(0)->getType()->getPointeeType()) && in VisitBuiltinCallExpr()
12916 for (; MaxLength; --MaxLength) { in VisitBuiltinCallExpr()
12922 return Success(Char1.getInt() < Char2.getInt() ? -1 : 1, E); in VisitBuiltinCallExpr()
12924 return Success(Char1.getInt().ult(Char2.getInt()) ? -1 : 1, E); in VisitBuiltinCallExpr()
12940 if (!EvaluateInteger(E->getArg(0), SizeVal, Info)) in VisitBuiltinCallExpr()
12945 // is lock-free. If the size isn't a power of two, or greater than the in VisitBuiltinCallExpr()
12946 // maximum alignment where we promote atomics, we know it is not lock-free in VisitBuiltinCallExpr()
12948 // the answer can only be determined at runtime; for example, 16-byte in VisitBuiltinCallExpr()
12949 // atomics have lock-free implementations on some, but not all, in VisitBuiltinCallExpr()
12950 // x86-64 processors. in VisitBuiltinCallExpr()
12952 // Check power-of-two. in VisitBuiltinCallExpr()
12963 // If the pointer argument can be evaluated to a compile-time constant in VisitBuiltinCallExpr()
12965 const Expr *PtrArg = E->getArg(1); in VisitBuiltinCallExpr()
12968 if (PtrArg->EvaluateAsRValue(ExprResult, Info.Ctx) && in VisitBuiltinCallExpr()
12969 ExprResult.Val.toIntegralConstant(IntResult, PtrArg->getType(), in VisitBuiltinCallExpr()
12976 // Drop the potential implicit-cast to 'const volatile void*', getting in VisitBuiltinCallExpr()
12978 if (ICE->getCastKind() == CK_BitCast) in VisitBuiltinCallExpr()
12979 PtrArg = ICE->getSubExpr(); in VisitBuiltinCallExpr()
12982 if (auto PtrTy = PtrArg->getType()->getAs<PointerType>()) { in VisitBuiltinCallExpr()
12983 QualType PointeeType = PtrTy->getPointeeType(); in VisitBuiltinCallExpr()
12984 if (!PointeeType->isIncompleteType() && in VisitBuiltinCallExpr()
13008 QualType ResultType = E->getArg(0)->getType(); in VisitBuiltinCallExpr()
13009 if (!EvaluateInteger(E->getArg(0), LHS, Info) || in VisitBuiltinCallExpr()
13010 !EvaluateInteger(E->getArg(1), RHS, Info) || in VisitBuiltinCallExpr()
13011 !EvaluateInteger(E->getArg(2), CarryIn, Info) || in VisitBuiltinCallExpr()
13012 !EvaluatePointer(E->getArg(3), CarryOutLValue, Info)) in VisitBuiltinCallExpr()
13073 QualType ResultType = E->getArg(2)->getType()->getPointeeType(); in VisitBuiltinCallExpr()
13074 if (!EvaluateInteger(E->getArg(0), LHS, Info) || in VisitBuiltinCallExpr()
13075 !EvaluateInteger(E->getArg(1), RHS, Info) || in VisitBuiltinCallExpr()
13076 !EvaluatePointer(E->getArg(2), ResultLValue, Info)) in VisitBuiltinCallExpr()
13087 ResultType->isSignedIntegerOrEnumerationType(); in VisitBuiltinCallExpr()
13089 ResultType->isSignedIntegerOrEnumerationType(); in VisitBuiltinCallExpr()
13098 // caught in the shrink-to-result later anyway. in VisitBuiltinCallExpr()
13151 // type-size of the result, so getTypeSize(ResultType) <= Result.BitWidth in VisitBuiltinCallExpr()
13154 Temp.setIsSigned(ResultType->isSignedIntegerOrEnumerationType()); in VisitBuiltinCallExpr()
13184 // A pointer to an incomplete type might be past-the-end if the type's size is in isOnePastTheEndOfCompleteObject()
13187 if (Ty->isIncompleteType()) in isOnePastTheEndOfCompleteObject()
13194 // We're a past-the-end pointer if we point to the byte after the object, in isOnePastTheEndOfCompleteObject()
13252 return E->getOpcode() == BO_Comma || E->isLogicalOp() || in shouldEnqueue()
13253 (E->isPRValue() && E->getType()->isIntegralOrEnumerationType() && in shouldEnqueue()
13254 E->getLHS()->getType()->isIntegralOrEnumerationType() && in shouldEnqueue()
13255 E->getRHS()->getType()->isIntegralOrEnumerationType()); in shouldEnqueue()
13304 E = E->IgnoreParens(); in enqueue()
13316 if (E->getOpcode() == BO_Comma) { in VisitBinOpLHSOnly()
13323 if (E->isLogicalOp()) { in VisitBinOpLHSOnly()
13327 // evaluating the RHS: 0 && X -> 0, 1 || X -> 1 in VisitBinOpLHSOnly()
13328 if (LHSAsBool == (E->getOpcode() == BO_LOr)) { in VisitBinOpLHSOnly()
13341 // is determined by the RHS: X && 0 -> 0, X || 1 -> 1. in VisitBinOpLHSOnly()
13349 assert(E->getLHS()->getType()->isIntegralOrEnumerationType() && in VisitBinOpLHSOnly()
13350 E->getRHS()->getType()->isIntegralOrEnumerationType()); in VisitBinOpLHSOnly()
13361 // FIXME: When compiling for a 32-bit target, we should use 32-bit in addOrSubLValueAsInteger()
13367 Offset = CharUnits::fromQuantity(IsSub ? Offset64 - Index64 in addOrSubLValueAsInteger()
13374 if (E->getOpcode() == BO_Comma) { in VisitBinOp()
13381 if (E->isLogicalOp()) { in VisitBinOp()
13388 if (E->getOpcode() == BO_LOr) in VisitBinOp()
13396 // is determined by the RHS: X && 0 -> 0, X || 1 -> 1. in VisitBinOp()
13397 if (rhsResult == (E->getOpcode() == BO_LOr)) in VisitBinOp()
13405 assert(E->getLHS()->getType()->isIntegralOrEnumerationType() && in VisitBinOp()
13406 E->getRHS()->getType()->isIntegralOrEnumerationType()); in VisitBinOp()
13415 if (E->isAdditiveOp() && LHSVal.isLValue() && RHSVal.isInt()) { in VisitBinOp()
13417 addOrSubLValueAsInteger(Result, RHSVal.getInt(), E->getOpcode() == BO_Sub); in VisitBinOp()
13422 if (E->getOpcode() == BO_Add && in VisitBinOp()
13429 if (E->getOpcode() == BO_Sub && LHSVal.isLValue() && RHSVal.isLValue()) { in VisitBinOp()
13430 // Handle (intptr_t)&&A - (intptr_t)&&B. in VisitBinOp()
13443 if (LHSAddrExpr->getLabel()->getDeclContext() != in VisitBinOp()
13444 RHSAddrExpr->getLabel()->getDeclContext()) in VisitBinOp()
13457 APSInt Value(Info.Ctx.getIntWidth(E->getType()), in VisitBinOp()
13458 E->getType()->isUnsignedIntegerOrEnumerationType()); in VisitBinOp()
13459 if (!handleIntIntBinOp(Info, E, LHSVal.getInt(), E->getOpcode(), in VisitBinOp()
13473 enqueue(Bop->getLHS()); in process()
13494 enqueue(Bop->getRHS()); in process()
13525 assert(!E->isValueDependent()); in EvaluateComparisonBinaryOperator()
13526 assert(E->isComparisonOp() && "expected comparison operator"); in EvaluateComparisonBinaryOperator()
13527 assert((E->getOpcode() == BO_Cmp || in EvaluateComparisonBinaryOperator()
13528 E->getType()->isIntegralOrEnumerationType()) && in EvaluateComparisonBinaryOperator()
13535 bool IsRelational = E->isRelationalOp() || E->getOpcode() == BO_Cmp; in EvaluateComparisonBinaryOperator()
13536 bool IsEquality = E->isEqualityOp(); in EvaluateComparisonBinaryOperator()
13538 QualType LHSTy = E->getLHS()->getType(); in EvaluateComparisonBinaryOperator()
13539 QualType RHSTy = E->getRHS()->getType(); in EvaluateComparisonBinaryOperator()
13541 if (LHSTy->isIntegralOrEnumerationType() && in EvaluateComparisonBinaryOperator()
13542 RHSTy->isIntegralOrEnumerationType()) { in EvaluateComparisonBinaryOperator()
13544 bool LHSOK = EvaluateInteger(E->getLHS(), LHS, Info); in EvaluateComparisonBinaryOperator()
13547 if (!EvaluateInteger(E->getRHS(), RHS, Info) || !LHSOK) in EvaluateComparisonBinaryOperator()
13556 if (LHSTy->isFixedPointType() || RHSTy->isFixedPointType()) { in EvaluateComparisonBinaryOperator()
13560 bool LHSOK = EvaluateFixedPointOrInteger(E->getLHS(), LHSFX, Info); in EvaluateComparisonBinaryOperator()
13563 if (!EvaluateFixedPointOrInteger(E->getRHS(), RHSFX, Info) || !LHSOK) in EvaluateComparisonBinaryOperator()
13572 if (LHSTy->isAnyComplexType() || RHSTy->isAnyComplexType()) { in EvaluateComparisonBinaryOperator()
13575 if (E->isAssignmentOp()) { in EvaluateComparisonBinaryOperator()
13577 EvaluateLValue(E->getLHS(), LV, Info); in EvaluateComparisonBinaryOperator()
13579 } else if (LHSTy->isRealFloatingType()) { in EvaluateComparisonBinaryOperator()
13580 LHSOK = EvaluateFloat(E->getLHS(), LHS.FloatReal, Info); in EvaluateComparisonBinaryOperator()
13586 LHSOK = EvaluateComplex(E->getLHS(), LHS, Info); in EvaluateComparisonBinaryOperator()
13591 if (E->getRHS()->getType()->isRealFloatingType()) { in EvaluateComparisonBinaryOperator()
13592 if (!EvaluateFloat(E->getRHS(), RHS.FloatReal, Info) || !LHSOK) in EvaluateComparisonBinaryOperator()
13596 } else if (!EvaluateComplex(E->getRHS(), RHS, Info) || !LHSOK) in EvaluateComparisonBinaryOperator()
13614 if (LHSTy->isRealFloatingType() && in EvaluateComparisonBinaryOperator()
13615 RHSTy->isRealFloatingType()) { in EvaluateComparisonBinaryOperator()
13618 bool LHSOK = EvaluateFloat(E->getRHS(), RHS, Info); in EvaluateComparisonBinaryOperator()
13622 if (!EvaluateFloat(E->getLHS(), LHS, Info) || !LHSOK) in EvaluateComparisonBinaryOperator()
13625 assert(E->isComparisonOp() && "Invalid binary operator!"); in EvaluateComparisonBinaryOperator()
13629 E->getFPFeaturesInEffect(Info.Ctx.getLangOpts()).isFPConstrained()) { in EvaluateComparisonBinaryOperator()
13650 if (LHSTy->isPointerType() && RHSTy->isPointerType()) { in EvaluateComparisonBinaryOperator()
13653 bool LHSOK = EvaluatePointer(E->getLHS(), LHSValue, Info); in EvaluateComparisonBinaryOperator()
13657 if (!EvaluatePointer(E->getRHS(), RHSValue, Info) || !LHSOK) in EvaluateComparisonBinaryOperator()
13660 // Reject differing bases from the normal codepath; we special-case in EvaluateComparisonBinaryOperator()
13664 std::string LHS = LHSValue.toString(Info.Ctx, E->getLHS()->getType()); in EvaluateComparisonBinaryOperator()
13665 std::string RHS = RHSValue.toString(Info.Ctx, E->getRHS()->getType()); in EvaluateComparisonBinaryOperator()
13684 // It's implementation-defined whether distinct literals will have in EvaluateComparisonBinaryOperator()
13687 // that the address of a literal will be non-null. in EvaluateComparisonBinaryOperator()
13697 // past-the-end address of another object, per C++ DR1652. in EvaluateComparisonBinaryOperator()
13728 if (LHSTy->isVoidPointerType() && LHSOffset != RHSOffset && IsRelational) in EvaluateComparisonBinaryOperator()
13732 // - If two pointers point to non-static data members of the same object, in EvaluateComparisonBinaryOperator()
13738 // - Otherwise pointer comparisons are unspecified. in EvaluateComparisonBinaryOperator()
13745 // - we are comparing array indices in EvaluateComparisonBinaryOperator()
13746 // - we are comparing fields of a union, or fields with the same access in EvaluateComparisonBinaryOperator()
13758 << RF->getParent() << RF; in EvaluateComparisonBinaryOperator()
13762 << LF->getParent() << LF; in EvaluateComparisonBinaryOperator()
13763 else if (!LF->getParent()->isUnion() && in EvaluateComparisonBinaryOperator()
13764 LF->getAccess() != RF->getAccess()) in EvaluateComparisonBinaryOperator()
13767 << LF << LF->getAccess() << RF << RF->getAccess() in EvaluateComparisonBinaryOperator()
13768 << LF->getParent(); in EvaluateComparisonBinaryOperator()
13778 uint64_t Mask = ~0ULL >> (64 - PtrSize); in EvaluateComparisonBinaryOperator()
13787 if (BaseTy->isIncompleteType()) in EvaluateComparisonBinaryOperator()
13802 if (LHSTy->isMemberPointerType()) { in EvaluateComparisonBinaryOperator()
13804 assert(RHSTy->isMemberPointerType() && "invalid comparison"); in EvaluateComparisonBinaryOperator()
13808 bool LHSOK = EvaluateMemberPointer(E->getLHS(), LHSValue, Info); in EvaluateComparisonBinaryOperator()
13812 if (!EvaluateMemberPointer(E->getRHS(), RHSValue, Info) || !LHSOK) in EvaluateComparisonBinaryOperator()
13817 if (LHSValue.getDecl() && LHSValue.getDecl()->isWeak()) { in EvaluateComparisonBinaryOperator()
13822 if (RHSValue.getDecl() && RHSValue.getDecl()->isWeak()) { in EvaluateComparisonBinaryOperator()
13839 if (MD->isVirtual()) in EvaluateComparisonBinaryOperator()
13842 if (MD->isVirtual()) in EvaluateComparisonBinaryOperator()
13853 if (LHSTy->isNullPtrType()) { in EvaluateComparisonBinaryOperator()
13854 assert(E->isComparisonOp() && "unexpected nullptr operation"); in EvaluateComparisonBinaryOperator()
13855 assert(RHSTy->isNullPtrType() && "missing pointer conversion"); in EvaluateComparisonBinaryOperator()
13860 if (!EvaluatePointer(E->getLHS(), Res, Info) || in EvaluateComparisonBinaryOperator()
13861 !EvaluatePointer(E->getRHS(), Res, Info)) in EvaluateComparisonBinaryOperator()
13877 llvm_unreachable("should never produce Unequal for three-way comparison"); in VisitBinCmp()
13894 Info.Ctx.CompCategories.getInfoForType(E->getType()); in VisitBinCmp()
13895 const VarDecl *VD = CmpInfo.getValueInfo(CmpInfo.makeWeakResult(CCR))->VD; in VisitBinCmp()
13899 if (!handleLValueToRValueConversion(Info, E, E->getType(), LV, Result)) in VisitBinCmp()
13901 return CheckConstantExpression(Info, E->getExprLoc(), E->getType(), Result, in VisitBinCmp()
13911 return VisitCXXParenListOrInitListExpr(E, E->getInitExprs()); in VisitCXXParenListInitExpr()
13917 if (E->isAssignmentOp()) { in VisitBinaryOperator()
13926 assert((!E->getLHS()->getType()->isIntegralOrEnumerationType() || in VisitBinaryOperator()
13927 !E->getRHS()->getType()->isIntegralOrEnumerationType()) && in VisitBinaryOperator()
13930 if (E->isComparisonOp()) { in VisitBinaryOperator()
13931 // Evaluate builtin binary comparisons by evaluating them as three-way in VisitBinaryOperator()
13934 assert((CR != CmpResult::Unequal || E->isEqualityOp()) && in VisitBinaryOperator()
13939 auto Op = E->getOpcode(); in VisitBinaryOperator()
13961 QualType LHSTy = E->getLHS()->getType(); in VisitBinaryOperator()
13962 QualType RHSTy = E->getRHS()->getType(); in VisitBinaryOperator()
13964 if (LHSTy->isPointerType() && RHSTy->isPointerType() && in VisitBinaryOperator()
13965 E->getOpcode() == BO_Sub) { in VisitBinaryOperator()
13968 bool LHSOK = EvaluatePointer(E->getLHS(), LHSValue, Info); in VisitBinaryOperator()
13972 if (!EvaluatePointer(E->getRHS(), RHSValue, Info) || !LHSOK) in VisitBinaryOperator()
13975 // Reject differing bases from the normal codepath; we special-case in VisitBinaryOperator()
13978 // Handle &&A - &&B. in VisitBinaryOperator()
13990 if (LHSAddrExpr->getLabel()->getDeclContext() != in VisitBinaryOperator()
13991 RHSAddrExpr->getLabel()->getDeclContext()) in VisitBinaryOperator()
14010 QualType Type = E->getLHS()->getType(); in VisitBinaryOperator()
14011 QualType ElementType = Type->castAs<PointerType>()->getPointeeType(); in VisitBinaryOperator()
14014 if (!HandleSizeof(Info, E->getExprLoc(), ElementType, ElementSize)) in VisitBinaryOperator()
14026 // FIXME: LLVM and GCC both compute LHSOffset - RHSOffset at runtime, in VisitBinaryOperator()
14028 // appears to be non-conforming, but is common, so perhaps we should in VisitBinaryOperator()
14032 // Compute (LHSOffset - RHSOffset) / Size carefully, checking for in VisitBinaryOperator()
14038 APSInt TrueResult = (LHS - RHS) / ElemSize; in VisitBinaryOperator()
14039 APSInt Result = TrueResult.trunc(Info.Ctx.getIntWidth(E->getType())); in VisitBinaryOperator()
14042 !HandleOverflow(Info, E, TrueResult, E->getType())) in VisitBinaryOperator()
14050 /// VisitUnaryExprOrTypeTraitExpr - Evaluate a sizeof, alignof or vec_step with
14054 switch(E->getKind()) { in VisitUnaryExprOrTypeTraitExpr()
14057 if (E->isArgumentType()) in VisitUnaryExprOrTypeTraitExpr()
14058 return Success(GetAlignOfType(Info, E->getArgumentType(), E->getKind()), in VisitUnaryExprOrTypeTraitExpr()
14061 return Success(GetAlignOfExpr(Info, E->getArgumentExpr(), E->getKind()), in VisitUnaryExprOrTypeTraitExpr()
14066 if (E->getArgumentType()->isDependentType()) in VisitUnaryExprOrTypeTraitExpr()
14069 Info.Ctx.getPointerAuthTypeDiscriminator(E->getArgumentType()), E); in VisitUnaryExprOrTypeTraitExpr()
14072 QualType Ty = E->getTypeOfArgument(); in VisitUnaryExprOrTypeTraitExpr()
14074 if (Ty->isVectorType()) { in VisitUnaryExprOrTypeTraitExpr()
14075 unsigned n = Ty->castAs<VectorType>()->getNumElements(); in VisitUnaryExprOrTypeTraitExpr()
14077 // The vec_step built-in functions that take a 3-component in VisitUnaryExprOrTypeTraitExpr()
14089 QualType SrcTy = E->getTypeOfArgument(); in VisitUnaryExprOrTypeTraitExpr()
14092 if (const ReferenceType *Ref = SrcTy->getAs<ReferenceType>()) in VisitUnaryExprOrTypeTraitExpr()
14093 SrcTy = Ref->getPointeeType(); in VisitUnaryExprOrTypeTraitExpr()
14096 if (!HandleSizeof(Info, E->getExprLoc(), SrcTy, Sizeof, in VisitUnaryExprOrTypeTraitExpr()
14097 E->getKind() == UETT_DataSizeOf ? SizeOfType::DataSizeOf in VisitUnaryExprOrTypeTraitExpr()
14104 assert(E->isArgumentType()); in VisitUnaryExprOrTypeTraitExpr()
14107 Info.Ctx.getOpenMPDefaultSimdAlign(E->getArgumentType())) in VisitUnaryExprOrTypeTraitExpr()
14111 QualType Ty = E->getTypeOfArgument(); in VisitUnaryExprOrTypeTraitExpr()
14114 if (const auto *VT = Ty->getAs<VectorType>()) in VisitUnaryExprOrTypeTraitExpr()
14115 return Success(VT->getNumElements(), E); in VisitUnaryExprOrTypeTraitExpr()
14117 assert(Ty->isSizelessVectorType()); in VisitUnaryExprOrTypeTraitExpr()
14120 << E->getSourceRange(); in VisitUnaryExprOrTypeTraitExpr()
14131 unsigned n = OOE->getNumComponents(); in VisitOffsetOfExpr()
14134 QualType CurrentType = OOE->getTypeSourceInfo()->getType(); in VisitOffsetOfExpr()
14136 OffsetOfNode ON = OOE->getComponent(i); in VisitOffsetOfExpr()
14139 const Expr *Idx = OOE->getIndexExpr(ON.getArrayExprIndex()); in VisitOffsetOfExpr()
14146 CurrentType = AT->getElementType(); in VisitOffsetOfExpr()
14154 const RecordType *RT = CurrentType->getAs<RecordType>(); in VisitOffsetOfExpr()
14157 RecordDecl *RD = RT->getDecl(); in VisitOffsetOfExpr()
14158 if (RD->isInvalidDecl()) return false; in VisitOffsetOfExpr()
14160 unsigned i = MemberDecl->getFieldIndex(); in VisitOffsetOfExpr()
14163 CurrentType = MemberDecl->getType().getNonReferenceType(); in VisitOffsetOfExpr()
14172 if (BaseSpec->isVirtual()) in VisitOffsetOfExpr()
14176 const RecordType *RT = CurrentType->getAs<RecordType>(); in VisitOffsetOfExpr()
14179 RecordDecl *RD = RT->getDecl(); in VisitOffsetOfExpr()
14180 if (RD->isInvalidDecl()) return false; in VisitOffsetOfExpr()
14184 CurrentType = BaseSpec->getType(); in VisitOffsetOfExpr()
14185 const RecordType *BaseRT = CurrentType->getAs<RecordType>(); in VisitOffsetOfExpr()
14190 Result += RL.getBaseClassOffset(cast<CXXRecordDecl>(BaseRT->getDecl())); in VisitOffsetOfExpr()
14199 switch (E->getOpcode()) { in VisitUnaryOperator()
14205 // FIXME: Should extension allow i-c-e extension expressions in its scope? in VisitUnaryOperator()
14207 return Visit(E->getSubExpr()); in VisitUnaryOperator()
14210 return Visit(E->getSubExpr()); in VisitUnaryOperator()
14212 if (!Visit(E->getSubExpr())) in VisitUnaryOperator()
14216 if (Value.isSigned() && Value.isMinSignedValue() && E->canOverflow()) { in VisitUnaryOperator()
14218 Info.Ctx.getDiagnostics().Report(E->getExprLoc(), in VisitUnaryOperator()
14222 << E->getType() << E->getSourceRange(); in VisitUnaryOperator()
14224 if (!HandleOverflow(Info, E, -Value.extend(Value.getBitWidth() + 1), in VisitUnaryOperator()
14225 E->getType())) in VisitUnaryOperator()
14228 return Success(-Value, E); in VisitUnaryOperator()
14231 if (!Visit(E->getSubExpr())) in VisitUnaryOperator()
14238 if (!EvaluateAsBooleanCondition(E->getSubExpr(), bres, Info)) in VisitUnaryOperator()
14245 /// HandleCast - This is used to evaluate implicit or explicit casts where the
14248 const Expr *SubExpr = E->getSubExpr(); in VisitCastExpr()
14249 QualType DestType = E->getType(); in VisitCastExpr()
14250 QualType SrcType = SubExpr->getType(); in VisitCastExpr()
14252 switch (E->getCastKind()) { in VisitCastExpr()
14324 if (BoolResult && E->getCastKind() == CK_BooleanToSignedIntegral) in VisitCastExpr()
14325 IntResult = (uint64_t)-1; in VisitCastExpr()
14336 DestType->isSignedIntegerOrEnumerationType(), &Overflowed); in VisitCastExpr()
14355 // Allow casts of address-of-label differences if they are no-ops in VisitCastExpr()
14357 // be constant-evaluatable except in some narrow cases which are hard in VisitCastExpr()
14368 DestType->isEnumeralType()) { in VisitCastExpr()
14379 ConstexprVar = VD->isConstexpr(); in VisitCastExpr()
14382 const EnumDecl *ED = ET->getDecl(); in VisitCastExpr()
14393 if (!ED->isFixed()) { in VisitCastExpr()
14397 ED->getValueRange(Max, Min); in VisitCastExpr()
14398 --Max; in VisitCastExpr()
14400 if (ED->getNumNegativeBits() && ConstexprVar && in VisitCastExpr()
14404 E->getExprLoc(), diag::warn_constexpr_unscoped_enum_out_of_range) in VisitCastExpr()
14407 else if (!ED->getNumNegativeBits() && ConstexprVar && in VisitCastExpr()
14410 E->getExprLoc(), diag::warn_constexpr_unscoped_enum_out_of_range) in VisitCastExpr()
14422 << 2 << Info.Ctx.getLangOpts().CPlusPlus << E->getSourceRange(); in VisitCastExpr()
14473 if (E->getSubExpr()->getType()->isAnyComplexType()) { in VisitUnaryReal()
14475 if (!EvaluateComplex(E->getSubExpr(), LV, Info)) in VisitUnaryReal()
14482 return Visit(E->getSubExpr()); in VisitUnaryReal()
14486 if (E->getSubExpr()->getType()->isComplexIntegerType()) { in VisitUnaryImag()
14488 if (!EvaluateComplex(E->getSubExpr(), LV, Info)) in VisitUnaryImag()
14495 VisitIgnoredValue(E->getSubExpr()); in VisitUnaryImag()
14500 return Success(E->getPackLength(), E); in VisitSizeOfPackExpr()
14504 return Success(E->getValue(), E); in VisitCXXNoexceptExpr()
14509 return Success(E->isSatisfied(), E); in VisitConceptSpecializationExpr()
14513 return Success(E->isSatisfied(), E); in VisitRequiresExpr()
14517 switch (E->getOpcode()) { in VisitUnaryOperator()
14523 return Visit(E->getSubExpr()); in VisitUnaryOperator()
14525 if (!Visit(E->getSubExpr())) return false; in VisitUnaryOperator()
14530 if (Overflowed && !HandleOverflow(Info, E, Negated, E->getType())) in VisitUnaryOperator()
14536 if (!EvaluateAsBooleanCondition(E->getSubExpr(), bres, Info)) in VisitUnaryOperator()
14544 const Expr *SubExpr = E->getSubExpr(); in VisitCastExpr()
14545 QualType DestType = E->getType(); in VisitCastExpr()
14546 assert(DestType->isFixedPointType() && in VisitCastExpr()
14550 switch (E->getCastKind()) { in VisitCastExpr()
14552 APFixedPoint Src(Info.Ctx.getFixedPointSemantics(SubExpr->getType())); in VisitCastExpr()
14559 Info.Ctx.getDiagnostics().Report(E->getExprLoc(), in VisitCastExpr()
14561 << Result.toString() << E->getType(); in VisitCastExpr()
14562 if (!HandleOverflow(Info, E, Result, E->getType())) in VisitCastExpr()
14578 Info.Ctx.getDiagnostics().Report(E->getExprLoc(), in VisitCastExpr()
14580 << IntResult.toString() << E->getType(); in VisitCastExpr()
14581 if (!HandleOverflow(Info, E, IntResult, E->getType())) in VisitCastExpr()
14598 Info.Ctx.getDiagnostics().Report(E->getExprLoc(), in VisitCastExpr()
14600 << Result.toString() << E->getType(); in VisitCastExpr()
14601 if (!HandleOverflow(Info, E, Result, E->getType())) in VisitCastExpr()
14616 if (E->isPtrMemOp() || E->isAssignmentOp() || E->getOpcode() == BO_Comma) in VisitBinaryOperator()
14619 const Expr *LHS = E->getLHS(); in VisitBinaryOperator()
14620 const Expr *RHS = E->getRHS(); in VisitBinaryOperator()
14622 Info.Ctx.getFixedPointSemantics(E->getType()); in VisitBinaryOperator()
14624 APFixedPoint LHSFX(Info.Ctx.getFixedPointSemantics(LHS->getType())); in VisitBinaryOperator()
14627 APFixedPoint RHSFX(Info.Ctx.getFixedPointSemantics(RHS->getType())); in VisitBinaryOperator()
14633 switch (E->getOpcode()) { in VisitBinaryOperator()
14664 LHSSema.getWidth() - (unsigned)LHSSema.hasUnsignedPadding(); in VisitBinaryOperator()
14665 unsigned Amt = RHSVal.getLimitedValue(ShiftBW - 1); in VisitBinaryOperator()
14666 // Embedded-C 4.1.6.2.2: in VisitBinaryOperator()
14668 // of (nonpadding) bits of the fixed-point operand ... in VisitBinaryOperator()
14673 << RHSVal << E->getType() << ShiftBW; in VisitBinaryOperator()
14675 if (E->getOpcode() == BO_Shl) in VisitBinaryOperator()
14686 Info.Ctx.getDiagnostics().Report(E->getExprLoc(), in VisitBinaryOperator()
14688 << Result.toString() << E->getType(); in VisitBinaryOperator()
14689 if (!HandleOverflow(Info, E, Result, E->getType())) in VisitBinaryOperator()
14695 //===----------------------------------------------------------------------===//
14697 //===----------------------------------------------------------------------===//
14713 Result = APFloat::getZero(Info.Ctx.getFloatTypeSemantics(E->getType())); in ZeroInitialization()
14732 assert(!E->isValueDependent()); in EvaluateFloat()
14733 assert(E->isPRValue() && E->getType()->isRealFloatingType()); in EvaluateFloat()
14742 const StringLiteral *S = dyn_cast<StringLiteral>(Arg->IgnoreParenCasts()); in TryEvaluateBuiltinNaN()
14750 if (S->getString().empty()) in TryEvaluateBuiltinNaN()
14752 else if (S->getString().getAsInteger(0, fill)) in TryEvaluateBuiltinNaN()
14761 // Prior to IEEE 754-2008, architectures were allowed to choose whether in TryEvaluateBuiltinNaN()
14763 // a different encoding to what became a standard in 2008, and for pre- in TryEvaluateBuiltinNaN()
14764 // 2008 revisions, MIPS interpreted sNaN-2008 as qNan and qNaN-2008 as in TryEvaluateBuiltinNaN()
14779 switch (E->getBuiltinCallee()) { in VisitCallExpr()
14794 Info.Ctx.getFloatTypeSemantics(E->getType()); in VisitCallExpr()
14804 if (!TryEvaluateBuiltinNaN(Info.Ctx, E->getType(), E->getArg(0), in VisitCallExpr()
14816 if (!TryEvaluateBuiltinNaN(Info.Ctx, E->getType(), E->getArg(0), in VisitCallExpr()
14825 // The C standard says "fabs raises no floating-point exceptions, in VisitCallExpr()
14830 if (!EvaluateFloat(E->getArg(0), Result, Info)) in VisitCallExpr()
14838 return EvaluateFloat(E->getArg(0), Result, Info); in VisitCallExpr()
14849 if (!EvaluateFloat(E->getArg(0), Result, Info) || in VisitCallExpr()
14850 !EvaluateFloat(E->getArg(1), RHS, Info)) in VisitCallExpr()
14863 if (!EvaluateFloat(E->getArg(0), Result, Info) || in VisitCallExpr()
14864 !EvaluateFloat(E->getArg(1), RHS, Info)) in VisitCallExpr()
14881 if (!EvaluateFloat(E->getArg(0), Result, Info) || in VisitCallExpr()
14882 !EvaluateFloat(E->getArg(1), RHS, Info)) in VisitCallExpr()
14884 // When comparing zeroes, return -0.0 if one of the zeroes is negative. in VisitCallExpr()
14895 if (E->getSubExpr()->getType()->isAnyComplexType()) { in VisitUnaryReal()
14897 if (!EvaluateComplex(E->getSubExpr(), CV, Info)) in VisitUnaryReal()
14903 return Visit(E->getSubExpr()); in VisitUnaryReal()
14907 if (E->getSubExpr()->getType()->isAnyComplexType()) { in VisitUnaryImag()
14909 if (!EvaluateComplex(E->getSubExpr(), CV, Info)) in VisitUnaryImag()
14915 VisitIgnoredValue(E->getSubExpr()); in VisitUnaryImag()
14916 const llvm::fltSemantics &Sem = Info.Ctx.getFloatTypeSemantics(E->getType()); in VisitUnaryImag()
14922 switch (E->getOpcode()) { in VisitUnaryOperator()
14925 return EvaluateFloat(E->getSubExpr(), Result, Info); in VisitUnaryOperator()
14928 // "the unary - raises no floating point exceptions, in VisitUnaryOperator()
14930 if (!EvaluateFloat(E->getSubExpr(), Result, Info)) in VisitUnaryOperator()
14938 if (E->isPtrMemOp() || E->isAssignmentOp() || E->getOpcode() == BO_Comma) in VisitBinaryOperator()
14942 bool LHSOK = EvaluateFloat(E->getLHS(), Result, Info); in VisitBinaryOperator()
14945 return EvaluateFloat(E->getRHS(), RHS, Info) && LHSOK && in VisitBinaryOperator()
14946 handleFloatFloatBinOp(Info, E, Result, E->getOpcode(), RHS); in VisitBinaryOperator()
14950 Result = E->getValue(); in VisitFloatingLiteral()
14955 const Expr* SubExpr = E->getSubExpr(); in VisitCastExpr()
14957 switch (E->getCastKind()) { in VisitCastExpr()
14963 const FPOptions FPO = E->getFPFeaturesInEffect( in VisitCastExpr()
14966 HandleIntToFloatCast(Info, E, FPO, SubExpr->getType(), in VisitCastExpr()
14967 IntResult, E->getType(), Result); in VisitCastExpr()
14971 APFixedPoint FixResult(Info.Ctx.getFixedPointSemantics(SubExpr->getType())); in VisitCastExpr()
14975 FixResult.convertToFloat(Info.Ctx.getFloatTypeSemantics(E->getType())); in VisitCastExpr()
14982 return HandleFloatToFloatCast(Info, E, SubExpr->getType(), E->getType(), in VisitCastExpr()
14996 //===----------------------------------------------------------------------===//
14998 //===----------------------------------------------------------------------===//
15016 //===--------------------------------------------------------------------===//
15018 //===--------------------------------------------------------------------===//
15031 assert(!E->isValueDependent()); in EvaluateComplex()
15032 assert(E->isPRValue() && E->getType()->isAnyComplexType()); in EvaluateComplex()
15037 QualType ElemTy = E->getType()->castAs<ComplexType>()->getElementType(); in ZeroInitialization()
15038 if (ElemTy->isRealFloatingType()) { in ZeroInitialization()
15053 const Expr* SubExpr = E->getSubExpr(); in VisitImaginaryLiteral()
15055 if (SubExpr->getType()->isRealFloatingType()) { in VisitImaginaryLiteral()
15064 assert(SubExpr->getType()->isIntegerType() && in VisitImaginaryLiteral()
15079 switch (E->getCastKind()) { in VisitCastExpr()
15149 if (!EvaluateFloat(E->getSubExpr(), Real, Info)) in VisitCastExpr()
15158 if (!Visit(E->getSubExpr())) in VisitCastExpr()
15161 QualType To = E->getType()->castAs<ComplexType>()->getElementType(); in VisitCastExpr()
15163 = E->getSubExpr()->getType()->castAs<ComplexType>()->getElementType(); in VisitCastExpr()
15170 if (!Visit(E->getSubExpr())) in VisitCastExpr()
15173 QualType To = E->getType()->castAs<ComplexType>()->getElementType(); in VisitCastExpr()
15175 = E->getSubExpr()->getType()->castAs<ComplexType>()->getElementType(); in VisitCastExpr()
15185 if (!EvaluateInteger(E->getSubExpr(), Real, Info)) in VisitCastExpr()
15194 if (!Visit(E->getSubExpr())) in VisitCastExpr()
15197 QualType To = E->getType()->castAs<ComplexType>()->getElementType(); in VisitCastExpr()
15199 = E->getSubExpr()->getType()->castAs<ComplexType>()->getElementType(); in VisitCastExpr()
15207 if (!Visit(E->getSubExpr())) in VisitCastExpr()
15210 const FPOptions FPO = E->getFPFeaturesInEffect( in VisitCastExpr()
15212 QualType To = E->getType()->castAs<ComplexType>()->getElementType(); in VisitCastExpr()
15214 = E->getSubExpr()->getType()->castAs<ComplexType>()->getElementType(); in VisitCastExpr()
15237 ResR = AC - BD; in HandleComplexComplexMul()
15276 ResR = APFloat::getInf(A.getSemantics()) * (A * C - B * D); in HandleComplexComplexMul()
15293 C = scalbn(C, -DenomLogB, APFloat::rmNearestTiesToEven); in HandleComplexComplexDiv()
15294 D = scalbn(D, -DenomLogB, APFloat::rmNearestTiesToEven); in HandleComplexComplexDiv()
15298 scalbn((A * C + B * D) / Denom, -DenomLogB, APFloat::rmNearestTiesToEven); in HandleComplexComplexDiv()
15300 scalbn((B * C - A * D) / Denom, -DenomLogB, APFloat::rmNearestTiesToEven); in HandleComplexComplexDiv()
15312 ResI = APFloat::getInf(ResI.getSemantics()) * (B * C - A * D); in HandleComplexComplexDiv()
15319 ResI = APFloat::getZero(ResI.getSemantics()) * (B * C - A * D); in HandleComplexComplexDiv()
15325 if (E->isPtrMemOp() || E->isAssignmentOp() || E->getOpcode() == BO_Comma) in VisitBinaryOperator()
15333 if (E->getLHS()->getType()->isRealFloatingType()) { in VisitBinaryOperator()
15336 LHSOK = EvaluateFloat(E->getLHS(), Real, Info); in VisitBinaryOperator()
15342 LHSOK = Visit(E->getLHS()); in VisitBinaryOperator()
15348 if (E->getRHS()->getType()->isRealFloatingType()) { in VisitBinaryOperator()
15351 if (!EvaluateFloat(E->getRHS(), Real, Info) || !LHSOK) in VisitBinaryOperator()
15355 } else if (!EvaluateComplex(E->getRHS(), RHS, Info) || !LHSOK) in VisitBinaryOperator()
15360 switch (E->getOpcode()) { in VisitBinaryOperator()
15388 Result.getComplexIntReal() -= RHS.getComplexIntReal(); in VisitBinaryOperator()
15389 Result.getComplexIntImag() -= RHS.getComplexIntImag(); in VisitBinaryOperator()
15428 (LHS.getComplexIntReal() * RHS.getComplexIntReal() - in VisitBinaryOperator()
15474 (LHS.getComplexIntImag() * RHS.getComplexIntReal() - in VisitBinaryOperator()
15485 if (!Visit(E->getSubExpr())) in VisitUnaryOperator()
15488 switch (E->getOpcode()) { in VisitUnaryOperator()
15502 Result.getComplexIntReal() = -Result.getComplexIntReal(); in VisitUnaryOperator()
15503 Result.getComplexIntImag() = -Result.getComplexIntImag(); in VisitUnaryOperator()
15510 Result.getComplexIntImag() = -Result.getComplexIntImag(); in VisitUnaryOperator()
15516 if (E->getNumInits() == 2) { in VisitInitListExpr()
15517 if (E->getType()->isComplexType()) { in VisitInitListExpr()
15519 if (!EvaluateFloat(E->getInit(0), Result.FloatReal, Info)) in VisitInitListExpr()
15521 if (!EvaluateFloat(E->getInit(1), Result.FloatImag, Info)) in VisitInitListExpr()
15525 if (!EvaluateInteger(E->getInit(0), Result.IntReal, Info)) in VisitInitListExpr()
15527 if (!EvaluateInteger(E->getInit(1), Result.IntImag, Info)) in VisitInitListExpr()
15539 switch (E->getBuiltinCallee()) { in VisitCallExpr()
15542 if (!EvaluateFloat(E->getArg(0), Result.FloatReal, Info)) in VisitCallExpr()
15544 if (!EvaluateFloat(E->getArg(1), Result.FloatImag, Info)) in VisitCallExpr()
15553 //===----------------------------------------------------------------------===//
15556 //===----------------------------------------------------------------------===//
15574 E->getType()->castAs<AtomicType>()->getValueType()); in ZeroInitialization()
15575 // For atomic-qualified class (and array) types in C++, initialize the in ZeroInitialization()
15576 // _Atomic-wrapped subobject directly, in-place. in ZeroInitialization()
15582 switch (E->getCastKind()) { in VisitCastExpr()
15586 VisitIgnoredValue(E->getSubExpr()); in VisitCastExpr()
15589 return This ? EvaluateInPlace(Result, Info, *This, E->getSubExpr()) in VisitCastExpr()
15590 : Evaluate(Result, Info, E->getSubExpr()); in VisitCastExpr()
15598 assert(!E->isValueDependent()); in EvaluateAtomic()
15599 assert(E->isPRValue() && E->getType()->isAtomicType()); in EvaluateAtomic()
15603 //===----------------------------------------------------------------------===//
15606 //===----------------------------------------------------------------------===//
15619 switch (E->getCastKind()) { in VisitCastExpr()
15623 VisitIgnoredValue(E->getSubExpr()); in VisitCastExpr()
15632 switch (E->getBuiltinCallee()) { in VisitCallExpr()
15655 FunctionDecl *OperatorDelete = E->getOperatorDelete(); in VisitCXXDeleteExpr()
15656 if (!OperatorDelete->isReplaceableGlobalAllocationFunction()) { in VisitCXXDeleteExpr()
15662 const Expr *Arg = E->getArgument(); in VisitCXXDeleteExpr()
15681 Info, E, Pointer, E->isArrayForm() ? DynAlloc::ArrayNew : DynAlloc::New); in VisitCXXDeleteExpr()
15686 // For the non-array case, the designator must be empty if the static type in VisitCXXDeleteExpr()
15688 if (!E->isArrayForm() && Pointer.Designator.Entries.size() != 0 && in VisitCXXDeleteExpr()
15689 !hasVirtualDestructor(Arg->getType()->getPointeeType())) { in VisitCXXDeleteExpr()
15691 << Arg->getType()->getPointeeType() << AllocType; in VisitCXXDeleteExpr()
15697 if (!E->isArrayForm() && !E->isGlobalDelete()) { in VisitCXXDeleteExpr()
15700 !VirtualDelete->isReplaceableGlobalAllocationFunction()) { in VisitCXXDeleteExpr()
15707 if (!HandleDestruction(Info, E->getExprLoc(), Pointer.getLValueBase(), in VisitCXXDeleteExpr()
15708 (*Alloc)->Value, AllocType)) in VisitCXXDeleteExpr()
15724 assert(!E->isValueDependent()); in EvaluateVoid()
15725 assert(E->isPRValue() && E->getType()->isVoidType()); in EvaluateVoid()
15729 //===----------------------------------------------------------------------===//
15731 //===----------------------------------------------------------------------===//
15734 assert(!E->isValueDependent()); in Evaluate()
15737 QualType T = E->getType(); in Evaluate()
15738 if (E->isGLValue() || T->isFunctionType()) { in Evaluate()
15743 } else if (T->isVectorType()) { in Evaluate()
15746 } else if (T->isIntegralOrEnumerationType()) { in Evaluate()
15749 } else if (T->hasPointerRepresentation()) { in Evaluate()
15754 } else if (T->isRealFloatingType()) { in Evaluate()
15759 } else if (T->isAnyComplexType()) { in Evaluate()
15764 } else if (T->isFixedPointType()) { in Evaluate()
15766 } else if (T->isMemberPointerType()) { in Evaluate()
15772 } else if (T->isArrayType()) { in Evaluate()
15775 Info.CurrentCall->createTemporary(E, T, ScopeKind::FullExpression, LV); in Evaluate()
15779 } else if (T->isRecordType()) { in Evaluate()
15782 Info.CurrentCall->createTemporary(E, T, ScopeKind::FullExpression, LV); in Evaluate()
15786 } else if (T->isVoidType()) { in Evaluate()
15789 << E->getType(); in Evaluate()
15792 } else if (T->isAtomicType()) { in Evaluate()
15794 if (Unqual->isArrayType() || Unqual->isRecordType()) { in Evaluate()
15796 APValue &Value = Info.CurrentCall->createTemporary( in Evaluate()
15806 Info.FFDiag(E, diag::note_constexpr_nonliteral) << E->getType(); in Evaluate()
15816 /// EvaluateInPlace - Evaluate an expression in-place in an APValue. In some
15817 /// cases, the in-place evaluation is essential, since later initializers for
15821 assert(!E->isValueDependent()); in EvaluateInPlace()
15826 if (E->isPRValue()) { in EvaluateInPlace()
15827 // Evaluate arrays and record types in-place, so that later initializers can in EvaluateInPlace()
15828 // refer to earlier-initialized members of the object. in EvaluateInPlace()
15829 QualType T = E->getType(); in EvaluateInPlace()
15830 if (T->isArrayType()) in EvaluateInPlace()
15832 else if (T->isRecordType()) in EvaluateInPlace()
15834 else if (T->isAtomicType()) { in EvaluateInPlace()
15836 if (Unqual->isArrayType() || Unqual->isRecordType()) in EvaluateInPlace()
15841 // For any other type, in-place evaluation is unimportant. in EvaluateInPlace()
15845 /// EvaluateAsRValue - Try to evaluate this expression, performing an implicit
15846 /// lvalue-to-rvalue cast if it is an lvalue.
15848 assert(!E->isValueDependent()); in EvaluateAsRValue()
15850 if (E->getType().isNull()) in EvaluateAsRValue()
15859 return CheckConstantExpression(Info, E->getExprLoc(), E->getType(), Result, in EvaluateAsRValue()
15866 // Implicit lvalue-to-rvalue cast. in EvaluateAsRValue()
15867 if (E->isGLValue()) { in EvaluateAsRValue()
15870 if (!handleLValueToRValueConversion(Info, E, E->getType(), LV, Result)) in EvaluateAsRValue()
15875 return CheckConstantExpression(Info, E->getExprLoc(), E->getType(), Result, in EvaluateAsRValue()
15882 // Fast-path evaluations of integer literals, since we sometimes see files in FastEvaluateAsRValue()
15885 Result.Val = APValue(APSInt(L->getValue(), in FastEvaluateAsRValue()
15886 L->getType()->isUnsignedIntegerType())); in FastEvaluateAsRValue()
15892 Result.Val = APValue(APSInt(APInt(1, L->getValue()))); in FastEvaluateAsRValue()
15898 if (CE->hasAPValueResult()) { in FastEvaluateAsRValue()
15899 APValue APV = CE->getAPValueResult(); in FastEvaluateAsRValue()
15908 return FastEvaluateAsRValue(CE->getSubExpr(), Result, Ctx, IsConst); in FastEvaluateAsRValue()
15913 if (Exp->getType().isNull()) { in FastEvaluateAsRValue()
15929 assert(!E->isValueDependent()); in EvaluateAsRValue()
15941 assert(!E->isValueDependent()); in EvaluateAsInt()
15942 if (!E->getType()->isIntegralOrEnumerationType()) in EvaluateAsInt()
15957 assert(!E->isValueDependent()); in EvaluateAsFixedPoint()
15958 if (!E->getType()->isFixedPointType()) in EvaluateAsFixedPoint()
15971 /// EvaluateAsRValue - Return true if this is a constant which we can fold using
15974 /// in Result. If this expression is a glvalue, an lvalue-to-rvalue conversion
16024 if (!getType()->isRealFloatingType()) in EvaluateAsFloat()
16122 // A full-expression is [...] a constant-expression in EvaluateAsConstantExpr()
16164 VD->printQualifiedName(OS); in EvaluateAsInitializer()
16179 SourceLocation DeclLoc = VD->getLocation(); in EvaluateAsInitializer()
16180 QualType DeclTy = VD->getType(); in EvaluateAsInitializer()
16195 // A full-expression is ... an init-declarator ([dcl.decl]) or a in EvaluateAsInitializer()
16196 // mem-initializer. in EvaluateAsInitializer()
16210 // At this point, any lifetime-extended temporaries are completely in EvaluateAsInitializer()
16233 // Otherwise, treat the value as default-initialized; if the destructor works in evaluateDestruction()
16236 if (getEvaluatedValue() && !getEvaluatedValue()->isAbsent()) in evaluateDestruction()
16247 ensureEvaluatedStmt()->HasConstantDestruction = true; in evaluateDestruction()
16251 /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be
16320 /// isIntegerConstantExpr - this recursive routine will test if an expression is
16323 /// FIXME: Pass up a reason why! Invalid operation in i-c-e, division by zero,
16326 // CheckICE - This function does the fundamental ICE checking: the returned
16342 /// the comma operator in C99 mode, and non-constant subexpressions.
16369 return ICEDiag(IK_NotICE, E->getBeginLoc()); in CheckEvalInICE()
16375 assert(!E->isValueDependent() && "Should not see value dependent exprs!"); in CheckICE()
16376 if (!E->getType()->isIntegralOrEnumerationType()) in CheckICE()
16377 return ICEDiag(IK_NotICE, E->getBeginLoc()); in CheckICE()
16379 switch (E->getStmtClass()) { in CheckICE()
16468 return ICEDiag(IK_NotICE, E->getBeginLoc()); in CheckICE()
16475 if (E->isPRValue()) in CheckICE()
16476 if (cast<InitListExpr>(E)->getNumInits() == 1) in CheckICE()
16477 return CheckICE(cast<InitListExpr>(E)->getInit(0), Ctx); in CheckICE()
16478 return ICEDiag(IK_NotICE, E->getBeginLoc()); in CheckICE()
16488 return CheckICE(cast<PackIndexingExpr>(E)->getSelectedExpr(), Ctx); in CheckICE()
16492 CheckICE(cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement(), Ctx); in CheckICE()
16495 return CheckICE(cast<ConstantExpr>(E)->getSubExpr(), Ctx); in CheckICE()
16498 return CheckICE(cast<ParenExpr>(E)->getSubExpr(), Ctx); in CheckICE()
16500 return CheckICE(cast<GenericSelectionExpr>(E)->getResultExpr(), Ctx); in CheckICE()
16520 if (CE->getBuiltinCallee()) in CheckICE()
16522 return ICEDiag(IK_NotICE, E->getBeginLoc()); in CheckICE()
16525 return CheckICE(cast<CXXRewrittenBinaryOperator>(E)->getSemanticForm(), in CheckICE()
16528 const NamedDecl *D = cast<DeclRefExpr>(E)->getDecl(); in CheckICE()
16532 // C++ and OpenCL (FIXME: spec reference?) allow reading const-qualified in CheckICE()
16536 // A variable of non-volatile const-qualified integral or enumeration in CheckICE()
16542 if (VD && VD->isUsableInConstantExpressions(Ctx) && in CheckICE()
16543 !VD->getType()->isReferenceType()) in CheckICE()
16546 return ICEDiag(IK_NotICE, E->getBeginLoc()); in CheckICE()
16550 switch (Exp->getOpcode()) { in CheckICE()
16561 return ICEDiag(IK_NotICE, E->getBeginLoc()); in CheckICE()
16569 return CheckICE(Exp->getSubExpr(), Ctx); in CheckICE()
16584 if ((Exp->getKind() == UETT_SizeOf) && in CheckICE()
16585 Exp->getTypeOfArgument()->isVariableArrayType()) in CheckICE()
16586 return ICEDiag(IK_NotICE, E->getBeginLoc()); in CheckICE()
16591 switch (Exp->getOpcode()) { in CheckICE()
16608 return ICEDiag(IK_NotICE, E->getBeginLoc()); in CheckICE()
16628 ICEDiag LHSResult = CheckICE(Exp->getLHS(), Ctx); in CheckICE()
16629 ICEDiag RHSResult = CheckICE(Exp->getRHS(), Ctx); in CheckICE()
16630 if (Exp->getOpcode() == BO_Div || in CheckICE()
16631 Exp->getOpcode() == BO_Rem) { in CheckICE()
16635 llvm::APSInt REval = Exp->getRHS()->EvaluateKnownConstInt(Ctx); in CheckICE()
16637 return ICEDiag(IK_ICEIfUnevaluated, E->getBeginLoc()); in CheckICE()
16639 llvm::APSInt LEval = Exp->getLHS()->EvaluateKnownConstInt(Ctx); in CheckICE()
16641 return ICEDiag(IK_ICEIfUnevaluated, E->getBeginLoc()); in CheckICE()
16645 if (Exp->getOpcode() == BO_Comma) { in CheckICE()
16650 return ICEDiag(IK_ICEIfUnevaluated, E->getBeginLoc()); in CheckICE()
16653 return ICEDiag(IK_NotICE, E->getBeginLoc()); in CheckICE()
16660 ICEDiag LHSResult = CheckICE(Exp->getLHS(), Ctx); in CheckICE()
16661 ICEDiag RHSResult = CheckICE(Exp->getRHS(), Ctx); in CheckICE()
16663 // Rare case where the RHS has a comma "side-effect"; we need in CheckICE()
16666 if ((Exp->getOpcode() == BO_LAnd) != in CheckICE()
16667 (Exp->getLHS()->EvaluateKnownConstInt(Ctx) == 0)) in CheckICE()
16684 const Expr *SubExpr = cast<CastExpr>(E)->getSubExpr(); in CheckICE()
16687 = dyn_cast<FloatingLiteral>(SubExpr->IgnoreParenImpCasts())) { in CheckICE()
16688 unsigned DestWidth = Ctx.getIntWidth(E->getType()); in CheckICE()
16689 bool DestSigned = E->getType()->isSignedIntegerOrEnumerationType(); in CheckICE()
16695 if (FL->getValue().convertToInteger(IgnoredVal, in CheckICE()
16698 return ICEDiag(IK_NotICE, E->getBeginLoc()); in CheckICE()
16702 switch (cast<CastExpr>(E)->getCastKind()) { in CheckICE()
16711 return ICEDiag(IK_NotICE, E->getBeginLoc()); in CheckICE()
16716 ICEDiag CommonResult = CheckICE(Exp->getCommon(), Ctx); in CheckICE()
16718 ICEDiag FalseResult = CheckICE(Exp->getFalseExpr(), Ctx); in CheckICE()
16722 Exp->getCommon()->EvaluateKnownConstInt(Ctx) != 0) return NoDiag(); in CheckICE()
16732 = dyn_cast<CallExpr>(Exp->getCond()->IgnoreParenCasts())) in CheckICE()
16733 if (CallCE->getBuiltinCallee() == Builtin::BI__builtin_constant_p) in CheckICE()
16735 ICEDiag CondResult = CheckICE(Exp->getCond(), Ctx); in CheckICE()
16739 ICEDiag TrueResult = CheckICE(Exp->getTrueExpr(), Ctx); in CheckICE()
16740 ICEDiag FalseResult = CheckICE(Exp->getFalseExpr(), Ctx); in CheckICE()
16752 // TrueResult and FalseResult is non-zero. in CheckICE()
16753 if (Exp->getCond()->EvaluateKnownConstInt(Ctx) == 0) in CheckICE()
16758 return CheckICE(cast<CXXDefaultArgExpr>(E)->getExpr(), Ctx); in CheckICE()
16760 return CheckICE(cast<CXXDefaultInitExpr>(E)->getExpr(), Ctx); in CheckICE()
16762 return CheckICE(cast<ChooseExpr>(E)->getChosenSubExpr(), Ctx); in CheckICE()
16766 return ICEDiag(IK_NotICE, E->getBeginLoc()); in CheckICE()
16767 return CheckICE(cast<CastExpr>(E)->getSubExpr(), Ctx); in CheckICE()
16779 if (!E->getType()->isIntegralOrUnscopedEnumerationType()) { in EvaluateCPlusPlus11IntegralConstantExpr()
16780 if (Loc) *Loc = E->getExprLoc(); in EvaluateCPlusPlus11IntegralConstantExpr()
16785 if (!E->isCXX11ConstantExpr(Ctx, &Result, Loc)) in EvaluateCPlusPlus11IntegralConstantExpr()
16789 if (Loc) *Loc = E->getExprLoc(); in EvaluateCPlusPlus11IntegralConstantExpr()
16833 // The only possible side-effects here are due to UB discovered in the in getIntegerConstantExpr()
16874 // call us on arbitrary full-expressions should generally not care. in isCXX11ConstantExpr()
16898 Callee->getNameForDiagnostic(OS, Ctx.getPrintingPolicy(), in EvaluateWithSubstitution()
16912 assert(MD && "Don't provide `this` for non-methods."); in EvaluateWithSubstitution()
16913 assert(MD->isImplicitObjectMemberFunction() && in EvaluateWithSubstitution()
16916 if (!This->isValueDependent() && in EvaluateWithSubstitution()
16921 // Ignore any side-effects from a failed evaluation. This is safe because in EvaluateWithSubstitution()
16926 CallRef Call = Info.CurrentCall->createCall(Callee); in EvaluateWithSubstitution()
16929 unsigned Idx = I - Args.begin(); in EvaluateWithSubstitution()
16930 if (Idx >= Callee->getNumParams()) in EvaluateWithSubstitution()
16932 const ParmVarDecl *PVD = Callee->getParamDecl(Idx); in EvaluateWithSubstitution()
16933 if ((*I)->isValueDependent() || in EvaluateWithSubstitution()
16941 // Ignore any side-effects from a failed evaluation. This is safe because in EvaluateWithSubstitution()
16952 CallStackFrame Frame(Info, Callee->getLocation(), Callee, ThisPtr, This, in EvaluateWithSubstitution()
16964 // moment the constant expression evaluator cannot cope with the non-rigorous in isPotentialConstantExpr()
16966 if (FD->isDependentContext()) in isPotentialConstantExpr()
16972 FD->getNameForDiagnostic(OS, FD->getASTContext().getPrintingPolicy(), in isPotentialConstantExpr()
16980 EvalInfo Info(FD->getASTContext(), Status, EvalInfo::EM_ConstantExpression); in isPotentialConstantExpr()
16991 const CXXRecordDecl *RD = MD ? MD->getParent()->getCanonicalDecl() : nullptr; in isPotentialConstantExpr()
16997 This.set({&VIE, Info.CurrentCall->Index}); in isPotentialConstantExpr()
17004 // of objects of non-literal types. in isPotentialConstantExpr()
17008 SourceLocation Loc = FD->getLocation(); in isPotentialConstantExpr()
17010 Loc, FD, (MD && MD->isImplicitObjectMemberFunction()) ? &This : nullptr, in isPotentialConstantExpr()
17011 &VIE, Args, CallRef(), FD->getBody(), Info, Scratch, in isPotentialConstantExpr()
17022 assert(!E->isValueDependent() && in isPotentialConstantExprUnevaluated()
17028 EvalInfo Info(FD->getASTContext(), Status, in isPotentialConstantExprUnevaluated()
17044 if (!getType()->isPointerType()) in tryEvaluateObjectSize()
17054 if (!E->getType()->hasPointerRepresentation() || !E->isPRValue()) in EvaluateBuiltinStrLen()
17062 QualType CharTy = E->getType()->getPointeeType(); in EvaluateBuiltinStrLen()
17067 StringRef Str = S->getBytes(); in EvaluateBuiltinStrLen()
17070 S->getCharByteWidth() == 1 && in EvaluateBuiltinStrLen()
17071 // FIXME: Add fast-path for wchar_t too. in EvaluateBuiltinStrLen()
17098 StringResult->push_back(Char.getInt().getExtValue()); in EvaluateBuiltinStrLen()
17133 QualType CharTy = PtrExpression->getType()->getPointeeType(); in EvaluateCharRangeAsString()