Skip to content

Commit 9b00a58

Browse files
authored
[clang][bytecode] Use bytecode interpreter in EvaluateAsLValue (#158038)
Set the EvalMode on InterpState and abort when initalizing a global temporary, like the current interpreter does. The rest is just plumbing in EvaluateAsLValue. Fixes #157497
1 parent e285602 commit 9b00a58

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

clang/lib/AST/ByteCode/Interp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,8 @@ bool InitGlobal(InterpState &S, CodePtr OpPC, uint32_t I) {
15271527
template <PrimType Name, class T = typename PrimConv<Name>::T>
15281528
bool InitGlobalTemp(InterpState &S, CodePtr OpPC, uint32_t I,
15291529
const LifetimeExtendedTemporaryDecl *Temp) {
1530+
if (S.EvalMode == EvaluationMode::ConstantFold)
1531+
return false;
15301532
assert(Temp);
15311533

15321534
const Pointer &Ptr = S.P.getGlobal(I);
@@ -1544,6 +1546,8 @@ bool InitGlobalTemp(InterpState &S, CodePtr OpPC, uint32_t I,
15441546
/// 3) Initialized global with index \I with that
15451547
inline bool InitGlobalTempComp(InterpState &S, CodePtr OpPC,
15461548
const LifetimeExtendedTemporaryDecl *Temp) {
1549+
if (S.EvalMode == EvaluationMode::ConstantFold)
1550+
return false;
15471551
assert(Temp);
15481552

15491553
const Pointer &Ptr = S.Stk.peek<Pointer>();

clang/lib/AST/ByteCode/InterpState.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
2525
CheckingPotentialConstantExpression =
2626
Parent.CheckingPotentialConstantExpression;
2727
CheckingForUndefinedBehavior = Parent.CheckingForUndefinedBehavior;
28+
EvalMode = Parent.EvalMode;
2829
}
2930

3031
InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
@@ -36,6 +37,7 @@ InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
3637
CheckingPotentialConstantExpression =
3738
Parent.CheckingPotentialConstantExpression;
3839
CheckingForUndefinedBehavior = Parent.CheckingForUndefinedBehavior;
40+
EvalMode = Parent.EvalMode;
3941
}
4042

4143
bool InterpState::inConstantContext() const {

clang/lib/AST/ExprConstant.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17611,6 +17611,18 @@ bool Expr::EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx,
1761117611
Info.InConstantContext = InConstantContext;
1761217612
LValue LV;
1761317613
CheckedTemporaries CheckedTemps;
17614+
17615+
if (Info.EnableNewConstInterp) {
17616+
if (!Info.Ctx.getInterpContext().evaluate(Info, this, Result.Val,
17617+
ConstantExprKind::Normal))
17618+
return false;
17619+
17620+
LV.setFrom(Ctx, Result.Val);
17621+
return CheckLValueConstantExpression(
17622+
Info, getExprLoc(), Ctx.getLValueReferenceType(getType()), LV,
17623+
ConstantExprKind::Normal, CheckedTemps);
17624+
}
17625+
1761417626
if (!EvaluateLValue(this, LV, Info) || !Info.discardCleanups() ||
1761517627
Result.HasSideEffects ||
1761617628
!CheckLValueConstantExpression(Info, getExprLoc(),

0 commit comments

Comments
 (0)