Skip to content

Commit f58844b

Browse files
authored
[clang] Move two flags from EvalInfo to State (#157046)
Instead of relaying from InterpState to the parent state (which is an EvalInfo), just save the variables in State instead, so both subclasses have access to it.
1 parent b869dfc commit f58844b

File tree

4 files changed

+33
-36
lines changed

4 files changed

+33
-36
lines changed

clang/lib/AST/ByteCode/InterpState.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@ using namespace clang::interp;
2020
InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
2121
Context &Ctx, SourceMapper *M)
2222
: Parent(Parent), M(M), P(P), Stk(Stk), Ctx(Ctx), BottomFrame(*this),
23-
Current(&BottomFrame) {}
23+
Current(&BottomFrame) {
24+
CheckingPotentialConstantExpression =
25+
Parent.CheckingPotentialConstantExpression;
26+
CheckingForUndefinedBehavior = Parent.CheckingForUndefinedBehavior;
27+
}
2428

2529
InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
2630
Context &Ctx, const Function *Func)
2731
: Parent(Parent), M(nullptr), P(P), Stk(Stk), Ctx(Ctx),
2832
BottomFrame(*this, Func, nullptr, CodePtr(), Func->getArgSize()),
29-
Current(&BottomFrame) {}
33+
Current(&BottomFrame) {
34+
CheckingPotentialConstantExpression =
35+
Parent.CheckingPotentialConstantExpression;
36+
CheckingForUndefinedBehavior = Parent.CheckingForUndefinedBehavior;
37+
}
3038

3139
bool InterpState::inConstantContext() const {
3240
if (ConstantContextOverride)

clang/lib/AST/ByteCode/InterpState.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,12 @@ class InterpState final : public State, public SourceMapper {
7070
ASTContext &getASTContext() const override { return Parent.getASTContext(); }
7171

7272
// Forward status checks and updates to the walker.
73-
bool checkingForUndefinedBehavior() const override {
74-
return Parent.checkingForUndefinedBehavior();
75-
}
7673
bool keepEvaluatingAfterFailure() const override {
7774
return Parent.keepEvaluatingAfterFailure();
7875
}
7976
bool keepEvaluatingAfterSideEffect() const override {
8077
return Parent.keepEvaluatingAfterSideEffect();
8178
}
82-
bool checkingPotentialConstantExpression() const override {
83-
return Parent.checkingPotentialConstantExpression();
84-
}
8579
bool noteUndefinedBehavior() override {
8680
return Parent.noteUndefinedBehavior();
8781
}

clang/lib/AST/ByteCode/State.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ class State {
5959
public:
6060
virtual ~State();
6161

62-
virtual bool checkingForUndefinedBehavior() const = 0;
63-
virtual bool checkingPotentialConstantExpression() const = 0;
6462
virtual bool noteUndefinedBehavior() = 0;
6563
virtual bool keepEvaluatingAfterFailure() const = 0;
6664
virtual bool keepEvaluatingAfterSideEffect() const = 0;
@@ -75,6 +73,16 @@ class State {
7573
virtual unsigned getCallStackDepth() = 0;
7674
virtual bool noteSideEffect() = 0;
7775

76+
/// Are we checking whether the expression is a potential constant
77+
/// expression?
78+
bool checkingPotentialConstantExpression() const {
79+
return CheckingPotentialConstantExpression;
80+
}
81+
/// Are we checking an expression for overflow?
82+
bool checkingForUndefinedBehavior() const {
83+
return CheckingForUndefinedBehavior;
84+
}
85+
7886
public:
7987
State() = default;
8088
/// Diagnose that the evaluation could not be folded (FF => FoldFailure)
@@ -128,6 +136,19 @@ class State {
128136
/// constant value.
129137
bool InConstantContext = false;
130138

139+
/// Whether we're checking that an expression is a potential constant
140+
/// expression. If so, do not fail on constructs that could become constant
141+
/// later on (such as a use of an undefined global).
142+
bool CheckingPotentialConstantExpression = false;
143+
144+
/// Whether we're checking for an expression that has undefined behavior.
145+
/// If so, we will produce warnings if we encounter an operation that is
146+
/// always undefined.
147+
///
148+
/// Note that we still need to evaluate the expression normally when this
149+
/// is set; this is used when evaluating ICEs in C.
150+
bool CheckingForUndefinedBehavior = false;
151+
131152
private:
132153
void addCallStack(unsigned Limit);
133154

clang/lib/AST/ExprConstant.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -926,19 +926,6 @@ namespace {
926926
/// fold (not just why it's not strictly a constant expression)?
927927
bool HasFoldFailureDiagnostic;
928928

929-
/// Whether we're checking that an expression is a potential constant
930-
/// expression. If so, do not fail on constructs that could become constant
931-
/// later on (such as a use of an undefined global).
932-
bool CheckingPotentialConstantExpression = false;
933-
934-
/// Whether we're checking for an expression that has undefined behavior.
935-
/// If so, we will produce warnings if we encounter an operation that is
936-
/// always undefined.
937-
///
938-
/// Note that we still need to evaluate the expression normally when this
939-
/// is set; this is used when evaluating ICEs in C.
940-
bool CheckingForUndefinedBehavior = false;
941-
942929
enum EvaluationMode {
943930
/// Evaluate as a constant expression. Stop if we find that the expression
944931
/// is not a constant expression.
@@ -960,19 +947,6 @@ namespace {
960947
EM_IgnoreSideEffects,
961948
} EvalMode;
962949

963-
/// Are we checking whether the expression is a potential constant
964-
/// expression?
965-
bool checkingPotentialConstantExpression() const override {
966-
return CheckingPotentialConstantExpression;
967-
}
968-
969-
/// Are we checking an expression for overflow?
970-
// FIXME: We should check for any kind of undefined or suspicious behavior
971-
// in such constructs, not just overflow.
972-
bool checkingForUndefinedBehavior() const override {
973-
return CheckingForUndefinedBehavior;
974-
}
975-
976950
EvalInfo(const ASTContext &C, Expr::EvalStatus &S, EvaluationMode Mode)
977951
: Ctx(const_cast<ASTContext &>(C)), EvalStatus(S), CurrentCall(nullptr),
978952
CallStackDepth(0), NextCallIndex(1),

0 commit comments

Comments
 (0)