Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,8 @@ bool InitGlobal(InterpState &S, CodePtr OpPC, uint32_t I) {
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);
Expand All @@ -1544,6 +1546,8 @@ bool InitGlobalTemp(InterpState &S, CodePtr OpPC, uint32_t I,
/// 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>();
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/AST/ByteCode/InterpState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
CheckingPotentialConstantExpression =
Parent.CheckingPotentialConstantExpression;
CheckingForUndefinedBehavior = Parent.CheckingForUndefinedBehavior;
EvalMode = Parent.EvalMode;
}

InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
Expand All @@ -36,6 +37,7 @@ InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
CheckingPotentialConstantExpression =
Parent.CheckingPotentialConstantExpression;
CheckingForUndefinedBehavior = Parent.CheckingForUndefinedBehavior;
EvalMode = Parent.EvalMode;
}

bool InterpState::inConstantContext() const {
Expand Down
12 changes: 12 additions & 0 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17611,6 +17611,18 @@ bool Expr::EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx,
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(),
Expand Down