22 unsigned ExtraNotes) {
23 return diag(Loc, DiagId, ExtraNotes,
false);
27 unsigned ExtraNotes) {
29 return diag(E->
getExprLoc(), DiagId, ExtraNotes,
false);
30 setActiveDiagnostic(
false);
35 unsigned ExtraNotes) {
37 return diag(SI.
getLoc(), DiagId, ExtraNotes,
false);
38 setActiveDiagnostic(
false);
43 unsigned ExtraNotes) {
47 setActiveDiagnostic(
false);
50 return diag(Loc, DiagId, ExtraNotes,
true);
54 unsigned ExtraNotes) {
59 unsigned ExtraNotes) {
64 if (!hasActiveDiagnostic())
70 if (hasActiveDiagnostic())
75 return Ctx.getDiagnostics().Report(Loc, DiagId);
81 EvalStatus.Diag->push_back(std::make_pair(Loc, PD));
82 return EvalStatus.Diag->back().second;
86 unsigned ExtraNotes,
bool IsCCEDiag) {
87 if (EvalStatus.Diag) {
88 if (hasPriorDiagnostic()) {
92 unsigned CallStackNotes = getCallStackDepth() - 1;
93 unsigned Limit = Ctx.getDiagnostics().getConstexprBacktraceLimit();
95 CallStackNotes = std::min(CallStackNotes, Limit + 1);
96 if (checkingPotentialConstantExpression())
99 setActiveDiagnostic(
true);
100 setFoldFailureDiagnostic(!IsCCEDiag);
101 EvalStatus.Diag->clear();
102 EvalStatus.Diag->reserve(1 + ExtraNotes + CallStackNotes);
103 addDiag(Loc, DiagId);
104 if (!checkingPotentialConstantExpression()) {
107 return OptionalDiagnostic(&(*EvalStatus.Diag)[0].second);
109 setActiveDiagnostic(
false);
110 return OptionalDiagnostic();
113void State::addCallStack(
unsigned Limit) {
115 unsigned ActiveCalls = getCallStackDepth() - 1;
116 unsigned SkipStart = ActiveCalls, SkipEnd = SkipStart;
117 if (Limit && Limit < ActiveCalls) {
118 SkipStart = Limit / 2 + Limit % 2;
119 SkipEnd = ActiveCalls - Limit / 2;
123 unsigned CallIdx = 0;
124 const Frame *Top = getCurrentFrame();
125 const Frame *Bottom = getBottomFrame();
126 for (
const Frame *F = Top; F != Bottom; F = F->
getCaller(), ++CallIdx) {
127 SourceRange CallRange = F->getCallRange();
131 if (CallIdx >= SkipStart && CallIdx < SkipEnd) {
132 if (CallIdx == SkipStart) {
134 addDiag(CallRange.
getBegin(), diag::note_constexpr_calls_suppressed)
135 << unsigned(ActiveCalls - Limit);
143 dyn_cast_if_present<CXXConstructorDecl>(F->getCallee());
144 CD && CD->isInheritingConstructor()) {
146 diag::note_constexpr_inherited_ctor_call_here)
151 SmallString<128> Buffer;
152 llvm::raw_svector_ostream
Out(Buffer);
155 addDiag(CallRange.
getBegin(), diag::note_constexpr_call_here)
156 <<
Out.str() << CallRange;
160bool State::hasPriorDiagnostic() {
161 if (!EvalStatus.Diag->empty()) {
163 case EvaluationMode::ConstantFold:
164 case EvaluationMode::IgnoreSideEffects:
165 if (!HasFoldFailureDiagnostic)
169 case EvaluationMode::ConstantExpression:
170 case EvaluationMode::ConstantExpressionUnevaluated:
171 setActiveDiagnostic(
false);
179 uint64_t Limit =
Ctx.getLangOpts().ConstexprStepLimit;
191 llvm_unreachable(
"Missed EvalMode case");
207 llvm_unreachable(
"Missed EvalMode case");
210bool State::keepEvaluatingAfterUndefinedBehavior()
const {
218 return checkingForUndefinedBehavior();
220 llvm_unreachable(
"Missed EvalMode case");
Defines the clang::ASTContext interface.
Implements a partial diagnostic which may not be emitted.
A little helper class used to produce diagnostics.
This represents one expression.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
A partial diagnostic which we might know in advance that we are not going to emit.
Encodes a location in the source.
SourceLocation getBegin() const
virtual Frame * getCaller() const =0
Returns a pointer to the caller frame.
Describes the statement/declaration an opcode was generated from.
SourceLocation getLoc() const
bool checkingForUndefinedBehavior() const
Are we checking an expression for overflow?
virtual bool stepsLeft() const =0
OptionalDiagnostic Note(SourceLocation Loc, diag::kind DiagId)
Add a note to a prior diagnostic.
DiagnosticBuilder report(SourceLocation Loc, diag::kind DiagId)
Directly reports a diagnostic message.
OptionalDiagnostic FFDiag(SourceLocation Loc, diag::kind DiagId=diag::note_invalid_subexpr_in_const_expr, unsigned ExtraNotes=0)
Diagnose that the evaluation could not be folded (FF => FoldFailure)
Expr::EvalStatus & EvalStatus
void addNotes(ArrayRef< PartialDiagnosticAt > Diags)
Add a stack of notes to a prior diagnostic.
OptionalDiagnostic CCEDiag(SourceLocation Loc, diag::kind DiagId=diag::note_invalid_subexpr_in_const_expr, unsigned ExtraNotes=0)
Diagnose that the evaluation does not produce a C++11 core constant expression.
bool checkingPotentialConstantExpression() const
Are we checking whether the expression is a potential constant expression?
bool keepEvaluatingAfterSideEffect() const
Should we continue evaluation after encountering a side-effect that we couldn't model?
bool keepEvaluatingAfterFailure() const
Should we continue evaluation as much as possible after encountering a construct which can't be reduc...
unsigned kind
All of the diagnostics that can be emitted by the frontend.
The JSON file list parser is used to communicate input to InstallAPI.
@ ConstantFold
Fold the expression to a constant.
@ ConstantExpressionUnevaluated
Evaluate as a constant expression.
@ ConstantExpression
Evaluate as a constant expression.
@ IgnoreSideEffects
Evaluate in any way we know how.