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())
78 return Ctx.getDiagnostics().Report(Loc, DiagId);
84 EvalStatus.Diag->push_back(std::make_pair(Loc, PD));
85 return EvalStatus.Diag->back().second;
89 unsigned ExtraNotes,
bool IsCCEDiag) {
90 if (EvalStatus.Diag) {
91 if (hasPriorDiagnostic()) {
95 unsigned CallStackNotes = getCallStackDepth() - 1;
96 unsigned Limit = Ctx.getDiagnostics().getConstexprBacktraceLimit();
98 CallStackNotes = std::min(CallStackNotes, Limit + 1);
99 if (checkingPotentialConstantExpression())
102 setActiveDiagnostic(
true);
103 setFoldFailureDiagnostic(!IsCCEDiag);
104 EvalStatus.Diag->clear();
105 EvalStatus.Diag->reserve(1 + ExtraNotes + CallStackNotes);
106 addDiag(Loc, DiagId);
107 if (!checkingPotentialConstantExpression()) {
110 return OptionalDiagnostic(&(*EvalStatus.Diag)[0].second);
112 setActiveDiagnostic(
false);
113 return OptionalDiagnostic();
116void State::addCallStack(
unsigned Limit) {
118 unsigned ActiveCalls = getCallStackDepth() - 1;
119 unsigned SkipStart = ActiveCalls, SkipEnd = SkipStart;
120 if (Limit && Limit < ActiveCalls) {
121 SkipStart = Limit / 2 + Limit % 2;
122 SkipEnd = ActiveCalls - Limit / 2;
126 unsigned CallIdx = 0;
127 const Frame *Top = getCurrentFrame();
128 for (
const Frame *F = Top; F->getCaller() !=
nullptr;
129 F = F->getCaller(), ++CallIdx) {
130 SourceRange CallRange = F->getCallRange();
134 if (CallIdx >= SkipStart && CallIdx < SkipEnd) {
135 if (CallIdx == SkipStart) {
137 addDiag(CallRange.
getBegin(), diag::note_constexpr_calls_suppressed)
138 << unsigned(ActiveCalls - Limit);
146 dyn_cast_if_present<CXXConstructorDecl>(F->getCallee());
147 CD && CD->isInheritingConstructor()) {
149 diag::note_constexpr_inherited_ctor_call_here)
154 SmallString<128> Buffer;
155 llvm::raw_svector_ostream
Out(Buffer);
158 addDiag(CallRange.
getBegin(), diag::note_constexpr_call_here)
159 <<
Out.str() << CallRange;
163bool State::hasPriorDiagnostic() {
164 if (!EvalStatus.Diag->empty()) {
166 case EvaluationMode::ConstantFold:
167 case EvaluationMode::IgnoreSideEffects:
168 if (!HasFoldFailureDiagnostic)
172 case EvaluationMode::ConstantExpression:
173 case EvaluationMode::ConstantExpressionUnevaluated:
174 setActiveDiagnostic(
false);
182 uint64_t Limit =
Ctx.getLangOpts().ConstexprStepLimit;
194 llvm_unreachable(
"Missed EvalMode case");
210 llvm_unreachable(
"Missed EvalMode case");
213bool State::keepEvaluatingAfterUndefinedBehavior()
const {
221 return checkingForUndefinedBehavior();
223 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.