================
@@ -22134,44 +22176,61 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result,
const ASTContext &Ctx,
// If this is a class template argument, it's required to have constant
// destruction too.
if (Kind == ConstantExprKind::ClassTemplateArgument &&
- (!EvaluateDestruction(Ctx, Base, Result.Val, T, getBeginLoc(), Result,
- true) ||
+ (!EvaluateDestruction(Ctx, Info.getSemaProxy(), Base, Result.Val, T,
+ E->getBeginLoc(), Result, true) ||
Result.HasSideEffects)) {
// FIXME: Prefix a note to indicate that the problem is lack of constant
// destruction.
return false;
}
+
return true;
}
-bool Expr::EvaluateAsInitializer(const ASTContext &Ctx, const VarDecl *VD,
- Expr::EvalResult &EStatus,
- bool IsConstantInitialization) const {
+bool Expr::EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx,
+ ConstantExprKind Kind) const {
assert(!isValueDependent() &&
"Expression evaluator can't be called on a dependent expression.");
- assert(VD && "Need a valid VarDecl");
+ bool IsConst;
+ if (FastEvaluateAsRValue(this, Result.Val, Ctx, IsConst) &&
+ Result.Val.hasValue())
+ return true;
- llvm::TimeTraceScope TimeScope("EvaluateAsInitializer", [&] {
- std::string Name;
- llvm::raw_string_ostream OS(Name);
- VD->printQualifiedName(OS);
- return Name;
- });
+ ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateAsConstantExpr");
+ EvaluationMode EM = EvaluationMode::ConstantExpression;
+ EvalInfo Info(Ctx, /*Sema=*/nullptr, Result, EM);
- EvalInfo Info(Ctx, EStatus,
- (IsConstantInitialization &&
- (Ctx.getLangOpts().CPlusPlus || Ctx.getLangOpts().C23))
- ? EvaluationMode::ConstantExpression
- : EvaluationMode::ConstantFold);
- Info.setEvaluatingDecl(VD, EStatus.Val);
- Info.InConstantContext = IsConstantInitialization;
+ return ::EvaluateConstantExpr(Result, Ctx, Info, this, Kind);
+}
+
+bool Expr::EvaluateAsMandatedConstantExpr(EvalResult &Result,
----------------
katzdm wrote:
I don't think that this is meaningfully more code duplication than occurs
between other entry-points into the constant evaluator (e.g.,
`EvaluateAsInitializer`, `EvaluateAsRValue`, `EvaluateAsConstantExpr`, etc):
They all assert against value-dependence; they all instantiate a `TimeScope`;
they all construct the `EvalInfo`. I think the level of code duplication is
relatively low, and fits within that established pattern. Let me know if you
buy that.
https://github.com/llvm/llvm-project/pull/205557
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits