21 if (!
Ctx.getLangOpts().MSVCCompat ||
26 case diag::note_constexpr_invalid_cast_ptrtoint:
27 addExtendedDiag(Loc, diag::warn_relaxed_constant_fold_cast);
29 case diag::note_constexpr_null_subobject:
30 addExtendedDiag(Loc, diag::warn_relaxed_constant_fold_null);
38 unsigned ExtraNotes) {
39 return diag(Loc, DiagId, ExtraNotes,
false);
43 unsigned ExtraNotes) {
46 return diag(E->
getExprLoc(), DiagId, ExtraNotes,
false);
47 setActiveDiagnostic(
false);
52 unsigned ExtraNotes) {
55 return diag(SI.
getLoc(), DiagId, ExtraNotes,
false);
56 setActiveDiagnostic(
false);
61 unsigned ExtraNotes) {
63 setActiveDiagnostic(
false);
70 setActiveDiagnostic(
false);
73 return diag(Loc, DiagId, ExtraNotes,
true);
77 unsigned ExtraNotes) {
82 unsigned ExtraNotes) {
87 if (!hasActiveDiagnostic())
93 if (!hasActiveDiagnostic())
99 if (hasActiveDiagnostic())
104 return Ctx.getDiagnostics().Report(Loc, DiagId);
110 EvalStatus.Diag->push_back(std::make_pair(Loc, PD));
111 return EvalStatus.Diag->back().second;
115 if (!EvalStatus.ExtendedDiag)
118 EvalStatus.ExtendedDiag->push_back(std::make_pair(Loc, PD));
122 unsigned ExtraNotes,
bool IsCCEDiag) {
123 if (EvalStatus.Diag) {
124 if (hasPriorDiagnostic()) {
128 unsigned CallStackNotes = getCallStackDepth() - 1;
129 unsigned Limit = Ctx.getDiagnostics().getConstexprBacktraceLimit();
131 CallStackNotes = std::min(CallStackNotes, Limit + 1);
132 if (checkingPotentialConstantExpression())
135 setActiveDiagnostic(
true);
136 setFoldFailureDiagnostic(!IsCCEDiag);
137 EvalStatus.Diag->clear();
138 EvalStatus.Diag->reserve(1 + ExtraNotes + CallStackNotes);
139 addDiag(Loc, DiagId);
140 if (!checkingPotentialConstantExpression()) {
143 return OptionalDiagnostic(&(*EvalStatus.Diag)[0].second);
145 setActiveDiagnostic(
false);
146 return OptionalDiagnostic();
149void State::addCallStack(
unsigned Limit) {
151 unsigned ActiveCalls = getCallStackDepth() - 1;
152 unsigned SkipStart = ActiveCalls, SkipEnd = SkipStart;
153 if (Limit && Limit < ActiveCalls) {
154 SkipStart = Limit / 2 + Limit % 2;
155 SkipEnd = ActiveCalls - Limit / 2;
159 unsigned CallIdx = 0;
160 const Frame *Top = getCurrentFrame();
161 for (
const Frame *F = Top; F->getCaller() !=
nullptr;
162 F = F->getCaller(), ++CallIdx) {
163 SourceRange CallRange = F->getCallRange();
167 if (CallIdx >= SkipStart && CallIdx < SkipEnd) {
168 if (CallIdx == SkipStart) {
170 addDiag(CallRange.
getBegin(), diag::note_constexpr_calls_suppressed)
171 << unsigned(ActiveCalls - Limit);
179 dyn_cast_if_present<CXXConstructorDecl>(F->getCallee());
180 CD && CD->isInheritingConstructor()) {
182 diag::note_constexpr_inherited_ctor_call_here)
187 SmallString<128> Buffer;
188 llvm::raw_svector_ostream
Out(Buffer);
191 addDiag(CallRange.
getBegin(), diag::note_constexpr_call_here)
192 <<
Out.str() << CallRange;
196bool State::hasPriorDiagnostic() {
197 if (!EvalStatus.Diag->empty()) {
199 case EvaluationMode::ConstantFold:
200 case EvaluationMode::IgnoreSideEffects:
201 if (!HasFoldFailureDiagnostic)
205 case EvaluationMode::ConstantExpression:
206 case EvaluationMode::ConstantExpressionUnevaluated:
207 setActiveDiagnostic(
false);
215 uint64_t Limit =
Ctx.getLangOpts().ConstexprStepLimit;
227 llvm_unreachable(
"Missed EvalMode case");
243 llvm_unreachable(
"Missed EvalMode case");
246bool State::keepEvaluatingAfterUndefinedBehavior()
const {
254 return checkingForUndefinedBehavior();
256 llvm_unreachable(
"Missed EvalMode case");
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.
bool emitRelaxedDiag(SourceLocation Loc, diag::kind DiagId)
If DiagId should be relaxed as per the current evaluation settings, emit it as a warning instead of a...
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...
bool InConstantContext
Whether or not we're in a context where the front end requires a constant value.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Top level wrappers for InstallAPI frontend operations.
@ 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.