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,
true);
43 unsigned ExtraNotes) {
46 return diag(E->
getExprLoc(), DiagId, ExtraNotes,
true);
47 setActiveDiagnostic(
false);
52 unsigned ExtraNotes) {
55 return diag(SI.
getLoc(), DiagId, ExtraNotes,
true);
56 setActiveDiagnostic(
false);
61 unsigned ExtraNotes) {
63 setActiveDiagnostic(
false);
70 setActiveDiagnostic(
false);
73 return diag(Loc, DiagId, ExtraNotes,
false);
77 unsigned ExtraNotes) {
82 unsigned ExtraNotes) {
87 if (!hasActiveDiagnostic())
93 if (!hasActiveDiagnostic())
99 return Ctx.getDiagnostics().Report(Loc, DiagId);
105 EvalStatus.Diag->push_back(std::make_pair(Loc, PD));
106 return EvalStatus.Diag->back().second;
110 if (!EvalStatus.ExtendedDiag)
113 EvalStatus.ExtendedDiag->push_back(std::make_pair(Loc, PD));
117 unsigned ExtraNotes,
bool IsFFDiag) {
118 if (EvalStatus.Diag) {
119 if (hasPriorDiagnostic()) {
123 unsigned CallStackNotes = getCallStackDepth() - 1;
124 unsigned Limit = Ctx.getDiagnostics().getConstexprBacktraceLimit();
126 CallStackNotes = std::min(CallStackNotes, Limit + 1);
127 if (checkingPotentialConstantExpression())
130 setActiveDiagnostic(
true);
131 setFoldFailureDiagnostic(IsFFDiag);
132 EvalStatus.Diag->clear();
133 EvalStatus.Diag->reserve(1 + ExtraNotes + CallStackNotes);
134 addDiag(Loc, DiagId);
135 if (!checkingPotentialConstantExpression()) {
138 return OptionalDiagnostic(&(*EvalStatus.Diag)[0].second);
140 setActiveDiagnostic(
false);
141 return OptionalDiagnostic();
144void State::addCallStack(
unsigned Limit) {
146 unsigned ActiveCalls = getCallStackDepth() - 1;
147 unsigned SkipStart = ActiveCalls, SkipEnd = SkipStart;
148 if (Limit && Limit < ActiveCalls) {
149 SkipStart = Limit / 2 + Limit % 2;
150 SkipEnd = ActiveCalls - Limit / 2;
154 unsigned CallIdx = 0;
155 const Frame *Top = getCurrentFrame();
156 for (
const Frame *F = Top; F->getCaller() !=
nullptr;
157 F = F->getCaller(), ++CallIdx) {
158 SourceRange CallRange = F->getCallRange();
162 if (CallIdx >= SkipStart && CallIdx < SkipEnd) {
163 if (CallIdx == SkipStart) {
165 addDiag(CallRange.
getBegin(), diag::note_constexpr_calls_suppressed)
166 << unsigned(ActiveCalls - Limit);
174 dyn_cast_if_present<CXXConstructorDecl>(F->getCallee());
175 CD && CD->isInheritingConstructor()) {
177 diag::note_constexpr_inherited_ctor_call_here)
182 SmallString<128> Buffer;
183 llvm::raw_svector_ostream
Out(Buffer);
186 addDiag(CallRange.
getBegin(), diag::note_constexpr_call_here)
187 <<
Out.str() << CallRange;
191bool State::hasPriorDiagnostic() {
192 if (!EvalStatus.Diag->empty()) {
194 case EvaluationMode::ConstantFold:
195 case EvaluationMode::IgnoreSideEffects:
196 if (!HasFoldFailureDiagnostic)
200 case EvaluationMode::ConstantExpression:
201 case EvaluationMode::ConstantExpressionUnevaluated:
202 setActiveDiagnostic(
false);
210 uint64_t Limit =
Ctx.getLangOpts().ConstexprStepLimit;
222 llvm_unreachable(
"Missed EvalMode case");
238 llvm_unreachable(
"Missed EvalMode case");
241bool State::keepEvaluatingAfterUndefinedBehavior()
const {
249 return checkingForUndefinedBehavior();
251 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
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.