[clang] b9e1679 - [clang][Interp][NFC] Clear stack memory even on success

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 9 07:16:54 PDT 2023


Author: Timm Bäder
Date: 2023-07-09T16:13:19+02:00
New Revision: b9e167994f01172c20716de28ea24f202b45b6a7

URL: https://github.com/llvm/llvm-project/commit/b9e167994f01172c20716de28ea24f202b45b6a7
DIFF: https://github.com/llvm/llvm-project/commit/b9e167994f01172c20716de28ea24f202b45b6a7.diff

LOG: [clang][Interp][NFC] Clear stack memory even on success

This makes it easier to use asan to find memory problems. clear() will
actually free the memory.

Added: 
    

Modified: 
    clang/lib/AST/Interp/Context.cpp

Removed: 
    


################################################################################
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<EvalEmitter> 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<EvalEmitter> 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;
   }
 


        


More information about the cfe-commits mailing list