[clang] fbf8b82 - [clang][Interp][NFC] Be more cautious about Block initialization state

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 17 23:01:37 PDT 2024


Author: Timm Bäder
Date: 2024-07-18T08:01:24+02:00
New Revision: fbf8b82cd02818c0888805bb39abbf550333bea6

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

LOG: [clang][Interp][NFC] Be more cautious about Block initialization state

... when moving a Block to a DeadBlock. Only invoke the MoveFn if the
old block was initialized at all.

Added: 
    

Modified: 
    clang/lib/AST/Interp/InterpBlock.cpp
    clang/lib/AST/Interp/InterpState.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/InterpBlock.cpp b/clang/lib/AST/Interp/InterpBlock.cpp
index 7bef5e678c074..5ac778aeb6075 100644
--- a/clang/lib/AST/Interp/InterpBlock.cpp
+++ b/clang/lib/AST/Interp/InterpBlock.cpp
@@ -110,6 +110,9 @@ DeadBlock::DeadBlock(DeadBlock *&Root, Block *Blk)
 }
 
 void DeadBlock::free() {
+  if (B.IsInitialized)
+    B.invokeDtor();
+
   if (Prev)
     Prev->Next = Next;
   if (Next)

diff  --git a/clang/lib/AST/Interp/InterpState.cpp b/clang/lib/AST/Interp/InterpState.cpp
index 332f551838b72..4ea05305540ee 100644
--- a/clang/lib/AST/Interp/InterpState.cpp
+++ b/clang/lib/AST/Interp/InterpState.cpp
@@ -69,13 +69,15 @@ void InterpState::deallocate(Block *B) {
     char *Memory =
         reinterpret_cast<char *>(std::malloc(sizeof(DeadBlock) + Size));
     auto *D = new (Memory) DeadBlock(DeadBlocks, B);
+    std::memset(D->B.rawData(), 0, D->B.getSize());
 
     // Move data and metadata from the old block to the new (dead)block.
-    if (Desc->MoveFn) {
+    if (B->IsInitialized && Desc->MoveFn) {
       Desc->MoveFn(B, B->data(), D->data(), Desc);
       if (Desc->getMetadataSize() > 0)
         std::memcpy(D->rawData(), B->rawData(), Desc->getMetadataSize());
     }
+    D->B.IsInitialized = B->IsInitialized;
 
     // We moved the contents over to the DeadBlock.
     B->IsInitialized = false;


        


More information about the cfe-commits mailing list