[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
GitOrigin-RevId: 9b00a58cbd8485ebf57e66e1c35b8ce86285e8fa
diff --git a/lib/AST/ByteCode/Interp.h b/lib/AST/ByteCode/Interp.h
index 2e9df41..9a7bd03 100644
--- a/lib/AST/ByteCode/Interp.h
+++ b/lib/AST/ByteCode/Interp.h
@@ -1527,6 +1527,8 @@
template <PrimType Name, class T = typename PrimConv<Name>::T>
bool InitGlobalTemp(InterpState &S, CodePtr OpPC, uint32_t I,
const LifetimeExtendedTemporaryDecl *Temp) {
+ if (S.EvalMode == EvaluationMode::ConstantFold)
+ return false;
assert(Temp);
const Pointer &Ptr = S.P.getGlobal(I);
@@ -1544,6 +1546,8 @@
/// 3) Initialized global with index \I with that
inline bool InitGlobalTempComp(InterpState &S, CodePtr OpPC,
const LifetimeExtendedTemporaryDecl *Temp) {
+ if (S.EvalMode == EvaluationMode::ConstantFold)
+ return false;
assert(Temp);
const Pointer &Ptr = S.Stk.peek<Pointer>();
diff --git a/lib/AST/ByteCode/InterpState.cpp b/lib/AST/ByteCode/InterpState.cpp
index 1ec4191..a95916c 100644
--- a/lib/AST/ByteCode/InterpState.cpp
+++ b/lib/AST/ByteCode/InterpState.cpp
@@ -25,6 +25,7 @@
CheckingPotentialConstantExpression =
Parent.CheckingPotentialConstantExpression;
CheckingForUndefinedBehavior = Parent.CheckingForUndefinedBehavior;
+ EvalMode = Parent.EvalMode;
}
InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
@@ -36,6 +37,7 @@
CheckingPotentialConstantExpression =
Parent.CheckingPotentialConstantExpression;
CheckingForUndefinedBehavior = Parent.CheckingForUndefinedBehavior;
+ EvalMode = Parent.EvalMode;
}
bool InterpState::inConstantContext() const {
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index e1bacd0..5145896 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -17611,6 +17611,18 @@
Info.InConstantContext = InConstantContext;
LValue LV;
CheckedTemporaries CheckedTemps;
+
+ if (Info.EnableNewConstInterp) {
+ if (!Info.Ctx.getInterpContext().evaluate(Info, this, Result.Val,
+ ConstantExprKind::Normal))
+ return false;
+
+ LV.setFrom(Ctx, Result.Val);
+ return CheckLValueConstantExpression(
+ Info, getExprLoc(), Ctx.getLValueReferenceType(getType()), LV,
+ ConstantExprKind::Normal, CheckedTemps);
+ }
+
if (!EvaluateLValue(this, LV, Info) || !Info.discardCleanups() ||
Result.HasSideEffects ||
!CheckLValueConstantExpression(Info, getExprLoc(),