summaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/InterpState.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/AST/ByteCode/InterpState.cpp')
-rw-r--r--clang/lib/AST/ByteCode/InterpState.cpp38
1 files changed, 21 insertions, 17 deletions
diff --git a/clang/lib/AST/ByteCode/InterpState.cpp b/clang/lib/AST/ByteCode/InterpState.cpp
index f89967759ff9..1ec4191d2ba3 100644
--- a/clang/lib/AST/ByteCode/InterpState.cpp
+++ b/clang/lib/AST/ByteCode/InterpState.cpp
@@ -20,19 +20,29 @@ using namespace clang::interp;
InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
Context &Ctx, SourceMapper *M)
: Parent(Parent), M(M), P(P), Stk(Stk), Ctx(Ctx), BottomFrame(*this),
- Current(&BottomFrame) {}
+ Current(&BottomFrame) {
+ InConstantContext = Parent.InConstantContext;
+ CheckingPotentialConstantExpression =
+ Parent.CheckingPotentialConstantExpression;
+ CheckingForUndefinedBehavior = Parent.CheckingForUndefinedBehavior;
+}
InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
Context &Ctx, const Function *Func)
: Parent(Parent), M(nullptr), P(P), Stk(Stk), Ctx(Ctx),
BottomFrame(*this, Func, nullptr, CodePtr(), Func->getArgSize()),
- Current(&BottomFrame) {}
+ Current(&BottomFrame) {
+ InConstantContext = Parent.InConstantContext;
+ CheckingPotentialConstantExpression =
+ Parent.CheckingPotentialConstantExpression;
+ CheckingForUndefinedBehavior = Parent.CheckingForUndefinedBehavior;
+}
bool InterpState::inConstantContext() const {
if (ConstantContextOverride)
return *ConstantContextOverride;
- return Parent.InConstantContext;
+ return InConstantContext;
}
InterpState::~InterpState() {
@@ -59,20 +69,11 @@ InterpState::~InterpState() {
void InterpState::cleanup() {
// As a last resort, make sure all pointers still pointing to a dead block
// don't point to it anymore.
- Alloc.cleanup();
-}
-
-Frame *InterpState::getCurrentFrame() {
- if (Current && Current->Caller)
- return Current;
- return Parent.getCurrentFrame();
+ if (Alloc)
+ Alloc->cleanup();
}
-bool InterpState::reportOverflow(const Expr *E, const llvm::APSInt &Value) {
- QualType Type = E->getType();
- CCEDiag(E, diag::note_constexpr_overflow) << Value << Type;
- return noteUndefinedBehavior();
-}
+Frame *InterpState::getCurrentFrame() { return Current; }
void InterpState::deallocate(Block *B) {
assert(B);
@@ -103,10 +104,13 @@ void InterpState::deallocate(Block *B) {
}
bool InterpState::maybeDiagnoseDanglingAllocations() {
- bool NoAllocationsLeft = !Alloc.hasAllocations();
+ if (!Alloc)
+ return true;
+
+ bool NoAllocationsLeft = !Alloc->hasAllocations();
if (!checkingPotentialConstantExpression()) {
- for (const auto &[Source, Site] : Alloc.allocation_sites()) {
+ for (const auto &[Source, Site] : Alloc->allocation_sites()) {
assert(!Site.empty());
CCEDiag(Source->getExprLoc(), diag::note_constexpr_memory_leak)