22 unsigned ExtraNotes) {
23 return diag(Loc, DiagId, ExtraNotes,
false);
27 unsigned ExtraNotes) {
30 return diag(E->
getExprLoc(), DiagId, ExtraNotes,
false);
31 setActiveDiagnostic(
false);
36 unsigned ExtraNotes) {
39 return diag(SI.
getLoc(), DiagId, ExtraNotes,
false);
40 setActiveDiagnostic(
false);
45 unsigned ExtraNotes) {
50 setActiveDiagnostic(
false);
53 return diag(Loc, DiagId, ExtraNotes,
true);
57 unsigned ExtraNotes) {
62 unsigned ExtraNotes) {
67 if (!hasActiveDiagnostic())
73 if (!hasActiveDiagnostic())
79 if (hasActiveDiagnostic())
84 return Ctx.getDiagnostics().Report(Loc, DiagId);
90 EvalStatus.Diag->push_back(std::make_pair(Loc, PD));
91 return EvalStatus.Diag->back().second;
95 unsigned ExtraNotes,
bool IsCCEDiag) {
96 if (EvalStatus.Diag) {
97 if (hasPriorDiagnostic()) {
101 unsigned CallStackNotes = getCallStackDepth() - 1;
102 unsigned Limit = Ctx.getDiagnostics().getConstexprBacktraceLimit();
104 CallStackNotes = std::min(CallStackNotes, Limit + 1);
105 if (checkingPotentialConstantExpression())
108 setActiveDiagnostic(
true);
109 setFoldFailureDiagnostic(!IsCCEDiag);
110 EvalStatus.Diag->clear();
111 EvalStatus.Diag->reserve(1 + ExtraNotes + CallStackNotes);
112 addDiag(Loc, DiagId);
113 if (!checkingPotentialConstantExpression()) {
116 return OptionalDiagnostic(&(*EvalStatus.Diag)[0].second);
118 setActiveDiagnostic(
false);
119 return OptionalDiagnostic();
122void State::addCallStack(
unsigned Limit) {
124 unsigned ActiveCalls = getCallStackDepth() - 1;
125 unsigned SkipStart = ActiveCalls, SkipEnd = SkipStart;
126 if (Limit && Limit < ActiveCalls) {
127 SkipStart = Limit / 2 + Limit % 2;
128 SkipEnd = ActiveCalls - Limit / 2;
132 unsigned CallIdx = 0;
133 const Frame *Top = getCurrentFrame();
134 for (
const Frame *F = Top; F->getCaller() !=
nullptr;
135 F = F->getCaller(), ++CallIdx) {
136 SourceRange CallRange = F->getCallRange();
140 if (CallIdx >= SkipStart && CallIdx < SkipEnd) {
141 if (CallIdx == SkipStart) {
143 addDiag(CallRange.
getBegin(), diag::note_constexpr_calls_suppressed)
144 << unsigned(ActiveCalls - Limit);
152 dyn_cast_if_present<CXXConstructorDecl>(F->getCallee());
153 CD && CD->isInheritingConstructor()) {
155 diag::note_constexpr_inherited_ctor_call_here)
160 SmallString<128> Buffer;
161 llvm::raw_svector_ostream
Out(Buffer);
164 addDiag(CallRange.
getBegin(), diag::note_constexpr_call_here)
165 <<
Out.str() << CallRange;
169bool State::hasPriorDiagnostic() {
170 if (!EvalStatus.Diag->empty()) {
172 case EvaluationMode::ConstantFold:
173 case EvaluationMode::IgnoreSideEffects:
174 if (!HasFoldFailureDiagnostic)
178 case EvaluationMode::ConstantExpression:
179 case EvaluationMode::ConstantExpressionUnevaluated:
180 setActiveDiagnostic(
false);
188 uint64_t Limit =
Ctx.getLangOpts().ConstexprStepLimit;
200 llvm_unreachable(
"Missed EvalMode case");
216 llvm_unreachable(
"Missed EvalMode case");
219bool State::keepEvaluatingAfterUndefinedBehavior()
const {
227 return checkingForUndefinedBehavior();
229 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
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.