diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp index 9d093ba1ad65b0..eeb7fa9379f5cc 100644 --- a/clang/lib/AST/Interp/Context.cpp +++ b/clang/lib/AST/Interp/Context.cpp @@ -55,6 +55,11 @@ bool Context::evaluateAsRValue(State &Parent, const Expr *E, APValue &Result) { ByteCodeExprGen C(*this, *P, Parent, Stk, Result); if (Check(Parent, C.interpretExpr(E))) { assert(Stk.empty()); +#ifndef NDEBUG + // Make sure we don't rely on some value being still alive in + // InterpStack memory. + Stk.clear(); +#endif return true; } @@ -68,6 +73,11 @@ bool Context::evaluateAsInitializer(State &Parent, const VarDecl *VD, ByteCodeExprGen C(*this, *P, Parent, Stk, Result); if (Check(Parent, C.interpretDecl(VD))) { assert(Stk.empty()); +#ifndef NDEBUG + // Make sure we don't rely on some value being still alive in + // InterpStack memory. + Stk.clear(); +#endif return true; }