• Home
  • Raw
  • Download

Lines Matching refs:E

71   APValue::BaseOrMemberType getAsBaseOrMember(APValue::LValuePathEntry E) {  in getAsBaseOrMember()  argument
73 Value.setFromOpaqueValue(E.BaseOrMember); in getAsBaseOrMember()
79 static const FieldDecl *getAsField(APValue::LValuePathEntry E) { in getAsField() argument
80 return dyn_cast<FieldDecl>(getAsBaseOrMember(E).getPointer()); in getAsField()
84 static const CXXRecordDecl *getAsBaseClass(APValue::LValuePathEntry E) { in getAsBaseClass() argument
85 return dyn_cast<CXXRecordDecl>(getAsBaseOrMember(E).getPointer()); in getAsBaseClass()
89 static bool isVirtualBaseClass(APValue::LValuePathEntry E) { in isVirtualBaseClass() argument
90 return getAsBaseOrMember(E).getInt(); in isVirtualBaseClass()
201 bool checkSubobject(EvalInfo &Info, const Expr *E, CheckSubobjectKind CSK);
241 void diagnosePointerArithmetic(EvalInfo &Info, const Expr *E, uint64_t N);
243 void adjustIndex(EvalInfo &Info, const Expr *E, uint64_t N) { in adjustIndex()
248 diagnosePointerArithmetic(Info, E, Entries.back().ArrayIndex); in adjustIndex()
261 diagnosePointerArithmetic(Info, E, uint64_t(IsOnePastTheEnd) + N); in adjustIndex()
476 OptionalDiagnostic Diag(const Expr *E, diag::kind DiagId in Diag()
480 return Diag(E->getExprLoc(), DiagId, ExtraNotes); in Diag()
557 bool SubobjectDesignator::checkSubobject(EvalInfo &Info, const Expr *E, in checkSubobject() argument
562 Info.CCEDiag(E, diag::note_constexpr_past_end_subobject) in checkSubobject()
571 const Expr *E, uint64_t N) { in diagnosePointerArithmetic() argument
573 Info.CCEDiag(E, diag::note_constexpr_array_index) in diagnosePointerArithmetic()
577 Info.CCEDiag(E, diag::note_constexpr_array_index) in diagnosePointerArithmetic()
608 E = Frame->Callee->param_end(); I != E; ++I, ++ArgIndex) { in describeCall() local
731 bool checkNullPointer(EvalInfo &Info, const Expr *E, in checkNullPointer()
736 Info.CCEDiag(E, diag::note_constexpr_null_subobject) in checkNullPointer()
746 bool checkSubobject(EvalInfo &Info, const Expr *E, CheckSubobjectKind CSK) { in checkSubobject()
751 return checkNullPointer(Info, E, CSK) && in checkSubobject()
752 Designator.checkSubobject(Info, E, CSK); in checkSubobject()
755 void addDecl(EvalInfo &Info, const Expr *E, in addDecl()
757 if (checkSubobject(Info, E, isa<FieldDecl>(D) ? CSK_Field : CSK_Base)) in addDecl()
760 void addArray(EvalInfo &Info, const Expr *E, const ConstantArrayType *CAT) { in addArray()
761 if (checkSubobject(Info, E, CSK_ArrayToPointer)) in addArray()
764 void addComplex(EvalInfo &Info, const Expr *E, QualType EltTy, bool Imag) { in addComplex()
765 if (checkSubobject(Info, E, Imag ? CSK_Imag : CSK_Real)) in addComplex()
768 void adjustIndex(EvalInfo &Info, const Expr *E, uint64_t N) { in adjustIndex()
769 if (checkNullPointer(Info, E, CSK_ArrayIndex)) in adjustIndex()
770 Designator.adjustIndex(Info, E, N); in adjustIndex()
880 static bool Evaluate(APValue &Result, EvalInfo &Info, const Expr *E);
882 const LValue &This, const Expr *E,
885 static bool EvaluateLValue(const Expr *E, LValue &Result, EvalInfo &Info);
886 static bool EvaluatePointer(const Expr *E, LValue &Result, EvalInfo &Info);
887 static bool EvaluateMemberPointer(const Expr *E, MemberPtr &Result,
889 static bool EvaluateTemporary(const Expr *E, LValue &Result, EvalInfo &Info);
890 static bool EvaluateInteger(const Expr *E, APSInt &Result, EvalInfo &Info);
891 static bool EvaluateIntegerOrLValue(const Expr *E, APValue &Result,
893 static bool EvaluateFloat(const Expr *E, APFloat &Result, EvalInfo &Info);
894 static bool EvaluateComplex(const Expr *E, ComplexValue &Res, EvalInfo &Info);
901 static bool IsStringLiteralCall(const CallExpr *E) { in IsStringLiteralCall() argument
902 unsigned Builtin = E->isBuiltinCall(); in IsStringLiteralCall()
923 const Expr *E = B.get<const Expr*>(); in IsGlobalLValue() local
924 switch (E->getStmtClass()) { in IsGlobalLValue()
928 const CompoundLiteralExpr *CLE = cast<CompoundLiteralExpr>(E); in IsGlobalLValue()
940 return IsStringLiteralCall(cast<CallExpr>(E)); in IsGlobalLValue()
947 return !cast<BlockExpr>(E)->getBlockDecl()->hasCaptures(); in IsGlobalLValue()
1024 static bool CheckLiteralType(EvalInfo &Info, const Expr *E) { in CheckLiteralType() argument
1025 if (!E->isRValue() || E->getType()->isLiteralType()) in CheckLiteralType()
1030 Info.Diag(E, diag::note_constexpr_nonliteral) in CheckLiteralType()
1031 << E->getType(); in CheckLiteralType()
1033 Info.Diag(E, diag::note_invalid_subexpr_in_const_expr); in CheckLiteralType()
1073 for (RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end(); in CheckConstantExpression() local
1074 I != E; ++I) { in CheckConstantExpression()
1153 static bool EvaluateAsBooleanCondition(const Expr *E, bool &Result, in EvaluateAsBooleanCondition() argument
1155 assert(E->isRValue() && "missing lvalue-to-rvalue conv in bool condition"); in EvaluateAsBooleanCondition()
1157 if (!Evaluate(Val, Info, E)) in EvaluateAsBooleanCondition()
1163 static bool HandleOverflow(EvalInfo &Info, const Expr *E, in HandleOverflow() argument
1165 Info.Diag(E, diag::note_constexpr_overflow) in HandleOverflow()
1170 static bool HandleFloatToIntCast(EvalInfo &Info, const Expr *E, in HandleFloatToIntCast() argument
1181 return HandleOverflow(Info, E, Value, DestType); in HandleFloatToIntCast()
1185 static bool HandleFloatToFloatCast(EvalInfo &Info, const Expr *E, in HandleFloatToFloatCast() argument
1193 return HandleOverflow(Info, E, Value, DestType); in HandleFloatToFloatCast()
1197 static APSInt HandleIntToIntCast(EvalInfo &Info, const Expr *E, in HandleIntToIntCast() argument
1209 static bool HandleIntToFloatCast(EvalInfo &Info, const Expr *E, in HandleIntToFloatCast() argument
1216 return HandleOverflow(Info, E, Value, DestType); in HandleIntToFloatCast()
1220 static bool EvalAndBitcastToAPInt(EvalInfo &Info, const Expr *E, in EvalAndBitcastToAPInt() argument
1223 if (!Evaluate(SVal, Info, E)) in EvalAndBitcastToAPInt()
1234 QualType VecTy = E->getType(); in EvalAndBitcastToAPInt()
1250 Info.Diag(E, diag::note_invalid_subexpr_in_const_expr); in EvalAndBitcastToAPInt()
1263 Info.Diag(E, diag::note_invalid_subexpr_in_const_expr); in EvalAndBitcastToAPInt()
1269 static bool CastToDerivedClass(EvalInfo &Info, const Expr *E, LValue &Result, in CastToDerivedClass() argument
1279 if (!Result.checkSubobject(Info, E, CSK_Derived)) in CastToDerivedClass()
1297 static void HandleLValueDirectBase(EvalInfo &Info, const Expr *E, LValue &Obj, in HandleLValueDirectBase() argument
1303 Obj.addDecl(Info, E, Base, /*Virtual*/ false); in HandleLValueDirectBase()
1306 static bool HandleLValueBase(EvalInfo &Info, const Expr *E, LValue &Obj, in HandleLValueBase() argument
1312 HandleLValueDirectBase(Info, E, Obj, DerivedDecl, BaseDecl); in HandleLValueBase()
1322 if (!CastToDerivedClass(Info, E, Obj, DerivedDecl, D.MostDerivedPathLength)) in HandleLValueBase()
1328 Obj.addDecl(Info, E, BaseDecl, /*Virtual*/ true); in HandleLValueBase()
1334 static void HandleLValueMember(EvalInfo &Info, const Expr *E, LValue &LVal, in HandleLValueMember() argument
1342 LVal.addDecl(Info, E, FD); in HandleLValueMember()
1346 static void HandleLValueIndirectMember(EvalInfo &Info, const Expr *E, in HandleLValueIndirectMember() argument
1351 HandleLValueMember(Info, E, LVal, cast<FieldDecl>(*C)); in HandleLValueIndirectMember()
1381 static bool HandleLValueArrayAdjustment(EvalInfo &Info, const Expr *E, in HandleLValueArrayAdjustment() argument
1385 if (!HandleSizeof(Info, E->getExprLoc(), EltTy, SizeOfPointee)) in HandleLValueArrayAdjustment()
1390 LVal.adjustIndex(Info, E, Adjustment); in HandleLValueArrayAdjustment()
1399 static bool HandleLValueComplexElement(EvalInfo &Info, const Expr *E, in HandleLValueComplexElement() argument
1404 if (!HandleSizeof(Info, E->getExprLoc(), EltTy, SizeOfComponent)) in HandleLValueComplexElement()
1408 LVal.addComplex(Info, E, EltTy, Imag); in HandleLValueComplexElement()
1413 static bool EvaluateVarDeclInit(EvalInfo &Info, const Expr *E, in EvaluateVarDeclInit() argument
1424 Info.Diag(E, diag::note_invalid_subexpr_in_const_expr); in EvaluateVarDeclInit()
1437 Info.Diag(E, diag::note_invalid_subexpr_in_const_expr); in EvaluateVarDeclInit()
1451 Info.Diag(E, diag::note_invalid_subexpr_in_const_expr); in EvaluateVarDeclInit()
1459 Info.Diag(E, diag::note_constexpr_var_init_non_constant, in EvaluateVarDeclInit()
1465 Info.CCEDiag(E, diag::note_constexpr_var_init_non_constant, in EvaluateVarDeclInit()
1487 E = Derived->bases_end(); I != E; ++I, ++Index) { in getBaseIndex() local
1514 static bool ExtractSubobject(EvalInfo &Info, const Expr *E, in ExtractSubobject() argument
1521 Info.Diag(E, Info.getLangOpts().CPlusPlus0x ? in ExtractSubobject()
1543 Info.Diag(E, Info.getLangOpts().CPlusPlus0x ? in ExtractSubobject()
1565 Info.Diag(E, Info.getLangOpts().CPlusPlus0x ? in ExtractSubobject()
1582 Info.Diag(E, diag::note_constexpr_ltor_mutable, 1) in ExtractSubobject()
1594 Info.Diag(E, diag::note_constexpr_read_inactive_union_member) in ExtractSubobject()
1606 Info.Diag(E, diag::note_constexpr_ltor_volatile_obj, 1) in ExtractSubobject()
1610 Info.Diag(E, diag::note_invalid_subexpr_in_const_expr); in ExtractSubobject()
1624 Info.Diag(E, diag::note_constexpr_read_uninit); in ExtractSubobject()
1978 static bool HandleBaseToDerivedCast(EvalInfo &Info, const CastExpr *E, in HandleBaseToDerivedCast() argument
1981 if (D.Invalid || !Result.checkNullPointer(Info, E, CSK_Derived)) in HandleBaseToDerivedCast()
1984 QualType TargetQT = E->getType(); in HandleBaseToDerivedCast()
1989 if (D.MostDerivedPathLength + E->path_size() > D.Entries.size()) { in HandleBaseToDerivedCast()
1990 Info.CCEDiag(E, diag::note_constexpr_invalid_downcast) in HandleBaseToDerivedCast()
1997 unsigned NewEntriesSize = D.Entries.size() - E->path_size(); in HandleBaseToDerivedCast()
2005 Info.CCEDiag(E, diag::note_constexpr_invalid_downcast) in HandleBaseToDerivedCast()
2011 return CastToDerivedClass(Info, E, Result, TargetType, NewEntriesSize); in HandleBaseToDerivedCast()
2120 for (ArrayRef<const Expr*>::iterator I = Args.begin(), E = Args.end(); in EvaluateArgs() local
2121 I != E; ++I) { in EvaluateArgs()
2200 E = Definition->init_end(); I != E; ++I) { in HandleConstructorCall() local
2284 bool VisitParenExpr(const ParenExpr *E) { return Visit(E->getSubExpr()); } in VisitParenExpr() argument
2285 bool VisitGenericSelectionExpr(const GenericSelectionExpr *E) { in VisitGenericSelectionExpr() argument
2286 return Visit(E->getResultExpr()); in VisitGenericSelectionExpr()
2288 bool VisitDeclRefExpr(const DeclRefExpr *E) { in VisitDeclRefExpr() argument
2289 if (Ctx.getCanonicalType(E->getType()).isVolatileQualified()) in VisitDeclRefExpr()
2293 bool VisitObjCIvarRefExpr(const ObjCIvarRefExpr *E) { in VisitObjCIvarRefExpr() argument
2294 if (Ctx.getCanonicalType(E->getType()).isVolatileQualified()) in VisitObjCIvarRefExpr()
2301 bool VisitBlockExpr(const BlockExpr *E) { return true; } in VisitBlockExpr() argument
2302 bool VisitPredefinedExpr(const PredefinedExpr *E) { return false; } in VisitPredefinedExpr() argument
2303 bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) in VisitCompoundLiteralExpr() argument
2304 { return Visit(E->getInitializer()); } in VisitCompoundLiteralExpr()
2305 bool VisitMemberExpr(const MemberExpr *E) { return Visit(E->getBase()); } in VisitMemberExpr() argument
2306 bool VisitIntegerLiteral(const IntegerLiteral *E) { return false; } in VisitIntegerLiteral() argument
2307 bool VisitFloatingLiteral(const FloatingLiteral *E) { return false; } in VisitFloatingLiteral() argument
2308 bool VisitStringLiteral(const StringLiteral *E) { return false; } in VisitStringLiteral() argument
2309 bool VisitCharacterLiteral(const CharacterLiteral *E) { return false; } in VisitCharacterLiteral() argument
2310 bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E) in VisitUnaryExprOrTypeTraitExpr() argument
2312 bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E) in VisitArraySubscriptExpr() argument
2313 { return Visit(E->getLHS()) || Visit(E->getRHS()); } in VisitArraySubscriptExpr()
2314 bool VisitChooseExpr(const ChooseExpr *E) in VisitChooseExpr() argument
2315 { return Visit(E->getChosenSubExpr(Ctx)); } in VisitChooseExpr()
2316 bool VisitCastExpr(const CastExpr *E) { return Visit(E->getSubExpr()); } in VisitCastExpr() argument
2317 bool VisitBinAssign(const BinaryOperator *E) { return true; } in VisitBinAssign() argument
2318 bool VisitCompoundAssignOperator(const BinaryOperator *E) { return true; } in VisitCompoundAssignOperator() argument
2319 bool VisitBinaryOperator(const BinaryOperator *E) in VisitBinaryOperator() argument
2320 { return Visit(E->getLHS()) || Visit(E->getRHS()); } in VisitBinaryOperator()
2321 bool VisitUnaryPreInc(const UnaryOperator *E) { return true; } in VisitUnaryPreInc() argument
2322 bool VisitUnaryPostInc(const UnaryOperator *E) { return true; } in VisitUnaryPostInc() argument
2323 bool VisitUnaryPreDec(const UnaryOperator *E) { return true; } in VisitUnaryPreDec() argument
2324 bool VisitUnaryPostDec(const UnaryOperator *E) { return true; } in VisitUnaryPostDec() argument
2325 bool VisitUnaryDeref(const UnaryOperator *E) { in VisitUnaryDeref() argument
2326 if (Ctx.getCanonicalType(E->getType()).isVolatileQualified()) in VisitUnaryDeref()
2328 return Visit(E->getSubExpr()); in VisitUnaryDeref()
2330 bool VisitUnaryOperator(const UnaryOperator *E) { return Visit(E->getSubExpr()); } in VisitUnaryOperator() argument
2333 bool VisitInitListExpr(const InitListExpr *E) { in VisitInitListExpr() argument
2334 for (unsigned i = 0, e = E->getNumInits(); i != e; ++i) in VisitInitListExpr()
2335 if (Visit(E->getInit(i))) return true; in VisitInitListExpr()
2336 if (const Expr *filler = E->getArrayFiller()) in VisitInitListExpr()
2382 RetTy DerivedSuccess(const APValue &V, const Expr *E) { in DerivedSuccess() argument
2383 return static_cast<Derived*>(this)->Success(V, E); in DerivedSuccess()
2385 RetTy DerivedZeroInitialization(const Expr *E) { in DerivedZeroInitialization() argument
2386 return static_cast<Derived*>(this)->ZeroInitialization(E); in DerivedZeroInitialization()
2393 void CheckPotentialConstantConditional(const ConditionalOperator *E) { in CheckPotentialConstantConditional() argument
2401 StmtVisitorTy::Visit(E->getFalseExpr()); in CheckPotentialConstantConditional()
2406 StmtVisitorTy::Visit(E->getTrueExpr()); in CheckPotentialConstantConditional()
2411 Error(E, diag::note_constexpr_conditional_never_const); in CheckPotentialConstantConditional()
2416 bool HandleConditionalOperator(const ConditionalOperator *E) { in HandleConditionalOperator() argument
2418 if (!EvaluateAsBooleanCondition(E->getCond(), BoolResult, Info)) { in HandleConditionalOperator()
2420 CheckPotentialConstantConditional(E); in HandleConditionalOperator()
2424 Expr *EvalExpr = BoolResult ? E->getTrueExpr() : E->getFalseExpr(); in HandleConditionalOperator()
2433 OptionalDiagnostic CCEDiag(const Expr *E, diag::kind D) { in CCEDiag() argument
2434 return Info.CCEDiag(E, D); in CCEDiag()
2437 RetTy ZeroInitialization(const Expr *E) { return Error(E); } in ZeroInitialization() argument
2446 bool Error(const Expr *E, diag::kind D) { in Error() argument
2447 Info.Diag(E, D); in Error()
2450 bool Error(const Expr *E) { in Error() argument
2451 return Error(E, diag::note_invalid_subexpr_in_const_expr); in Error()
2457 RetTy VisitExpr(const Expr *E) { in VisitExpr() argument
2458 return Error(E); in VisitExpr()
2461 RetTy VisitParenExpr(const ParenExpr *E) in VisitParenExpr() argument
2462 { return StmtVisitorTy::Visit(E->getSubExpr()); } in VisitParenExpr()
2463 RetTy VisitUnaryExtension(const UnaryOperator *E) in VisitUnaryExtension() argument
2464 { return StmtVisitorTy::Visit(E->getSubExpr()); } in VisitUnaryExtension()
2465 RetTy VisitUnaryPlus(const UnaryOperator *E) in VisitUnaryPlus() argument
2466 { return StmtVisitorTy::Visit(E->getSubExpr()); } in VisitUnaryPlus()
2467 RetTy VisitChooseExpr(const ChooseExpr *E) in VisitChooseExpr() argument
2468 { return StmtVisitorTy::Visit(E->getChosenSubExpr(Info.Ctx)); } in VisitChooseExpr()
2469 RetTy VisitGenericSelectionExpr(const GenericSelectionExpr *E) in VisitGenericSelectionExpr() argument
2470 { return StmtVisitorTy::Visit(E->getResultExpr()); } in VisitGenericSelectionExpr()
2471 RetTy VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E) in VisitSubstNonTypeTemplateParmExpr() argument
2472 { return StmtVisitorTy::Visit(E->getReplacement()); } in VisitSubstNonTypeTemplateParmExpr()
2473 RetTy VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E) in VisitCXXDefaultArgExpr() argument
2474 { return StmtVisitorTy::Visit(E->getExpr()); } in VisitCXXDefaultArgExpr()
2477 RetTy VisitExprWithCleanups(const ExprWithCleanups *E) in VisitExprWithCleanups() argument
2478 { return StmtVisitorTy::Visit(E->getSubExpr()); } in VisitExprWithCleanups()
2480 RetTy VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E) { in VisitCXXReinterpretCastExpr() argument
2481 CCEDiag(E, diag::note_constexpr_invalid_cast) << 0; in VisitCXXReinterpretCastExpr()
2482 return static_cast<Derived*>(this)->VisitCastExpr(E); in VisitCXXReinterpretCastExpr()
2484 RetTy VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *E) { in VisitCXXDynamicCastExpr() argument
2485 CCEDiag(E, diag::note_constexpr_invalid_cast) << 1; in VisitCXXDynamicCastExpr()
2486 return static_cast<Derived*>(this)->VisitCastExpr(E); in VisitCXXDynamicCastExpr()
2489 RetTy VisitBinaryOperator(const BinaryOperator *E) { in VisitBinaryOperator() argument
2490 switch (E->getOpcode()) { in VisitBinaryOperator()
2492 return Error(E); in VisitBinaryOperator()
2495 VisitIgnoredValue(E->getLHS()); in VisitBinaryOperator()
2496 return StmtVisitorTy::Visit(E->getRHS()); in VisitBinaryOperator()
2501 if (!HandleMemberPointerAccess(Info, E, Obj)) in VisitBinaryOperator()
2504 if (!HandleLValueToRValueConversion(Info, E, E->getType(), Obj, Result)) in VisitBinaryOperator()
2506 return DerivedSuccess(Result, E); in VisitBinaryOperator()
2511 RetTy VisitBinaryConditionalOperator(const BinaryConditionalOperator *E) { in VisitBinaryConditionalOperator() argument
2513 OpaqueValueEvaluation opaque(Info, E->getOpaqueValue(), E->getCommon()); in VisitBinaryConditionalOperator()
2517 return HandleConditionalOperator(E); in VisitBinaryConditionalOperator()
2520 RetTy VisitConditionalOperator(const ConditionalOperator *E) { in VisitConditionalOperator() argument
2527 dyn_cast<CallExpr>(E->getCond()->IgnoreParenCasts())) in VisitConditionalOperator()
2538 if (!HandleConditionalOperator(E)) in VisitConditionalOperator()
2547 RetTy VisitOpaqueValueExpr(const OpaqueValueExpr *E) { in VisitOpaqueValueExpr() argument
2548 const APValue *Value = Info.getOpaqueValue(E); in VisitOpaqueValueExpr()
2550 const Expr *Source = E->getSourceExpr(); in VisitOpaqueValueExpr()
2552 return Error(E); in VisitOpaqueValueExpr()
2553 if (Source == E) { // sanity checking. in VisitOpaqueValueExpr()
2555 return Error(E); in VisitOpaqueValueExpr()
2559 return DerivedSuccess(*Value, E); in VisitOpaqueValueExpr()
2562 RetTy VisitCallExpr(const CallExpr *E) { in VisitCallExpr() argument
2563 const Expr *Callee = E->getCallee()->IgnoreParens(); in VisitCallExpr()
2568 llvm::ArrayRef<const Expr*> Args(E->getArgs(), E->getNumArgs()); in VisitCallExpr()
2612 return Error(E); in VisitCallExpr()
2622 return Error(E); in VisitCallExpr()
2624 return Error(E); in VisitCallExpr()
2626 if (This && !This->checkSubobject(Info, E, CSK_This)) in VisitCallExpr()
2633 return Error(E, diag::note_constexpr_virtual_call); in VisitCallExpr()
2639 if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition) || in VisitCallExpr()
2640 !HandleFunctionCall(E->getExprLoc(), Definition, This, Args, Body, in VisitCallExpr()
2644 return DerivedSuccess(Result, E); in VisitCallExpr()
2647 RetTy VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) { in VisitCompoundLiteralExpr() argument
2648 return StmtVisitorTy::Visit(E->getInitializer()); in VisitCompoundLiteralExpr()
2650 RetTy VisitInitListExpr(const InitListExpr *E) { in VisitInitListExpr() argument
2651 if (E->getNumInits() == 0) in VisitInitListExpr()
2652 return DerivedZeroInitialization(E); in VisitInitListExpr()
2653 if (E->getNumInits() == 1) in VisitInitListExpr()
2654 return StmtVisitorTy::Visit(E->getInit(0)); in VisitInitListExpr()
2655 return Error(E); in VisitInitListExpr()
2657 RetTy VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E) { in VisitImplicitValueInitExpr() argument
2658 return DerivedZeroInitialization(E); in VisitImplicitValueInitExpr()
2660 RetTy VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E) { in VisitCXXScalarValueInitExpr() argument
2661 return DerivedZeroInitialization(E); in VisitCXXScalarValueInitExpr()
2663 RetTy VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E) { in VisitCXXNullPtrLiteralExpr() argument
2664 return DerivedZeroInitialization(E); in VisitCXXNullPtrLiteralExpr()
2668 RetTy VisitMemberExpr(const MemberExpr *E) { in VisitMemberExpr() argument
2669 assert(!E->isArrow() && "missing call to bound member function?"); in VisitMemberExpr()
2672 if (!Evaluate(Val, Info, E->getBase())) in VisitMemberExpr()
2675 QualType BaseTy = E->getBase()->getType(); in VisitMemberExpr()
2677 const FieldDecl *FD = dyn_cast<FieldDecl>(E->getMemberDecl()); in VisitMemberExpr()
2678 if (!FD) return Error(E); in VisitMemberExpr()
2686 return ExtractSubobject(Info, E, Val, BaseTy, Designator, E->getType()) && in VisitMemberExpr()
2687 DerivedSuccess(Val, E); in VisitMemberExpr()
2690 RetTy VisitCastExpr(const CastExpr *E) { in VisitCastExpr() argument
2691 switch (E->getCastKind()) { in VisitCastExpr()
2699 return StmtVisitorTy::Visit(E->getSubExpr()); in VisitCastExpr()
2703 if (!EvaluateLValue(E->getSubExpr(), LVal, Info)) in VisitCastExpr()
2707 if (!HandleLValueToRValueConversion(Info, E, E->getSubExpr()->getType(), in VisitCastExpr()
2710 return DerivedSuccess(RVal, E); in VisitCastExpr()
2714 return Error(E); in VisitCastExpr()
2718 void VisitIgnoredValue(const Expr *E) { in VisitIgnoredValue() argument
2720 if (!Evaluate(Scratch, Info, E)) in VisitIgnoredValue()
2748 bool Success(const APValue &V, const Expr *E) { in Success() argument
2753 bool VisitMemberExpr(const MemberExpr *E) { in VisitMemberExpr() argument
2756 if (E->isArrow()) { in VisitMemberExpr()
2757 if (!EvaluatePointer(E->getBase(), Result, this->Info)) in VisitMemberExpr()
2759 BaseTy = E->getBase()->getType()->getAs<PointerType>()->getPointeeType(); in VisitMemberExpr()
2760 } else if (E->getBase()->isRValue()) { in VisitMemberExpr()
2761 assert(E->getBase()->getType()->isRecordType()); in VisitMemberExpr()
2762 if (!EvaluateTemporary(E->getBase(), Result, this->Info)) in VisitMemberExpr()
2764 BaseTy = E->getBase()->getType(); in VisitMemberExpr()
2766 if (!this->Visit(E->getBase())) in VisitMemberExpr()
2768 BaseTy = E->getBase()->getType(); in VisitMemberExpr()
2771 const ValueDecl *MD = E->getMemberDecl(); in VisitMemberExpr()
2772 if (const FieldDecl *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { in VisitMemberExpr()
2776 HandleLValueMember(this->Info, E, Result, FD); in VisitMemberExpr()
2778 HandleLValueIndirectMember(this->Info, E, Result, IFD); in VisitMemberExpr()
2780 return this->Error(E); in VisitMemberExpr()
2784 if (!HandleLValueToRValueConversion(this->Info, E, MD->getType(), Result, in VisitMemberExpr()
2787 return Success(RefValue, E); in VisitMemberExpr()
2792 bool VisitBinaryOperator(const BinaryOperator *E) { in VisitBinaryOperator() argument
2793 switch (E->getOpcode()) { in VisitBinaryOperator()
2795 return ExprEvaluatorBaseTy::VisitBinaryOperator(E); in VisitBinaryOperator()
2799 return HandleMemberPointerAccess(this->Info, E, Result); in VisitBinaryOperator()
2803 bool VisitCastExpr(const CastExpr *E) { in VisitCastExpr() argument
2804 switch (E->getCastKind()) { in VisitCastExpr()
2806 return ExprEvaluatorBaseTy::VisitCastExpr(E); in VisitCastExpr()
2810 if (!this->Visit(E->getSubExpr())) in VisitCastExpr()
2815 QualType Type = E->getSubExpr()->getType(); in VisitCastExpr()
2817 for (CastExpr::path_const_iterator PathI = E->path_begin(), in VisitCastExpr()
2818 PathE = E->path_end(); PathI != PathE; ++PathI) { in VisitCastExpr()
2819 if (!HandleLValueBase(this->Info, E, Result, Type->getAsCXXRecordDecl(), in VisitCastExpr()
2866 bool VisitVarDecl(const Expr *E, const VarDecl *VD);
2868 bool VisitDeclRefExpr(const DeclRefExpr *E);
2869 bool VisitPredefinedExpr(const PredefinedExpr *E) { return Success(E); } in VisitPredefinedExpr() argument
2870 bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
2871 bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
2872 bool VisitMemberExpr(const MemberExpr *E);
2873 bool VisitStringLiteral(const StringLiteral *E) { return Success(E); } in VisitStringLiteral() argument
2874 bool VisitObjCEncodeExpr(const ObjCEncodeExpr *E) { return Success(E); } in VisitObjCEncodeExpr() argument
2875 bool VisitCXXTypeidExpr(const CXXTypeidExpr *E);
2876 bool VisitCXXUuidofExpr(const CXXUuidofExpr *E);
2877 bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E);
2878 bool VisitUnaryDeref(const UnaryOperator *E);
2879 bool VisitUnaryReal(const UnaryOperator *E);
2880 bool VisitUnaryImag(const UnaryOperator *E);
2882 bool VisitCastExpr(const CastExpr *E) { in VisitCastExpr() argument
2883 switch (E->getCastKind()) { in VisitCastExpr()
2885 return LValueExprEvaluatorBaseTy::VisitCastExpr(E); in VisitCastExpr()
2888 this->CCEDiag(E, diag::note_constexpr_invalid_cast) << 2; in VisitCastExpr()
2889 if (!Visit(E->getSubExpr())) in VisitCastExpr()
2895 if (!Visit(E->getSubExpr())) in VisitCastExpr()
2897 return HandleBaseToDerivedCast(Info, E, Result); in VisitCastExpr()
2908 static bool EvaluateLValue(const Expr* E, LValue& Result, EvalInfo &Info) { in EvaluateLValue() argument
2909 assert((E->isGLValue() || E->getType()->isFunctionType() || in EvaluateLValue()
2910 E->getType()->isVoidType() || isa<CXXTemporaryObjectExpr>(E)) && in EvaluateLValue()
2912 return LValueExprEvaluator(Info, Result).Visit(E); in EvaluateLValue()
2915 bool LValueExprEvaluator::VisitDeclRefExpr(const DeclRefExpr *E) { in VisitDeclRefExpr() argument
2916 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(E->getDecl())) in VisitDeclRefExpr()
2918 if (const VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) in VisitDeclRefExpr()
2919 return VisitVarDecl(E, VD); in VisitDeclRefExpr()
2920 return Error(E); in VisitDeclRefExpr()
2923 bool LValueExprEvaluator::VisitVarDecl(const Expr *E, const VarDecl *VD) { in VisitVarDecl() argument
2933 if (!EvaluateVarDeclInit(Info, E, VD, Info.CurrentCall, V)) in VisitVarDecl()
2935 return Success(V, E); in VisitVarDecl()
2939 const MaterializeTemporaryExpr *E) { in VisitMaterializeTemporaryExpr() argument
2940 if (E->GetTemporaryExpr()->isRValue()) { in VisitMaterializeTemporaryExpr()
2941 if (E->getType()->isRecordType()) in VisitMaterializeTemporaryExpr()
2942 return EvaluateTemporary(E->GetTemporaryExpr(), Result, Info); in VisitMaterializeTemporaryExpr()
2944 Result.set(E, Info.CurrentCall->Index); in VisitMaterializeTemporaryExpr()
2945 return EvaluateInPlace(Info.CurrentCall->Temporaries[E], Info, in VisitMaterializeTemporaryExpr()
2946 Result, E->GetTemporaryExpr()); in VisitMaterializeTemporaryExpr()
2952 if (!Visit(E->GetTemporaryExpr())) in VisitMaterializeTemporaryExpr()
2954 if (!HandleLValueToRValueConversion(Info, E, E->getType(), Result, in VisitMaterializeTemporaryExpr()
2955 Info.CurrentCall->Temporaries[E])) in VisitMaterializeTemporaryExpr()
2957 Result.set(E, Info.CurrentCall->Index); in VisitMaterializeTemporaryExpr()
2962 LValueExprEvaluator::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) { in VisitCompoundLiteralExpr() argument
2966 return Success(E); in VisitCompoundLiteralExpr()
2969 bool LValueExprEvaluator::VisitCXXTypeidExpr(const CXXTypeidExpr *E) { in VisitCXXTypeidExpr() argument
2970 if (E->isTypeOperand()) in VisitCXXTypeidExpr()
2971 return Success(E); in VisitCXXTypeidExpr()
2972 CXXRecordDecl *RD = E->getExprOperand()->getType()->getAsCXXRecordDecl(); in VisitCXXTypeidExpr()
2974 Info.Diag(E, diag::note_constexpr_typeid_polymorphic) in VisitCXXTypeidExpr()
2975 << E->getExprOperand()->getType() in VisitCXXTypeidExpr()
2976 << E->getExprOperand()->getSourceRange(); in VisitCXXTypeidExpr()
2979 return Success(E); in VisitCXXTypeidExpr()
2982 bool LValueExprEvaluator::VisitCXXUuidofExpr(const CXXUuidofExpr *E) { in VisitCXXUuidofExpr() argument
2983 return Success(E); in VisitCXXUuidofExpr()
2986 bool LValueExprEvaluator::VisitMemberExpr(const MemberExpr *E) { in VisitMemberExpr() argument
2988 if (const VarDecl *VD = dyn_cast<VarDecl>(E->getMemberDecl())) { in VisitMemberExpr()
2989 VisitIgnoredValue(E->getBase()); in VisitMemberExpr()
2990 return VisitVarDecl(E, VD); in VisitMemberExpr()
2994 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(E->getMemberDecl())) { in VisitMemberExpr()
2996 VisitIgnoredValue(E->getBase()); in VisitMemberExpr()
3002 return LValueExprEvaluatorBaseTy::VisitMemberExpr(E); in VisitMemberExpr()
3005 bool LValueExprEvaluator::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) { in VisitArraySubscriptExpr() argument
3007 if (E->getBase()->getType()->isVectorType()) in VisitArraySubscriptExpr()
3008 return Error(E); in VisitArraySubscriptExpr()
3010 if (!EvaluatePointer(E->getBase(), Result, Info)) in VisitArraySubscriptExpr()
3014 if (!EvaluateInteger(E->getIdx(), Index, Info)) in VisitArraySubscriptExpr()
3020 return HandleLValueArrayAdjustment(Info, E, Result, E->getType(), IndexValue); in VisitArraySubscriptExpr()
3023 bool LValueExprEvaluator::VisitUnaryDeref(const UnaryOperator *E) { in VisitUnaryDeref() argument
3024 return EvaluatePointer(E->getSubExpr(), Result, Info); in VisitUnaryDeref()
3027 bool LValueExprEvaluator::VisitUnaryReal(const UnaryOperator *E) { in VisitUnaryReal() argument
3028 if (!Visit(E->getSubExpr())) in VisitUnaryReal()
3031 if (E->getSubExpr()->getType()->isAnyComplexType()) in VisitUnaryReal()
3032 HandleLValueComplexElement(Info, E, Result, E->getType(), false); in VisitUnaryReal()
3036 bool LValueExprEvaluator::VisitUnaryImag(const UnaryOperator *E) { in VisitUnaryImag() argument
3037 assert(E->getSubExpr()->getType()->isAnyComplexType() && in VisitUnaryImag()
3039 if (!Visit(E->getSubExpr())) in VisitUnaryImag()
3041 HandleLValueComplexElement(Info, E, Result, E->getType(), true); in VisitUnaryImag()
3054 bool Success(const Expr *E) { in Success() argument
3055 Result.set(E); in Success()
3063 bool Success(const APValue &V, const Expr *E) { in Success() argument
3067 bool ZeroInitialization(const Expr *E) { in ZeroInitialization() argument
3071 bool VisitBinaryOperator(const BinaryOperator *E);
3072 bool VisitCastExpr(const CastExpr* E);
3073 bool VisitUnaryAddrOf(const UnaryOperator *E);
3074 bool VisitObjCStringLiteral(const ObjCStringLiteral *E) in VisitObjCStringLiteral() argument
3075 { return Success(E); } in VisitObjCStringLiteral()
3076 bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E) in VisitObjCBoxedExpr() argument
3077 { return Success(E); } in VisitObjCBoxedExpr()
3078 bool VisitAddrLabelExpr(const AddrLabelExpr *E) in VisitAddrLabelExpr() argument
3079 { return Success(E); } in VisitAddrLabelExpr()
3080 bool VisitCallExpr(const CallExpr *E);
3081 bool VisitBlockExpr(const BlockExpr *E) { in VisitBlockExpr() argument
3082 if (!E->getBlockDecl()->hasCaptures()) in VisitBlockExpr()
3083 return Success(E); in VisitBlockExpr()
3084 return Error(E); in VisitBlockExpr()
3086 bool VisitCXXThisExpr(const CXXThisExpr *E) { in VisitCXXThisExpr() argument
3088 return Error(E); in VisitCXXThisExpr()
3097 static bool EvaluatePointer(const Expr* E, LValue& Result, EvalInfo &Info) { in EvaluatePointer() argument
3098 assert(E->isRValue() && E->getType()->hasPointerRepresentation()); in EvaluatePointer()
3099 return PointerExprEvaluator(Info, Result).Visit(E); in EvaluatePointer()
3102 bool PointerExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { in VisitBinaryOperator() argument
3103 if (E->getOpcode() != BO_Add && in VisitBinaryOperator()
3104 E->getOpcode() != BO_Sub) in VisitBinaryOperator()
3105 return ExprEvaluatorBaseTy::VisitBinaryOperator(E); in VisitBinaryOperator()
3107 const Expr *PExp = E->getLHS(); in VisitBinaryOperator()
3108 const Expr *IExp = E->getRHS(); in VisitBinaryOperator()
3122 if (E->getOpcode() == BO_Sub) in VisitBinaryOperator()
3126 return HandleLValueArrayAdjustment(Info, E, Result, Pointee, in VisitBinaryOperator()
3130 bool PointerExprEvaluator::VisitUnaryAddrOf(const UnaryOperator *E) { in VisitUnaryAddrOf() argument
3131 return EvaluateLValue(E->getSubExpr(), Result, Info); in VisitUnaryAddrOf()
3134 bool PointerExprEvaluator::VisitCastExpr(const CastExpr* E) { in VisitCastExpr() argument
3135 const Expr* SubExpr = E->getSubExpr(); in VisitCastExpr()
3137 switch (E->getCastKind()) { in VisitCastExpr()
3150 if (!E->getType()->isVoidPointerType()) { in VisitCastExpr()
3153 CCEDiag(E, diag::note_constexpr_invalid_cast) in VisitCastExpr()
3156 CCEDiag(E, diag::note_constexpr_invalid_cast) << 2; in VisitCastExpr()
3162 if (!EvaluatePointer(E->getSubExpr(), Result, Info)) in VisitCastExpr()
3170 E->getSubExpr()->getType()->castAs<PointerType>()->getPointeeType(); in VisitCastExpr()
3172 for (CastExpr::path_const_iterator PathI = E->path_begin(), in VisitCastExpr()
3173 PathE = E->path_end(); PathI != PathE; ++PathI) { in VisitCastExpr()
3174 if (!HandleLValueBase(Info, E, Result, Type->getAsCXXRecordDecl(), in VisitCastExpr()
3184 if (!Visit(E->getSubExpr())) in VisitCastExpr()
3188 return HandleBaseToDerivedCast(Info, E, Result); in VisitCastExpr()
3191 VisitIgnoredValue(E->getSubExpr()); in VisitCastExpr()
3192 return ZeroInitialization(E); in VisitCastExpr()
3195 CCEDiag(E, diag::note_constexpr_invalid_cast) << 2; in VisitCastExpr()
3202 unsigned Size = Info.Ctx.getTypeSize(E->getType()); in VisitCastExpr()
3228 Result.addArray(Info, E, CAT); in VisitCastExpr()
3237 return ExprEvaluatorBaseTy::VisitCastExpr(E); in VisitCastExpr()
3240 bool PointerExprEvaluator::VisitCallExpr(const CallExpr *E) { in VisitCallExpr() argument
3241 if (IsStringLiteralCall(E)) in VisitCallExpr()
3242 return Success(E); in VisitCallExpr()
3244 return ExprEvaluatorBaseTy::VisitCallExpr(E); in VisitCallExpr()
3265 bool Success(const APValue &V, const Expr *E) { in Success() argument
3269 bool ZeroInitialization(const Expr *E) { in ZeroInitialization() argument
3273 bool VisitCastExpr(const CastExpr *E);
3274 bool VisitUnaryAddrOf(const UnaryOperator *E);
3278 static bool EvaluateMemberPointer(const Expr *E, MemberPtr &Result, in EvaluateMemberPointer() argument
3280 assert(E->isRValue() && E->getType()->isMemberPointerType()); in EvaluateMemberPointer()
3281 return MemberPointerExprEvaluator(Info, Result).Visit(E); in EvaluateMemberPointer()
3284 bool MemberPointerExprEvaluator::VisitCastExpr(const CastExpr *E) { in VisitCastExpr() argument
3285 switch (E->getCastKind()) { in VisitCastExpr()
3287 return ExprEvaluatorBaseTy::VisitCastExpr(E); in VisitCastExpr()
3290 VisitIgnoredValue(E->getSubExpr()); in VisitCastExpr()
3291 return ZeroInitialization(E); in VisitCastExpr()
3294 if (!Visit(E->getSubExpr())) in VisitCastExpr()
3296 if (E->path_empty()) in VisitCastExpr()
3302 for (ReverseIter PathI(E->path_end() - 1), PathE(E->path_begin()); in VisitCastExpr()
3307 return Error(E); in VisitCastExpr()
3309 const Type *FinalTy = E->getType()->castAs<MemberPointerType>()->getClass(); in VisitCastExpr()
3311 return Error(E); in VisitCastExpr()
3316 if (!Visit(E->getSubExpr())) in VisitCastExpr()
3318 for (CastExpr::path_const_iterator PathI = E->path_begin(), in VisitCastExpr()
3319 PathE = E->path_end(); PathI != PathE; ++PathI) { in VisitCastExpr()
3323 return Error(E); in VisitCastExpr()
3329 bool MemberPointerExprEvaluator::VisitUnaryAddrOf(const UnaryOperator *E) { in VisitUnaryAddrOf() argument
3332 return Success(cast<DeclRefExpr>(E->getSubExpr())->getDecl()); in VisitUnaryAddrOf()
3349 bool Success(const APValue &V, const Expr *E) { in Success() argument
3353 bool ZeroInitialization(const Expr *E);
3355 bool VisitCastExpr(const CastExpr *E);
3356 bool VisitInitListExpr(const InitListExpr *E);
3357 bool VisitCXXConstructExpr(const CXXConstructExpr *E);
3368 static bool HandleClassZeroInitialization(EvalInfo &Info, const Expr *E, in HandleClassZeroInitialization() argument
3384 HandleLValueDirectBase(Info, E, Subobject, CD, Base, &Layout); in HandleClassZeroInitialization()
3385 if (!HandleClassZeroInitialization(Info, E, Base, Subobject, in HandleClassZeroInitialization()
3398 HandleLValueMember(Info, E, Subobject, *I, &Layout); in HandleClassZeroInitialization()
3409 bool RecordExprEvaluator::ZeroInitialization(const Expr *E) { in ZeroInitialization() argument
3410 const RecordDecl *RD = E->getType()->castAs<RecordType>()->getDecl(); in ZeroInitialization()
3421 HandleLValueMember(Info, E, Subobject, *I); in ZeroInitialization()
3428 Info.Diag(E, diag::note_constexpr_virtual_base) << RD; in ZeroInitialization()
3432 return HandleClassZeroInitialization(Info, E, RD, This, Result); in ZeroInitialization()
3435 bool RecordExprEvaluator::VisitCastExpr(const CastExpr *E) { in VisitCastExpr() argument
3436 switch (E->getCastKind()) { in VisitCastExpr()
3438 return ExprEvaluatorBaseTy::VisitCastExpr(E); in VisitCastExpr()
3441 return Visit(E->getSubExpr()); in VisitCastExpr()
3446 if (!Evaluate(DerivedObject, Info, E->getSubExpr())) in VisitCastExpr()
3449 return Error(E->getSubExpr()); in VisitCastExpr()
3453 const CXXRecordDecl *RD = E->getSubExpr()->getType()->getAsCXXRecordDecl(); in VisitCastExpr()
3454 for (CastExpr::path_const_iterator PathI = E->path_begin(), in VisitCastExpr()
3455 PathE = E->path_end(); PathI != PathE; ++PathI) { in VisitCastExpr()
3467 bool RecordExprEvaluator::VisitInitListExpr(const InitListExpr *E) { in VisitInitListExpr() argument
3469 if (E->initializesStdInitializerList()) in VisitInitListExpr()
3472 const RecordDecl *RD = E->getType()->castAs<RecordType>()->getDecl(); in VisitInitListExpr()
3476 const FieldDecl *Field = E->getInitializedFieldInUnion(); in VisitInitListExpr()
3484 const Expr *InitExpr = E->getNumInits() ? E->getInit(0) : &VIE; in VisitInitListExpr()
3506 bool HaveInit = ElementNo < E->getNumInits(); in VisitInitListExpr()
3510 HandleLValueMember(Info, HaveInit ? E->getInit(ElementNo) : E, Subobject, in VisitInitListExpr()
3519 Info, Subobject, HaveInit ? E->getInit(ElementNo++) : &VIE)) { in VisitInitListExpr()
3529 bool RecordExprEvaluator::VisitCXXConstructExpr(const CXXConstructExpr *E) { in VisitCXXConstructExpr() argument
3530 const CXXConstructorDecl *FD = E->getConstructor(); in VisitCXXConstructExpr()
3531 bool ZeroInit = E->requiresZeroInitialization(); in VisitCXXConstructExpr()
3532 if (CheckTrivialDefaultConstructor(Info, E->getExprLoc(), FD, ZeroInit)) { in VisitCXXConstructExpr()
3538 return ZeroInitialization(E); in VisitCXXConstructExpr()
3552 if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition)) in VisitCXXConstructExpr()
3556 if (E->isElidable() && !ZeroInit) in VisitCXXConstructExpr()
3558 = dyn_cast<MaterializeTemporaryExpr>(E->getArg(0))) in VisitCXXConstructExpr()
3561 if (ZeroInit && !ZeroInitialization(E)) in VisitCXXConstructExpr()
3564 llvm::ArrayRef<const Expr*> Args(E->getArgs(), E->getNumArgs()); in VisitCXXConstructExpr()
3565 return HandleConstructorCall(E->getExprLoc(), This, Args, in VisitCXXConstructExpr()
3570 static bool EvaluateRecord(const Expr *E, const LValue &This, in EvaluateRecord() argument
3572 assert(E->isRValue() && E->getType()->isRecordType() && in EvaluateRecord()
3574 return RecordExprEvaluator(Info, This, Result).Visit(E); in EvaluateRecord()
3592 bool VisitConstructExpr(const Expr *E) { in VisitConstructExpr() argument
3593 Result.set(E, Info.CurrentCall->Index); in VisitConstructExpr()
3594 return EvaluateInPlace(Info.CurrentCall->Temporaries[E], Info, Result, E); in VisitConstructExpr()
3597 bool VisitCastExpr(const CastExpr *E) { in VisitCastExpr() argument
3598 switch (E->getCastKind()) { in VisitCastExpr()
3600 return LValueExprEvaluatorBaseTy::VisitCastExpr(E); in VisitCastExpr()
3603 return VisitConstructExpr(E->getSubExpr()); in VisitCastExpr()
3606 bool VisitInitListExpr(const InitListExpr *E) { in VisitInitListExpr() argument
3607 return VisitConstructExpr(E); in VisitInitListExpr()
3609 bool VisitCXXConstructExpr(const CXXConstructExpr *E) { in VisitCXXConstructExpr() argument
3610 return VisitConstructExpr(E); in VisitCXXConstructExpr()
3612 bool VisitCallExpr(const CallExpr *E) { in VisitCallExpr() argument
3613 return VisitConstructExpr(E); in VisitCallExpr()
3619 static bool EvaluateTemporary(const Expr *E, LValue &Result, EvalInfo &Info) { in EvaluateTemporary() argument
3620 assert(E->isRValue() && E->getType()->isRecordType()); in EvaluateTemporary()
3621 return TemporaryExprEvaluator(Info, Result).Visit(E); in EvaluateTemporary()
3637 bool Success(const ArrayRef<APValue> &V, const Expr *E) { in Success() argument
3638 assert(V.size() == E->getType()->castAs<VectorType>()->getNumElements()); in Success()
3643 bool Success(const APValue &V, const Expr *E) { in Success() argument
3648 bool ZeroInitialization(const Expr *E);
3650 bool VisitUnaryReal(const UnaryOperator *E) in VisitUnaryReal() argument
3651 { return Visit(E->getSubExpr()); } in VisitUnaryReal()
3652 bool VisitCastExpr(const CastExpr* E);
3653 bool VisitInitListExpr(const InitListExpr *E);
3654 bool VisitUnaryImag(const UnaryOperator *E);
3661 static bool EvaluateVector(const Expr* E, APValue& Result, EvalInfo &Info) { in EvaluateVector() argument
3662 assert(E->isRValue() && E->getType()->isVectorType() &&"not a vector rvalue"); in EvaluateVector()
3663 return VectorExprEvaluator(Info, Result).Visit(E); in EvaluateVector()
3666 bool VectorExprEvaluator::VisitCastExpr(const CastExpr* E) { in VisitCastExpr() argument
3667 const VectorType *VTy = E->getType()->castAs<VectorType>(); in VisitCastExpr()
3670 const Expr *SE = E->getSubExpr(); in VisitCastExpr()
3673 switch (E->getCastKind()) { in VisitCastExpr()
3687 return Error(E); in VisitCastExpr()
3692 return Success(Elts, E); in VisitCastExpr()
3728 return Error(E); in VisitCastExpr()
3730 return Success(Elts, E); in VisitCastExpr()
3733 return ExprEvaluatorBaseTy::VisitCastExpr(E); in VisitCastExpr()
3738 VectorExprEvaluator::VisitInitListExpr(const InitListExpr *E) { in VisitInitListExpr() argument
3739 const VectorType *VT = E->getType()->castAs<VectorType>(); in VisitInitListExpr()
3740 unsigned NumInits = E->getNumInits(); in VisitInitListExpr()
3754 && E->getInit(CountInits)->getType()->isExtVectorType()) { in VisitInitListExpr()
3756 if (!EvaluateVector(E->getInit(CountInits), v, Info)) in VisitInitListExpr()
3757 return Error(E); in VisitInitListExpr()
3765 if (!EvaluateInteger(E->getInit(CountInits), sInt, Info)) in VisitInitListExpr()
3774 if (!EvaluateFloat(E->getInit(CountInits), f, Info)) in VisitInitListExpr()
3783 return Success(Elements, E); in VisitInitListExpr()
3787 VectorExprEvaluator::ZeroInitialization(const Expr *E) { in ZeroInitialization() argument
3788 const VectorType *VT = E->getType()->getAs<VectorType>(); in ZeroInitialization()
3798 return Success(Elements, E); in ZeroInitialization()
3801 bool VectorExprEvaluator::VisitUnaryImag(const UnaryOperator *E) { in VisitUnaryImag() argument
3802 VisitIgnoredValue(E->getSubExpr()); in VisitUnaryImag()
3803 return ZeroInitialization(E); in VisitUnaryImag()
3820 bool Success(const APValue &V, const Expr *E) { in Success() argument
3827 bool ZeroInitialization(const Expr *E) { in ZeroInitialization() argument
3829 Info.Ctx.getAsConstantArrayType(E->getType()); in ZeroInitialization()
3831 return Error(E); in ZeroInitialization()
3839 Subobject.addArray(Info, E, CAT); in ZeroInitialization()
3844 bool VisitInitListExpr(const InitListExpr *E);
3845 bool VisitCXXConstructExpr(const CXXConstructExpr *E);
3849 static bool EvaluateArray(const Expr *E, const LValue &This, in EvaluateArray() argument
3851 assert(E->isRValue() && E->getType()->isArrayType() && "not an array rvalue"); in EvaluateArray()
3852 return ArrayExprEvaluator(Info, This, Result).Visit(E); in EvaluateArray()
3855 bool ArrayExprEvaluator::VisitInitListExpr(const InitListExpr *E) { in VisitInitListExpr() argument
3856 const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(E->getType()); in VisitInitListExpr()
3858 return Error(E); in VisitInitListExpr()
3862 if (E->isStringLiteralInit()) { in VisitInitListExpr()
3864 if (!EvaluateLValue(E->getInit(0), LV, Info)) in VisitInitListExpr()
3868 return Success(Val, E); in VisitInitListExpr()
3873 Result = APValue(APValue::UninitArray(), E->getNumInits(), in VisitInitListExpr()
3876 Subobject.addArray(Info, E, CAT); in VisitInitListExpr()
3878 for (InitListExpr::const_iterator I = E->begin(), End = E->end(); in VisitInitListExpr()
3891 assert(E->hasArrayFiller() && "no array filler for incomplete init list"); in VisitInitListExpr()
3897 Subobject, E->getArrayFiller()) && Success; in VisitInitListExpr()
3900 bool ArrayExprEvaluator::VisitCXXConstructExpr(const CXXConstructExpr *E) { in VisitCXXConstructExpr() argument
3901 const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(E->getType()); in VisitCXXConstructExpr()
3903 return Error(E); in VisitCXXConstructExpr()
3911 const CXXConstructorDecl *FD = E->getConstructor(); in VisitCXXConstructExpr()
3913 bool ZeroInit = E->requiresZeroInitialization(); in VisitCXXConstructExpr()
3914 if (CheckTrivialDefaultConstructor(Info, E->getExprLoc(), FD, ZeroInit)) { in VisitCXXConstructExpr()
3920 Subobject.addArray(Info, E, CAT); in VisitCXXConstructExpr()
3938 if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition)) in VisitCXXConstructExpr()
3946 Subobject.addArray(Info, E, CAT); in VisitCXXConstructExpr()
3954 llvm::ArrayRef<const Expr*> Args(E->getArgs(), E->getNumArgs()); in VisitCXXConstructExpr()
3955 return HandleConstructorCall(E->getExprLoc(), Subobject, Args, in VisitCXXConstructExpr()
3976 bool Success(const llvm::APSInt &SI, const Expr *E, APValue &Result) { in Success() argument
3977 assert(E->getType()->isIntegralOrEnumerationType() && in Success()
3979 assert(SI.isSigned() == E->getType()->isSignedIntegerOrEnumerationType() && in Success()
3981 assert(SI.getBitWidth() == Info.Ctx.getIntWidth(E->getType()) && in Success()
3986 bool Success(const llvm::APSInt &SI, const Expr *E) { in Success() argument
3987 return Success(SI, E, Result); in Success()
3990 bool Success(const llvm::APInt &I, const Expr *E, APValue &Result) { in Success() argument
3991 assert(E->getType()->isIntegralOrEnumerationType() && in Success()
3993 assert(I.getBitWidth() == Info.Ctx.getIntWidth(E->getType()) && in Success()
3997 E->getType()->isUnsignedIntegerOrEnumerationType()); in Success()
4000 bool Success(const llvm::APInt &I, const Expr *E) { in Success() argument
4001 return Success(I, E, Result); in Success()
4004 bool Success(uint64_t Value, const Expr *E, APValue &Result) { in Success() argument
4005 assert(E->getType()->isIntegralOrEnumerationType() && in Success()
4007 Result = APValue(Info.Ctx.MakeIntValue(Value, E->getType())); in Success()
4010 bool Success(uint64_t Value, const Expr *E) { in Success() argument
4011 return Success(Value, E, Result); in Success()
4014 bool Success(CharUnits Size, const Expr *E) { in Success() argument
4015 return Success(Size.getQuantity(), E); in Success()
4018 bool Success(const APValue &V, const Expr *E) { in Success() argument
4023 return Success(V.getInt(), E); in Success()
4026 bool ZeroInitialization(const Expr *E) { return Success(0, E); } in ZeroInitialization() argument
4032 bool VisitIntegerLiteral(const IntegerLiteral *E) { in VisitIntegerLiteral() argument
4033 return Success(E->getValue(), E); in VisitIntegerLiteral()
4035 bool VisitCharacterLiteral(const CharacterLiteral *E) { in VisitCharacterLiteral() argument
4036 return Success(E->getValue(), E); in VisitCharacterLiteral()
4039 bool CheckReferencedDecl(const Expr *E, const Decl *D);
4040 bool VisitDeclRefExpr(const DeclRefExpr *E) { in VisitDeclRefExpr() argument
4041 if (CheckReferencedDecl(E, E->getDecl())) in VisitDeclRefExpr()
4044 return ExprEvaluatorBaseTy::VisitDeclRefExpr(E); in VisitDeclRefExpr()
4046 bool VisitMemberExpr(const MemberExpr *E) { in VisitMemberExpr() argument
4047 if (CheckReferencedDecl(E, E->getMemberDecl())) { in VisitMemberExpr()
4048 VisitIgnoredValue(E->getBase()); in VisitMemberExpr()
4052 return ExprEvaluatorBaseTy::VisitMemberExpr(E); in VisitMemberExpr()
4055 bool VisitCallExpr(const CallExpr *E);
4056 bool VisitBinaryOperator(const BinaryOperator *E);
4057 bool VisitOffsetOfExpr(const OffsetOfExpr *E);
4058 bool VisitUnaryOperator(const UnaryOperator *E);
4060 bool VisitCastExpr(const CastExpr* E);
4061 bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E);
4063 bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) { in VisitCXXBoolLiteralExpr() argument
4064 return Success(E->getValue(), E); in VisitCXXBoolLiteralExpr()
4067 bool VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *E) { in VisitObjCBoolLiteralExpr() argument
4068 return Success(E->getValue(), E); in VisitObjCBoolLiteralExpr()
4072 bool VisitGNUNullExpr(const GNUNullExpr *E) { in VisitGNUNullExpr() argument
4073 return ZeroInitialization(E); in VisitGNUNullExpr()
4076 bool VisitUnaryTypeTraitExpr(const UnaryTypeTraitExpr *E) { in VisitUnaryTypeTraitExpr() argument
4077 return Success(E->getValue(), E); in VisitUnaryTypeTraitExpr()
4080 bool VisitBinaryTypeTraitExpr(const BinaryTypeTraitExpr *E) { in VisitBinaryTypeTraitExpr() argument
4081 return Success(E->getValue(), E); in VisitBinaryTypeTraitExpr()
4084 bool VisitTypeTraitExpr(const TypeTraitExpr *E) { in VisitTypeTraitExpr() argument
4085 return Success(E->getValue(), E); in VisitTypeTraitExpr()
4088 bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E) { in VisitArrayTypeTraitExpr() argument
4089 return Success(E->getValue(), E); in VisitArrayTypeTraitExpr()
4092 bool VisitExpressionTraitExpr(const ExpressionTraitExpr *E) { in VisitExpressionTraitExpr() argument
4093 return Success(E->getValue(), E); in VisitExpressionTraitExpr()
4096 bool VisitUnaryReal(const UnaryOperator *E);
4097 bool VisitUnaryImag(const UnaryOperator *E);
4099 bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E);
4100 bool VisitSizeOfPackExpr(const SizeOfPackExpr *E);
4103 CharUnits GetAlignOfExpr(const Expr *E);
4106 bool TryEvaluateBuiltinObjectSize(const CallExpr *E);
4119 static bool EvaluateIntegerOrLValue(const Expr *E, APValue &Result, in EvaluateIntegerOrLValue() argument
4121 assert(E->isRValue() && E->getType()->isIntegralOrEnumerationType()); in EvaluateIntegerOrLValue()
4122 return IntExprEvaluator(Info, Result).Visit(E); in EvaluateIntegerOrLValue()
4125 static bool EvaluateInteger(const Expr *E, APSInt &Result, EvalInfo &Info) { in EvaluateInteger() argument
4127 if (!EvaluateIntegerOrLValue(E, Val, Info)) in EvaluateInteger()
4132 Info.Diag(E, diag::note_invalid_subexpr_in_const_expr); in EvaluateInteger()
4142 bool IntExprEvaluator::CheckReferencedDecl(const Expr* E, const Decl* D) { in CheckReferencedDecl() argument
4147 == E->getType()->isSignedIntegerOrEnumerationType()); in CheckReferencedDecl()
4149 == Info.Ctx.getIntWidth(E->getType())); in CheckReferencedDecl()
4151 return Success(ECD->getInitVal(), E); in CheckReferencedDecl()
4159 Val = Val.extOrTrunc(Info.Ctx.getIntWidth(E->getType())); in CheckReferencedDecl()
4160 return Success(Val, E); in CheckReferencedDecl()
4168 static int EvaluateBuiltinClassifyType(const CallExpr *E) { in EvaluateBuiltinClassifyType() argument
4185 if (E->getNumArgs() == 0) in EvaluateBuiltinClassifyType()
4188 QualType ArgTy = E->getArg(0)->getType(); in EvaluateBuiltinClassifyType()
4228 const Expr *E = LV.getLValueBase().template dyn_cast<const Expr*>(); in EvaluateBuiltinConstantPForLValue() local
4229 return E && isa<StringLiteral>(E) && LV.getLValueOffset().isZero(); in EvaluateBuiltinConstantPForLValue()
4282 } else if (const Expr *E = B.get<const Expr*>()) { in GetObjectType() local
4283 if (isa<CompoundLiteralExpr>(E)) in GetObjectType()
4284 return E->getType(); in GetObjectType()
4290 bool IntExprEvaluator::TryEvaluateBuiltinObjectSize(const CallExpr *E) { in TryEvaluateBuiltinObjectSize() argument
4293 if (!EvaluatePointer(E->getArg(0), Base, Info)) in TryEvaluateBuiltinObjectSize()
4297 if (!Base.getLValueBase()) return Success(0, E); in TryEvaluateBuiltinObjectSize()
4305 return Error(E); in TryEvaluateBuiltinObjectSize()
4314 return Success(Size, E); in TryEvaluateBuiltinObjectSize()
4317 bool IntExprEvaluator::VisitCallExpr(const CallExpr *E) { in VisitCallExpr() argument
4318 switch (unsigned BuiltinOp = E->isBuiltinCall()) { in VisitCallExpr()
4320 return ExprEvaluatorBaseTy::VisitCallExpr(E); in VisitCallExpr()
4323 if (TryEvaluateBuiltinObjectSize(E)) in VisitCallExpr()
4328 if (E->getArg(0)->HasSideEffects(Info.Ctx)) { in VisitCallExpr()
4329 if (E->getArg(1)->EvaluateKnownConstInt(Info.Ctx).getZExtValue() <= 1) in VisitCallExpr()
4330 return Success(-1ULL, E); in VisitCallExpr()
4331 return Success(0, E); in VisitCallExpr()
4334 return Error(E); in VisitCallExpr()
4338 return Success(EvaluateBuiltinClassifyType(E), E); in VisitCallExpr()
4341 return Success(EvaluateBuiltinConstantP(Info.Ctx, E->getArg(0)), E); in VisitCallExpr()
4344 int Operand = E->getArg(0)->EvaluateKnownConstInt(Info.Ctx).getZExtValue(); in VisitCallExpr()
4346 return Success(Operand, E); in VisitCallExpr()
4350 return Visit(E->getArg(0)); in VisitCallExpr()
4355 Info.CCEDiag(E, diag::note_constexpr_invalid_function) in VisitCallExpr()
4358 Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr); in VisitCallExpr()
4364 = dyn_cast<StringLiteral>(E->getArg(0)->IgnoreParenImpCasts())) { in VisitCallExpr()
4372 return Success(Str.size(), E); in VisitCallExpr()
4375 return Error(E); in VisitCallExpr()
4381 if (!EvaluateInteger(E->getArg(0), SizeVal, Info)) in VisitCallExpr()
4402 E->getArg(1)->isNullPointerConstant(Info.Ctx, in VisitCallExpr()
4406 return Success(1, E); in VisitCallExpr()
4408 QualType PointeeType = E->getArg(1)->IgnoreImpCasts()->getType()-> in VisitCallExpr()
4413 return Success(1, E); in VisitCallExpr()
4419 Success(0, E) : Error(E); in VisitCallExpr()
4448 static APSInt CheckedIntArithmetic(EvalInfo &Info, const Expr *E, in CheckedIntArithmetic() argument
4457 HandleOverflow(Info, E, Value, E->getType()); in CheckedIntArithmetic()
4483 const Expr *E; member
4517 static bool shouldEnqueue(const BinaryOperator *E) { in shouldEnqueue() argument
4518 return E->getOpcode() == BO_Comma || in shouldEnqueue()
4519 E->isLogicalOp() || in shouldEnqueue()
4520 (E->getLHS()->getType()->isIntegralOrEnumerationType() && in shouldEnqueue()
4521 E->getRHS()->getType()->isIntegralOrEnumerationType()); in shouldEnqueue()
4524 bool Traverse(const BinaryOperator *E) { in Traverse() argument
4525 enqueue(E); in Traverse()
4537 bool Success(uint64_t Value, const Expr *E, APValue &Result) { in Success() argument
4538 return IntEval.Success(Value, E, Result); in Success()
4540 bool Success(const APSInt &Value, const Expr *E, APValue &Result) { in Success() argument
4541 return IntEval.Success(Value, E, Result); in Success()
4543 bool Error(const Expr *E) { in Error() argument
4544 return IntEval.Error(E); in Error()
4546 bool Error(const Expr *E, diag::kind D) { in Error() argument
4547 return IntEval.Error(E, D); in Error()
4550 OptionalDiagnostic CCEDiag(const Expr *E, diag::kind D) { in CCEDiag() argument
4551 return Info.CCEDiag(E, D); in CCEDiag()
4555 bool VisitBinOpLHSOnly(EvalResult &LHSResult, const BinaryOperator *E,
4559 const BinaryOperator *E, APValue &Result);
4561 void EvaluateExpr(const Expr *E, EvalResult &Result) { in EvaluateExpr() argument
4562 Result.Failed = !Evaluate(Result.Val, Info, E); in EvaluateExpr()
4569 void enqueue(const Expr *E) { in enqueue() argument
4570 E = E->IgnoreParens(); in enqueue()
4572 Queue.back().E = E; in enqueue()
4580 VisitBinOpLHSOnly(EvalResult &LHSResult, const BinaryOperator *E, in VisitBinOpLHSOnly() argument
4582 if (E->getOpcode() == BO_Comma) { in VisitBinOpLHSOnly()
4589 if (E->isLogicalOp()) { in VisitBinOpLHSOnly()
4594 if (lhsResult == (E->getOpcode() == BO_LOr)) { in VisitBinOpLHSOnly()
4595 Success(lhsResult, E, LHSResult.Val); in VisitBinOpLHSOnly()
4612 assert(E->getLHS()->getType()->isIntegralOrEnumerationType() && in VisitBinOpLHSOnly()
4613 E->getRHS()->getType()->isIntegralOrEnumerationType()); in VisitBinOpLHSOnly()
4623 const BinaryOperator *E, APValue &Result) { in VisitBinOp() argument
4624 if (E->getOpcode() == BO_Comma) { in VisitBinOp()
4631 if (E->isLogicalOp()) { in VisitBinOp()
4638 if (E->getOpcode() == BO_LOr) in VisitBinOp()
4639 return Success(lhsResult || rhsResult, E, Result); in VisitBinOp()
4641 return Success(lhsResult && rhsResult, E, Result); in VisitBinOp()
4647 if (rhsResult == (E->getOpcode() == BO_LOr)) in VisitBinOp()
4648 return Success(rhsResult, E, Result); in VisitBinOp()
4655 assert(E->getLHS()->getType()->isIntegralOrEnumerationType() && in VisitBinOp()
4656 E->getRHS()->getType()->isIntegralOrEnumerationType()); in VisitBinOp()
4665 if (E->isAdditiveOp() && LHSVal.isLValue() && RHSVal.isInt()) { in VisitBinOp()
4669 if (E->getOpcode() == BO_Add) in VisitBinOp()
4677 if (E->getOpcode() == BO_Add && in VisitBinOp()
4685 if (E->getOpcode() == BO_Sub && LHSVal.isLValue() && RHSVal.isLValue()) { in VisitBinOp()
4708 return Error(E); in VisitBinOp()
4713 switch (E->getOpcode()) { in VisitBinOp()
4715 return Error(E); in VisitBinOp()
4717 return Success(CheckedIntArithmetic(Info, E, LHS, RHS, in VisitBinOp()
4719 std::multiplies<APSInt>()), E, in VisitBinOp()
4722 return Success(CheckedIntArithmetic(Info, E, LHS, RHS, in VisitBinOp()
4724 std::plus<APSInt>()), E, Result); in VisitBinOp()
4726 return Success(CheckedIntArithmetic(Info, E, LHS, RHS, in VisitBinOp()
4728 std::minus<APSInt>()), E, Result); in VisitBinOp()
4729 case BO_And: return Success(LHS & RHS, E, Result); in VisitBinOp()
4730 case BO_Xor: return Success(LHS ^ RHS, E, Result); in VisitBinOp()
4731 case BO_Or: return Success(LHS | RHS, E, Result); in VisitBinOp()
4735 return Error(E, diag::note_expr_divide_by_zero); in VisitBinOp()
4740 HandleOverflow(Info, E, -LHS.extend(LHS.getBitWidth() + 1), E->getType()); in VisitBinOp()
4741 return Success(E->getOpcode() == BO_Rem ? LHS % RHS : LHS / RHS, E, in VisitBinOp()
4747 CCEDiag(E, diag::note_constexpr_negative_shift) << RHS; in VisitBinOp()
4757 CCEDiag(E, diag::note_constexpr_large_shift) in VisitBinOp()
4758 << RHS << E->getType() << LHS.getBitWidth(); in VisitBinOp()
4763 CCEDiag(E, diag::note_constexpr_lshift_of_negative) << LHS; in VisitBinOp()
4765 CCEDiag(E, diag::note_constexpr_lshift_discards); in VisitBinOp()
4768 return Success(LHS << SA, E, Result); in VisitBinOp()
4774 CCEDiag(E, diag::note_constexpr_negative_shift) << RHS; in VisitBinOp()
4784 CCEDiag(E, diag::note_constexpr_large_shift) in VisitBinOp()
4785 << RHS << E->getType() << LHS.getBitWidth(); in VisitBinOp()
4787 return Success(LHS >> SA, E, Result); in VisitBinOp()
4790 case BO_LT: return Success(LHS < RHS, E, Result); in VisitBinOp()
4791 case BO_GT: return Success(LHS > RHS, E, Result); in VisitBinOp()
4792 case BO_LE: return Success(LHS <= RHS, E, Result); in VisitBinOp()
4793 case BO_GE: return Success(LHS >= RHS, E, Result); in VisitBinOp()
4794 case BO_EQ: return Success(LHS == RHS, E, Result); in VisitBinOp()
4795 case BO_NE: return Success(LHS != RHS, E, Result); in VisitBinOp()
4804 if (const BinaryOperator *Bop = dyn_cast<BinaryOperator>(job.E)) { in process()
4812 EvaluateExpr(job.E, Result); in process()
4818 const BinaryOperator *Bop = cast<BinaryOperator>(job.E); in process()
4833 const BinaryOperator *Bop = cast<BinaryOperator>(job.E); in process()
4845 bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { in VisitBinaryOperator() argument
4846 if (E->isAssignmentOp()) in VisitBinaryOperator()
4847 return Error(E); in VisitBinaryOperator()
4849 if (DataRecursiveIntBinOpEvaluator::shouldEnqueue(E)) in VisitBinaryOperator()
4850 return DataRecursiveIntBinOpEvaluator(*this, Result).Traverse(E); in VisitBinaryOperator()
4852 QualType LHSTy = E->getLHS()->getType(); in VisitBinaryOperator()
4853 QualType RHSTy = E->getRHS()->getType(); in VisitBinaryOperator()
4859 bool LHSOK = EvaluateComplex(E->getLHS(), LHS, Info); in VisitBinaryOperator()
4863 if (!EvaluateComplex(E->getRHS(), RHS, Info) || !LHSOK) in VisitBinaryOperator()
4872 if (E->getOpcode() == BO_EQ) in VisitBinaryOperator()
4874 CR_i == APFloat::cmpEqual), E); in VisitBinaryOperator()
4876 assert(E->getOpcode() == BO_NE && in VisitBinaryOperator()
4883 CR_i == APFloat::cmpUnordered)), E); in VisitBinaryOperator()
4886 if (E->getOpcode() == BO_EQ) in VisitBinaryOperator()
4888 LHS.getComplexIntImag() == RHS.getComplexIntImag()), E); in VisitBinaryOperator()
4890 assert(E->getOpcode() == BO_NE && in VisitBinaryOperator()
4893 LHS.getComplexIntImag() != RHS.getComplexIntImag()), E); in VisitBinaryOperator()
4902 bool LHSOK = EvaluateFloat(E->getRHS(), RHS, Info); in VisitBinaryOperator()
4906 if (!EvaluateFloat(E->getLHS(), LHS, Info) || !LHSOK) in VisitBinaryOperator()
4911 switch (E->getOpcode()) { in VisitBinaryOperator()
4915 return Success(CR == APFloat::cmpLessThan, E); in VisitBinaryOperator()
4917 return Success(CR == APFloat::cmpGreaterThan, E); in VisitBinaryOperator()
4919 return Success(CR == APFloat::cmpLessThan || CR == APFloat::cmpEqual, E); in VisitBinaryOperator()
4922 E); in VisitBinaryOperator()
4924 return Success(CR == APFloat::cmpEqual, E); in VisitBinaryOperator()
4928 || CR == APFloat::cmpUnordered, E); in VisitBinaryOperator()
4933 if (E->getOpcode() == BO_Sub || E->isComparisonOp()) { in VisitBinaryOperator()
4936 bool LHSOK = EvaluatePointer(E->getLHS(), LHSValue, Info); in VisitBinaryOperator()
4940 if (!EvaluatePointer(E->getRHS(), RHSValue, Info) || !LHSOK) in VisitBinaryOperator()
4946 if (E->getOpcode() == BO_Sub) { in VisitBinaryOperator()
4967 if (!E->isEqualityOp()) in VisitBinaryOperator()
4968 return Error(E); in VisitBinaryOperator()
4974 return Error(E); in VisitBinaryOperator()
4981 return Error(E); in VisitBinaryOperator()
4985 return Error(E); in VisitBinaryOperator()
4990 return Success(E->getOpcode() == BO_NE, E); in VisitBinaryOperator()
4999 if (E->getOpcode() == BO_Sub) { in VisitBinaryOperator()
5007 CCEDiag(E, diag::note_constexpr_pointer_subtraction_not_same_array); in VisitBinaryOperator()
5009 QualType Type = E->getLHS()->getType(); in VisitBinaryOperator()
5013 if (!HandleSizeof(Info, E->getExprLoc(), ElementType, ElementSize)) in VisitBinaryOperator()
5031 APSInt Result = TrueResult.trunc(Info.Ctx.getIntWidth(E->getType())); in VisitBinaryOperator()
5034 HandleOverflow(Info, E, TrueResult, E->getType()); in VisitBinaryOperator()
5035 return Success(Result, E); in VisitBinaryOperator()
5046 E->isRelationalOp()) in VisitBinaryOperator()
5047 CCEDiag(E, diag::note_constexpr_void_comparison); in VisitBinaryOperator()
5058 E->isRelationalOp()) { in VisitBinaryOperator()
5074 CCEDiag(E, diag::note_constexpr_pointer_comparison_base_classes); in VisitBinaryOperator()
5076 CCEDiag(E, diag::note_constexpr_pointer_comparison_base_field) in VisitBinaryOperator()
5080 CCEDiag(E, diag::note_constexpr_pointer_comparison_base_field) in VisitBinaryOperator()
5085 CCEDiag(E, diag::note_constexpr_pointer_comparison_differing_access) in VisitBinaryOperator()
5104 if (!LHSValue.Base.isNull() && E->isRelationalOp()) { in VisitBinaryOperator()
5107 return Error(E); in VisitBinaryOperator()
5111 return Error(E); in VisitBinaryOperator()
5114 switch (E->getOpcode()) { in VisitBinaryOperator()
5116 case BO_LT: return Success(CompareLHS < CompareRHS, E); in VisitBinaryOperator()
5117 case BO_GT: return Success(CompareLHS > CompareRHS, E); in VisitBinaryOperator()
5118 case BO_LE: return Success(CompareLHS <= CompareRHS, E); in VisitBinaryOperator()
5119 case BO_GE: return Success(CompareLHS >= CompareRHS, E); in VisitBinaryOperator()
5120 case BO_EQ: return Success(CompareLHS == CompareRHS, E); in VisitBinaryOperator()
5121 case BO_NE: return Success(CompareLHS != CompareRHS, E); in VisitBinaryOperator()
5127 assert(E->isEqualityOp() && "unexpected member pointer operation"); in VisitBinaryOperator()
5132 bool LHSOK = EvaluateMemberPointer(E->getLHS(), LHSValue, Info); in VisitBinaryOperator()
5136 if (!EvaluateMemberPointer(E->getRHS(), RHSValue, Info) || !LHSOK) in VisitBinaryOperator()
5144 return Success(E->getOpcode() == BO_EQ ? Equal : !Equal, E); in VisitBinaryOperator()
5151 CCEDiag(E, diag::note_constexpr_compare_virtual_mem_ptr) << MD; in VisitBinaryOperator()
5154 CCEDiag(E, diag::note_constexpr_compare_virtual_mem_ptr) << MD; in VisitBinaryOperator()
5161 return Success(E->getOpcode() == BO_EQ ? Equal : !Equal, E); in VisitBinaryOperator()
5165 assert(E->isComparisonOp() && "unexpected nullptr operation"); in VisitBinaryOperator()
5170 BinaryOperator::Opcode Opcode = E->getOpcode(); in VisitBinaryOperator()
5171 return Success(Opcode == BO_EQ || Opcode == BO_LE || Opcode == BO_GE, E); in VisitBinaryOperator()
5178 return ExprEvaluatorBaseTy::VisitBinaryOperator(E); in VisitBinaryOperator()
5192 CharUnits IntExprEvaluator::GetAlignOfExpr(const Expr *E) { in GetAlignOfExpr() argument
5193 E = E->IgnoreParens(); in GetAlignOfExpr()
5197 if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) in GetAlignOfExpr()
5201 if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) in GetAlignOfExpr()
5205 return GetAlignOfType(E->getType()); in GetAlignOfExpr()
5212 const UnaryExprOrTypeTraitExpr *E) { in VisitUnaryExprOrTypeTraitExpr() argument
5213 switch(E->getKind()) { in VisitUnaryExprOrTypeTraitExpr()
5215 if (E->isArgumentType()) in VisitUnaryExprOrTypeTraitExpr()
5216 return Success(GetAlignOfType(E->getArgumentType()), E); in VisitUnaryExprOrTypeTraitExpr()
5218 return Success(GetAlignOfExpr(E->getArgumentExpr()), E); in VisitUnaryExprOrTypeTraitExpr()
5222 QualType Ty = E->getTypeOfArgument(); in VisitUnaryExprOrTypeTraitExpr()
5232 return Success(n, E); in VisitUnaryExprOrTypeTraitExpr()
5234 return Success(1, E); in VisitUnaryExprOrTypeTraitExpr()
5238 QualType SrcTy = E->getTypeOfArgument(); in VisitUnaryExprOrTypeTraitExpr()
5245 if (!HandleSizeof(Info, E->getExprLoc(), SrcTy, Sizeof)) in VisitUnaryExprOrTypeTraitExpr()
5247 return Success(Sizeof, E); in VisitUnaryExprOrTypeTraitExpr()
5321 bool IntExprEvaluator::VisitUnaryOperator(const UnaryOperator *E) { in VisitUnaryOperator() argument
5322 switch (E->getOpcode()) { in VisitUnaryOperator()
5326 return Error(E); in VisitUnaryOperator()
5330 return Visit(E->getSubExpr()); in VisitUnaryOperator()
5333 return Visit(E->getSubExpr()); in VisitUnaryOperator()
5335 if (!Visit(E->getSubExpr())) in VisitUnaryOperator()
5337 if (!Result.isInt()) return Error(E); in VisitUnaryOperator()
5340 HandleOverflow(Info, E, -Value.extend(Value.getBitWidth() + 1), in VisitUnaryOperator()
5341 E->getType()); in VisitUnaryOperator()
5342 return Success(-Value, E); in VisitUnaryOperator()
5345 if (!Visit(E->getSubExpr())) in VisitUnaryOperator()
5347 if (!Result.isInt()) return Error(E); in VisitUnaryOperator()
5348 return Success(~Result.getInt(), E); in VisitUnaryOperator()
5352 if (!EvaluateAsBooleanCondition(E->getSubExpr(), bres, Info)) in VisitUnaryOperator()
5354 return Success(!bres, E); in VisitUnaryOperator()
5361 bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) { in VisitCastExpr() argument
5362 const Expr *SubExpr = E->getSubExpr(); in VisitCastExpr()
5363 QualType DestType = E->getType(); in VisitCastExpr()
5366 switch (E->getCastKind()) { in VisitCastExpr()
5406 return Error(E); in VisitCastExpr()
5413 return ExprEvaluatorBaseTy::VisitCastExpr(E); in VisitCastExpr()
5424 return Success(BoolResult, E); in VisitCastExpr()
5443 return Success(HandleIntToIntCast(Info, E, DestType, SrcType, in VisitCastExpr()
5444 Result.getInt()), E); in VisitCastExpr()
5448 CCEDiag(E, diag::note_constexpr_invalid_cast) << 2; in VisitCastExpr()
5460 return Error(E); in VisitCastExpr()
5469 return Success(HandleIntToIntCast(Info, E, DestType, SrcType, AsInt), E); in VisitCastExpr()
5476 return Success(C.getComplexIntReal(), E); in VisitCastExpr()
5485 if (!HandleFloatToIntCast(Info, E, SrcType, F, DestType, Value)) in VisitCastExpr()
5487 return Success(Value, E); in VisitCastExpr()
5494 bool IntExprEvaluator::VisitUnaryReal(const UnaryOperator *E) { in VisitUnaryReal() argument
5495 if (E->getSubExpr()->getType()->isAnyComplexType()) { in VisitUnaryReal()
5497 if (!EvaluateComplex(E->getSubExpr(), LV, Info)) in VisitUnaryReal()
5500 return Error(E); in VisitUnaryReal()
5501 return Success(LV.getComplexIntReal(), E); in VisitUnaryReal()
5504 return Visit(E->getSubExpr()); in VisitUnaryReal()
5507 bool IntExprEvaluator::VisitUnaryImag(const UnaryOperator *E) { in VisitUnaryImag() argument
5508 if (E->getSubExpr()->getType()->isComplexIntegerType()) { in VisitUnaryImag()
5510 if (!EvaluateComplex(E->getSubExpr(), LV, Info)) in VisitUnaryImag()
5513 return Error(E); in VisitUnaryImag()
5514 return Success(LV.getComplexIntImag(), E); in VisitUnaryImag()
5517 VisitIgnoredValue(E->getSubExpr()); in VisitUnaryImag()
5518 return Success(0, E); in VisitUnaryImag()
5521 bool IntExprEvaluator::VisitSizeOfPackExpr(const SizeOfPackExpr *E) { in VisitSizeOfPackExpr() argument
5522 return Success(E->getPackLength(), E); in VisitSizeOfPackExpr()
5525 bool IntExprEvaluator::VisitCXXNoexceptExpr(const CXXNoexceptExpr *E) { in VisitCXXNoexceptExpr() argument
5526 return Success(E->getValue(), E); in VisitCXXNoexceptExpr()
5546 bool ZeroInitialization(const Expr *E) { in ZeroInitialization() argument
5547 Result = APFloat::getZero(Info.Ctx.getFloatTypeSemantics(E->getType())); in ZeroInitialization()
5551 bool VisitCallExpr(const CallExpr *E);
5553 bool VisitUnaryOperator(const UnaryOperator *E);
5554 bool VisitBinaryOperator(const BinaryOperator *E);
5555 bool VisitFloatingLiteral(const FloatingLiteral *E);
5556 bool VisitCastExpr(const CastExpr *E);
5558 bool VisitUnaryReal(const UnaryOperator *E);
5559 bool VisitUnaryImag(const UnaryOperator *E);
5565 static bool EvaluateFloat(const Expr* E, APFloat& Result, EvalInfo &Info) { in EvaluateFloat() argument
5566 assert(E->isRValue() && E->getType()->isRealFloatingType()); in EvaluateFloat()
5567 return FloatExprEvaluator(Info, Result).Visit(E); in EvaluateFloat()
5595 bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) { in VisitCallExpr() argument
5596 switch (E->isBuiltinCall()) { in VisitCallExpr()
5598 return ExprEvaluatorBaseTy::VisitCallExpr(E); in VisitCallExpr()
5607 Info.Ctx.getFloatTypeSemantics(E->getType()); in VisitCallExpr()
5615 if (!TryEvaluateBuiltinNaN(Info.Ctx, E->getType(), E->getArg(0), in VisitCallExpr()
5617 return Error(E); in VisitCallExpr()
5625 if (!TryEvaluateBuiltinNaN(Info.Ctx, E->getType(), E->getArg(0), in VisitCallExpr()
5627 return Error(E); in VisitCallExpr()
5633 if (!EvaluateFloat(E->getArg(0), Result, Info)) in VisitCallExpr()
5644 if (!EvaluateFloat(E->getArg(0), Result, Info) || in VisitCallExpr()
5645 !EvaluateFloat(E->getArg(1), RHS, Info)) in VisitCallExpr()
5653 bool FloatExprEvaluator::VisitUnaryReal(const UnaryOperator *E) { in VisitUnaryReal() argument
5654 if (E->getSubExpr()->getType()->isAnyComplexType()) { in VisitUnaryReal()
5656 if (!EvaluateComplex(E->getSubExpr(), CV, Info)) in VisitUnaryReal()
5662 return Visit(E->getSubExpr()); in VisitUnaryReal()
5665 bool FloatExprEvaluator::VisitUnaryImag(const UnaryOperator *E) { in VisitUnaryImag() argument
5666 if (E->getSubExpr()->getType()->isAnyComplexType()) { in VisitUnaryImag()
5668 if (!EvaluateComplex(E->getSubExpr(), CV, Info)) in VisitUnaryImag()
5674 VisitIgnoredValue(E->getSubExpr()); in VisitUnaryImag()
5675 const llvm::fltSemantics &Sem = Info.Ctx.getFloatTypeSemantics(E->getType()); in VisitUnaryImag()
5680 bool FloatExprEvaluator::VisitUnaryOperator(const UnaryOperator *E) { in VisitUnaryOperator() argument
5681 switch (E->getOpcode()) { in VisitUnaryOperator()
5682 default: return Error(E); in VisitUnaryOperator()
5684 return EvaluateFloat(E->getSubExpr(), Result, Info); in VisitUnaryOperator()
5686 if (!EvaluateFloat(E->getSubExpr(), Result, Info)) in VisitUnaryOperator()
5693 bool FloatExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { in VisitBinaryOperator() argument
5694 if (E->isPtrMemOp() || E->isAssignmentOp() || E->getOpcode() == BO_Comma) in VisitBinaryOperator()
5695 return ExprEvaluatorBaseTy::VisitBinaryOperator(E); in VisitBinaryOperator()
5698 bool LHSOK = EvaluateFloat(E->getLHS(), Result, Info); in VisitBinaryOperator()
5701 if (!EvaluateFloat(E->getRHS(), RHS, Info) || !LHSOK) in VisitBinaryOperator()
5704 switch (E->getOpcode()) { in VisitBinaryOperator()
5705 default: return Error(E); in VisitBinaryOperator()
5721 CCEDiag(E, diag::note_constexpr_float_arithmetic) << Result.isNaN(); in VisitBinaryOperator()
5725 bool FloatExprEvaluator::VisitFloatingLiteral(const FloatingLiteral *E) { in VisitFloatingLiteral() argument
5726 Result = E->getValue(); in VisitFloatingLiteral()
5730 bool FloatExprEvaluator::VisitCastExpr(const CastExpr *E) { in VisitCastExpr() argument
5731 const Expr* SubExpr = E->getSubExpr(); in VisitCastExpr()
5733 switch (E->getCastKind()) { in VisitCastExpr()
5735 return ExprEvaluatorBaseTy::VisitCastExpr(E); in VisitCastExpr()
5740 HandleIntToFloatCast(Info, E, SubExpr->getType(), IntResult, in VisitCastExpr()
5741 E->getType(), Result); in VisitCastExpr()
5747 return HandleFloatToFloatCast(Info, E, SubExpr->getType(), E->getType(), in VisitCastExpr()
5779 bool ZeroInitialization(const Expr *E);
5785 bool VisitImaginaryLiteral(const ImaginaryLiteral *E);
5786 bool VisitCastExpr(const CastExpr *E);
5787 bool VisitBinaryOperator(const BinaryOperator *E);
5788 bool VisitUnaryOperator(const UnaryOperator *E);
5789 bool VisitInitListExpr(const InitListExpr *E);
5793 static bool EvaluateComplex(const Expr *E, ComplexValue &Result, in EvaluateComplex() argument
5795 assert(E->isRValue() && E->getType()->isAnyComplexType()); in EvaluateComplex()
5796 return ComplexExprEvaluator(Info, Result).Visit(E); in EvaluateComplex()
5799 bool ComplexExprEvaluator::ZeroInitialization(const Expr *E) { in ZeroInitialization() argument
5800 QualType ElemTy = E->getType()->getAs<ComplexType>()->getElementType(); in ZeroInitialization()
5815 bool ComplexExprEvaluator::VisitImaginaryLiteral(const ImaginaryLiteral *E) { in VisitImaginaryLiteral() argument
5816 const Expr* SubExpr = E->getSubExpr(); in VisitImaginaryLiteral()
5840 bool ComplexExprEvaluator::VisitCastExpr(const CastExpr *E) { in VisitCastExpr() argument
5842 switch (E->getCastKind()) { in VisitCastExpr()
5888 return ExprEvaluatorBaseTy::VisitCastExpr(E); in VisitCastExpr()
5893 return Error(E); in VisitCastExpr()
5897 if (!EvaluateFloat(E->getSubExpr(), Real, Info)) in VisitCastExpr()
5906 if (!Visit(E->getSubExpr())) in VisitCastExpr()
5909 QualType To = E->getType()->getAs<ComplexType>()->getElementType(); in VisitCastExpr()
5911 = E->getSubExpr()->getType()->getAs<ComplexType>()->getElementType(); in VisitCastExpr()
5913 return HandleFloatToFloatCast(Info, E, From, To, Result.FloatReal) && in VisitCastExpr()
5914 HandleFloatToFloatCast(Info, E, From, To, Result.FloatImag); in VisitCastExpr()
5918 if (!Visit(E->getSubExpr())) in VisitCastExpr()
5921 QualType To = E->getType()->getAs<ComplexType>()->getElementType(); in VisitCastExpr()
5923 = E->getSubExpr()->getType()->getAs<ComplexType>()->getElementType(); in VisitCastExpr()
5925 return HandleFloatToIntCast(Info, E, From, Result.FloatReal, in VisitCastExpr()
5927 HandleFloatToIntCast(Info, E, From, Result.FloatImag, in VisitCastExpr()
5933 if (!EvaluateInteger(E->getSubExpr(), Real, Info)) in VisitCastExpr()
5942 if (!Visit(E->getSubExpr())) in VisitCastExpr()
5945 QualType To = E->getType()->getAs<ComplexType>()->getElementType(); in VisitCastExpr()
5947 = E->getSubExpr()->getType()->getAs<ComplexType>()->getElementType(); in VisitCastExpr()
5949 Result.IntReal = HandleIntToIntCast(Info, E, To, From, Result.IntReal); in VisitCastExpr()
5950 Result.IntImag = HandleIntToIntCast(Info, E, To, From, Result.IntImag); in VisitCastExpr()
5955 if (!Visit(E->getSubExpr())) in VisitCastExpr()
5958 QualType To = E->getType()->getAs<ComplexType>()->getElementType(); in VisitCastExpr()
5960 = E->getSubExpr()->getType()->getAs<ComplexType>()->getElementType(); in VisitCastExpr()
5962 return HandleIntToFloatCast(Info, E, From, Result.IntReal, in VisitCastExpr()
5964 HandleIntToFloatCast(Info, E, From, Result.IntImag, in VisitCastExpr()
5972 bool ComplexExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { in VisitBinaryOperator() argument
5973 if (E->isPtrMemOp() || E->isAssignmentOp() || E->getOpcode() == BO_Comma) in VisitBinaryOperator()
5974 return ExprEvaluatorBaseTy::VisitBinaryOperator(E); in VisitBinaryOperator()
5976 bool LHSOK = Visit(E->getLHS()); in VisitBinaryOperator()
5981 if (!EvaluateComplex(E->getRHS(), RHS, Info) || !LHSOK) in VisitBinaryOperator()
5986 switch (E->getOpcode()) { in VisitBinaryOperator()
5987 default: return Error(E); in VisitBinaryOperator()
6072 return Error(E, diag::note_expr_divide_by_zero); in VisitBinaryOperator()
6090 bool ComplexExprEvaluator::VisitUnaryOperator(const UnaryOperator *E) { in VisitUnaryOperator() argument
6092 if (!Visit(E->getSubExpr())) in VisitUnaryOperator()
6095 switch (E->getOpcode()) { in VisitUnaryOperator()
6097 return Error(E); in VisitUnaryOperator()
6122 bool ComplexExprEvaluator::VisitInitListExpr(const InitListExpr *E) { in VisitInitListExpr() argument
6123 if (E->getNumInits() == 2) { in VisitInitListExpr()
6124 if (E->getType()->isComplexType()) { in VisitInitListExpr()
6126 if (!EvaluateFloat(E->getInit(0), Result.FloatReal, Info)) in VisitInitListExpr()
6128 if (!EvaluateFloat(E->getInit(1), Result.FloatImag, Info)) in VisitInitListExpr()
6132 if (!EvaluateInteger(E->getInit(0), Result.IntReal, Info)) in VisitInitListExpr()
6134 if (!EvaluateInteger(E->getInit(1), Result.IntImag, Info)) in VisitInitListExpr()
6139 return ExprEvaluatorBaseTy::VisitInitListExpr(E); in VisitInitListExpr()
6155 bool VisitCastExpr(const CastExpr *E) { in VisitCastExpr() argument
6156 switch (E->getCastKind()) { in VisitCastExpr()
6158 return ExprEvaluatorBaseTy::VisitCastExpr(E); in VisitCastExpr()
6160 VisitIgnoredValue(E->getSubExpr()); in VisitCastExpr()
6167 static bool EvaluateVoid(const Expr *E, EvalInfo &Info) { in EvaluateVoid() argument
6168 assert(E->isRValue() && E->getType()->isVoidType()); in EvaluateVoid()
6169 return VoidExprEvaluator(Info).Visit(E); in EvaluateVoid()
6176 static bool Evaluate(APValue &Result, EvalInfo &Info, const Expr *E) { in Evaluate() argument
6179 if (E->isGLValue() || E->getType()->isFunctionType()) { in Evaluate()
6181 if (!EvaluateLValue(E, LV, Info)) in Evaluate()
6184 } else if (E->getType()->isVectorType()) { in Evaluate()
6185 if (!EvaluateVector(E, Result, Info)) in Evaluate()
6187 } else if (E->getType()->isIntegralOrEnumerationType()) { in Evaluate()
6188 if (!IntExprEvaluator(Info, Result).Visit(E)) in Evaluate()
6190 } else if (E->getType()->hasPointerRepresentation()) { in Evaluate()
6192 if (!EvaluatePointer(E, LV, Info)) in Evaluate()
6195 } else if (E->getType()->isRealFloatingType()) { in Evaluate()
6197 if (!EvaluateFloat(E, F, Info)) in Evaluate()
6200 } else if (E->getType()->isAnyComplexType()) { in Evaluate()
6202 if (!EvaluateComplex(E, C, Info)) in Evaluate()
6205 } else if (E->getType()->isMemberPointerType()) { in Evaluate()
6207 if (!EvaluateMemberPointer(E, P, Info)) in Evaluate()
6211 } else if (E->getType()->isArrayType()) { in Evaluate()
6213 LV.set(E, Info.CurrentCall->Index); in Evaluate()
6214 if (!EvaluateArray(E, LV, Info.CurrentCall->Temporaries[E], Info)) in Evaluate()
6216 Result = Info.CurrentCall->Temporaries[E]; in Evaluate()
6217 } else if (E->getType()->isRecordType()) { in Evaluate()
6219 LV.set(E, Info.CurrentCall->Index); in Evaluate()
6220 if (!EvaluateRecord(E, LV, Info.CurrentCall->Temporaries[E], Info)) in Evaluate()
6222 Result = Info.CurrentCall->Temporaries[E]; in Evaluate()
6223 } else if (E->getType()->isVoidType()) { in Evaluate()
6225 Info.CCEDiag(E, diag::note_constexpr_nonliteral) in Evaluate()
6226 << E->getType(); in Evaluate()
6228 Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr); in Evaluate()
6229 if (!EvaluateVoid(E, Info)) in Evaluate()
6232 Info.Diag(E, diag::note_constexpr_nonliteral) << E->getType(); in Evaluate()
6235 Info.Diag(E, diag::note_invalid_subexpr_in_const_expr); in Evaluate()
6246 const Expr *E, CheckConstantExpressionKind CCEK, in EvaluateInPlace() argument
6248 if (!AllowNonLiteralTypes && !CheckLiteralType(Info, E)) in EvaluateInPlace()
6251 if (E->isRValue()) { in EvaluateInPlace()
6254 if (E->getType()->isArrayType()) in EvaluateInPlace()
6255 return EvaluateArray(E, This, Result, Info); in EvaluateInPlace()
6256 else if (E->getType()->isRecordType()) in EvaluateInPlace()
6257 return EvaluateRecord(E, This, Result, Info); in EvaluateInPlace()
6261 return Evaluate(Result, Info, E); in EvaluateInPlace()
6266 static bool EvaluateAsRValue(EvalInfo &Info, const Expr *E, APValue &Result) { in EvaluateAsRValue() argument
6267 if (!CheckLiteralType(Info, E)) in EvaluateAsRValue()
6270 if (!::Evaluate(Result, Info, E)) in EvaluateAsRValue()
6273 if (E->isGLValue()) { in EvaluateAsRValue()
6276 if (!HandleLValueToRValueConversion(Info, E, E->getType(), LV, Result)) in EvaluateAsRValue()
6281 return CheckConstantExpression(Info, E->getExprLoc(), E->getType(), Result); in EvaluateAsRValue()
6447 static ICEDiag CheckEvalInICE(const Expr* E, ASTContext &Ctx) { in CheckEvalInICE() argument
6449 if (!E->EvaluateAsRValue(EVResult, Ctx) || EVResult.HasSideEffects || in CheckEvalInICE()
6451 return ICEDiag(2, E->getLocStart()); in CheckEvalInICE()
6456 static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) { in CheckICE() argument
6457 assert(!E->isValueDependent() && "Should not see value dependent exprs!"); in CheckICE()
6458 if (!E->getType()->isIntegralOrEnumerationType()) { in CheckICE()
6459 return ICEDiag(2, E->getLocStart()); in CheckICE()
6462 switch (E->getStmtClass()) { in CheckICE()
6528 return ICEDiag(2, E->getLocStart()); in CheckICE()
6537 CheckICE(cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement(), Ctx); in CheckICE()
6540 return CheckICE(cast<ParenExpr>(E)->getSubExpr(), Ctx); in CheckICE()
6542 return CheckICE(cast<GenericSelectionExpr>(E)->getResultExpr(), Ctx); in CheckICE()
6560 const CallExpr *CE = cast<CallExpr>(E); in CheckICE()
6562 return CheckEvalInICE(E, Ctx); in CheckICE()
6563 return ICEDiag(2, E->getLocStart()); in CheckICE()
6566 if (isa<EnumConstantDecl>(cast<DeclRefExpr>(E)->getDecl())) in CheckICE()
6568 const ValueDecl *D = dyn_cast<ValueDecl>(cast<DeclRefExpr>(E)->getDecl()); in CheckICE()
6575 return ICEDiag(2, cast<DeclRefExpr>(E)->getLocation()); in CheckICE()
6582 return ICEDiag(2, cast<DeclRefExpr>(E)->getLocation()); in CheckICE()
6590 return ICEDiag(2, cast<DeclRefExpr>(E)->getLocation()); in CheckICE()
6593 return ICEDiag(2, E->getLocStart()); in CheckICE()
6596 const UnaryOperator *Exp = cast<UnaryOperator>(E); in CheckICE()
6607 return ICEDiag(2, E->getLocStart()); in CheckICE()
6627 return CheckEvalInICE(E, Ctx); in CheckICE()
6630 const UnaryExprOrTypeTraitExpr *Exp = cast<UnaryExprOrTypeTraitExpr>(E); in CheckICE()
6633 return ICEDiag(2, E->getLocStart()); in CheckICE()
6637 const BinaryOperator *Exp = cast<BinaryOperator>(E); in CheckICE()
6655 return ICEDiag(2, E->getLocStart()); in CheckICE()
6683 return ICEDiag(1, E->getLocStart()); in CheckICE()
6687 return ICEDiag(1, E->getLocStart()); in CheckICE()
6696 return ICEDiag(1, E->getLocStart()); in CheckICE()
6699 return ICEDiag(2, E->getLocStart()); in CheckICE()
6733 const Expr *SubExpr = cast<CastExpr>(E)->getSubExpr(); in CheckICE()
6734 if (isa<ExplicitCastExpr>(E)) { in CheckICE()
6737 unsigned DestWidth = Ctx.getIntWidth(E->getType()); in CheckICE()
6738 bool DestSigned = E->getType()->isSignedIntegerOrEnumerationType(); in CheckICE()
6747 return ICEDiag(2, E->getLocStart()); in CheckICE()
6751 switch (cast<CastExpr>(E)->getCastKind()) { in CheckICE()
6760 return ICEDiag(2, E->getLocStart()); in CheckICE()
6764 const BinaryConditionalOperator *Exp = cast<BinaryConditionalOperator>(E); in CheckICE()
6775 const ConditionalOperator *Exp = cast<ConditionalOperator>(E); in CheckICE()
6783 return CheckEvalInICE(E, Ctx); in CheckICE()
6808 return CheckICE(cast<CXXDefaultArgExpr>(E)->getExpr(), Ctx); in CheckICE()
6810 return CheckICE(cast<ChooseExpr>(E)->getChosenSubExpr(Ctx), Ctx); in CheckICE()
6819 const Expr *E, in EvaluateCPlusPlus11IntegralConstantExpr() argument
6822 if (!E->getType()->isIntegralOrEnumerationType()) { in EvaluateCPlusPlus11IntegralConstantExpr()
6823 if (Loc) *Loc = E->getExprLoc(); in EvaluateCPlusPlus11IntegralConstantExpr()
6828 if (!E->isCXX11ConstantExpr(Ctx, &Result, Loc)) in EvaluateCPlusPlus11IntegralConstantExpr()