@@ -60,6 +60,47 @@ namespace clang {
6060 class ValueDecl ;
6161 class WarnUnusedResultAttr ;
6262
63+ // / EvalStatus is a struct with detailed info about an evaluation in progress.
64+ struct EvalStatus {
65+ // / Whether the evaluated expression has side effects.
66+ // / For example, (f() && 0) can be folded, but it still has side effects.
67+ bool HasSideEffects = false ;
68+
69+ // / Whether the evaluation hit undefined behavior.
70+ // / For example, 1.0 / 0.0 can be folded to Inf, but has undefined behavior.
71+ // / Likewise, INT_MAX + 1 can be folded to INT_MIN, but has UB.
72+ bool HasUndefinedBehavior = false ;
73+
74+ bool HasFFDiagnostic = false ;
75+ bool HasCCEDiagnostic = false ;
76+
77+ // / Diag - If this is non-null, it will be filled in with a stack of notes
78+ // / indicating why evaluation failed (or why it failed to produce a constant
79+ // / expression).
80+ // / If the expression is unfoldable, the notes will indicate why it's not
81+ // / foldable. If the expression is foldable, but not a constant expression,
82+ // / the notes will describes why it isn't a constant expression. If the
83+ // / expression *is* a constant expression, no notes will be produced.
84+ // /
85+ // / FIXME: this causes significant performance concerns and should be
86+ // / refactored at some point. Not all evaluations of the constant
87+ // / expression interpreter will display the given diagnostics, this means
88+ // / those kinds of uses are paying the expense of generating a diagnostic
89+ // / (which may include expensive operations like converting APValue objects
90+ // / to a string representation).
91+ SmallVectorImpl<PartialDiagnosticAt> *Diag = nullptr ;
92+
93+ EvalStatus () = default ;
94+
95+ // / Return true if the evaluated expression has
96+ // / side effects.
97+ bool hasSideEffects () const { return HasSideEffects; }
98+
99+ bool hasAnyDiagnostic () const {
100+ return HasFFDiagnostic || HasCCEDiagnostic;
101+ }
102+ };
103+
63104// / A simple array of base specifiers.
64105typedef SmallVector<CXXBaseSpecifier*, 4 > CXXCastPath;
65106
@@ -605,42 +646,6 @@ class Expr : public ValueStmt {
605646 // / expression is a member pointer constant.
606647 const ValueDecl *getAsBuiltinConstantDeclRef (const ASTContext &Context) const ;
607648
608- // / EvalStatus is a struct with detailed info about an evaluation in progress.
609- struct EvalStatus {
610- // / Whether the evaluated expression has side effects.
611- // / For example, (f() && 0) can be folded, but it still has side effects.
612- bool HasSideEffects = false ;
613-
614- // / Whether the evaluation hit undefined behavior.
615- // / For example, 1.0 / 0.0 can be folded to Inf, but has undefined behavior.
616- // / Likewise, INT_MAX + 1 can be folded to INT_MIN, but has UB.
617- bool HasUndefinedBehavior = false ;
618-
619- // / Diag - If this is non-null, it will be filled in with a stack of notes
620- // / indicating why evaluation failed (or why it failed to produce a constant
621- // / expression).
622- // / If the expression is unfoldable, the notes will indicate why it's not
623- // / foldable. If the expression is foldable, but not a constant expression,
624- // / the notes will describes why it isn't a constant expression. If the
625- // / expression *is* a constant expression, no notes will be produced.
626- // /
627- // / FIXME: this causes significant performance concerns and should be
628- // / refactored at some point. Not all evaluations of the constant
629- // / expression interpreter will display the given diagnostics, this means
630- // / those kinds of uses are paying the expense of generating a diagnostic
631- // / (which may include expensive operations like converting APValue objects
632- // / to a string representation).
633- SmallVectorImpl<PartialDiagnosticAt> *Diag = nullptr ;
634-
635- EvalStatus () = default ;
636-
637- // / Return true if the evaluated expression has
638- // / side effects.
639- bool hasSideEffects () const {
640- return HasSideEffects;
641- }
642- };
643-
644649 // / EvalResult is a struct with detailed info about an evaluated expression.
645650 struct EvalResult : EvalStatus {
646651 // / Val - This is the value the expression can be folded to.
@@ -735,8 +740,7 @@ class Expr : public ValueStmt {
735740 // / can be folded to a constant, and produces any relevant notes. In C++11,
736741 // / notes will be produced if the expression is not a constant expression.
737742 bool EvaluateAsInitializer (APValue &Result, const ASTContext &Ctx,
738- const VarDecl *VD,
739- SmallVectorImpl<PartialDiagnosticAt> &Notes,
743+ const VarDecl *VD, EvalStatus &Status,
740744 bool IsConstantInitializer) const ;
741745
742746 // / EvaluateWithSubstitution - Evaluate an expression as if from the context
0 commit comments