Skip to content

Commit 95db809

Browse files
committed
[clang] Use new interpreter in EvaluateAsConstantExpr if requested
EvaluateAsConstantExpr() uses ::EvaluateInPlace() directly, which does not use the new interpreter if requested. Do it here, which is the same pattern we use in EvaluateAsInitializer.
1 parent 410f130 commit 95db809

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15672,12 +15672,14 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx,
1567215672
// this doesn't escape.
1567315673
MaterializeTemporaryExpr BaseMTE(T, const_cast<Expr*>(this), true);
1567415674
APValue::LValueBase Base(&BaseMTE);
15675-
1567615675
Info.setEvaluatingDecl(Base, Result.Val);
15677-
LValue LVal;
15678-
LVal.set(Base);
1567915676

15680-
{
15677+
if (Info.EnableNewConstInterp) {
15678+
if (!Info.Ctx.getInterpContext().evaluateAsRValue(Info, this, Result.Val))
15679+
return false;
15680+
} else {
15681+
LValue LVal;
15682+
LVal.set(Base);
1568115683
// C++23 [intro.execution]/p5
1568215684
// A full-expression is [...] a constant-expression
1568315685
// So we need to make sure temporary objects are destroyed after having
@@ -15686,10 +15688,10 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx,
1568615688
if (!::EvaluateInPlace(Result.Val, Info, LVal, this) ||
1568715689
Result.HasSideEffects || !Scope.destroy())
1568815690
return false;
15689-
}
1569015691

15691-
if (!Info.discardCleanups())
15692-
llvm_unreachable("Unhandled cleanup; missing full expression marker?");
15692+
if (!Info.discardCleanups())
15693+
llvm_unreachable("Unhandled cleanup; missing full expression marker?");
15694+
}
1569315695

1569415696
if (!CheckConstantExpression(Info, getExprLoc(), getStorageType(Ctx, this),
1569515697
Result.Val, Kind))

clang/test/AST/Interp/literals.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,13 @@ namespace SizeOf {
261261
#if __cplusplus >= 202002L
262262
/// FIXME: The following code should be accepted.
263263
consteval int foo(int n) { // ref-error {{consteval function never produces a constant expression}}
264-
return sizeof(int[n]); // ref-note 3{{not valid in a constant expression}} \
265-
// expected-note {{not valid in a constant expression}}
264+
return sizeof(int[n]); // ref-note 3{{not valid in a constant expression}}
266265
}
267266
constinit int var = foo(5); // ref-error {{not a constant expression}} \
268267
// ref-note 2{{in call to}} \
269268
// ref-error {{does not have a constant initializer}} \
270269
// ref-note {{required by 'constinit' specifier}} \
271270
// expected-error {{is not a constant expression}} \
272-
// expected-note {{in call to}} \
273271
// expected-error {{does not have a constant initializer}} \
274272
// expected-note {{required by 'constinit' specifier}} \
275273

0 commit comments

Comments
 (0)