[clang] 58031e5 - [clang][bytecode] Add `Block::invokeCtorNoMemset()` (#203749)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 15 00:54:31 PDT 2026


Author: Timm Baeder
Date: 2026-06-15T09:54:26+02:00
New Revision: 58031e519153fdbe637f9f135ac1fbfef6f0e224

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

LOG: [clang][bytecode] Add `Block::invokeCtorNoMemset()` (#203749)

`invokeCtor()` first memsets the memory to zero, then calls the
descriptor ctor function. The memset is unnecessary if we're already
working with zero-ed memory, like the one we get from
`std::make_unique`.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/DynamicAllocator.cpp
    clang/lib/AST/ByteCode/EvalEmitter.cpp
    clang/lib/AST/ByteCode/InterpBlock.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/DynamicAllocator.cpp b/clang/lib/AST/ByteCode/DynamicAllocator.cpp
index 36e0bfd666b74..a3a0dcd489a76 100644
--- a/clang/lib/AST/ByteCode/DynamicAllocator.cpp
+++ b/clang/lib/AST/ByteCode/DynamicAllocator.cpp
@@ -76,7 +76,7 @@ Block *DynamicAllocator::allocate(const Descriptor *D, unsigned EvalID,
   auto Memory =
       std::make_unique<std::byte[]>(sizeof(Block) + D->getAllocSize());
   auto *B = new (Memory.get()) Block(EvalID, D, /*isStatic=*/false);
-  B->invokeCtor();
+  B->invokeCtorNoMemset();
 
   assert(D->getMetadataSize() == sizeof(InlineDescriptor));
   InlineDescriptor *ID = reinterpret_cast<InlineDescriptor *>(B->rawData());

diff  --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index a7afd3008afb8..6e986f4bcbda5 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.cpp
+++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp
@@ -134,7 +134,7 @@ Scope::Local EvalEmitter::createLocal(Descriptor *D) {
   // Allocate memory for a local.
   auto Memory = std::make_unique<char[]>(sizeof(Block) + D->getAllocSize());
   auto *B = new (Memory.get()) Block(Ctx.getEvalID(), D, /*IsStatic=*/false);
-  B->invokeCtor();
+  B->invokeCtorNoMemset();
 
   // Initialize local variable inline descriptor.
   auto &Desc = B->getBlockDesc<InlineDescriptor>();

diff  --git a/clang/lib/AST/ByteCode/InterpBlock.h b/clang/lib/AST/ByteCode/InterpBlock.h
index 4a1195ef25bbe..0d64439da78ae 100644
--- a/clang/lib/AST/ByteCode/InterpBlock.h
+++ b/clang/lib/AST/ByteCode/InterpBlock.h
@@ -136,11 +136,16 @@ class Block final {
   void invokeCtor() {
     assert(!IsInitialized);
     std::memset(rawData(), 0, Desc->getAllocSize());
-    if (Desc->CtorFn) {
+    invokeCtorNoMemset();
+  }
+  /// The same, but won't memset() the memory first to zero.
+  void invokeCtorNoMemset() {
+    assert(!IsInitialized);
+    if (Desc->CtorFn)
       Desc->CtorFn(this, data(), Desc->IsConst, Desc->IsMutable,
                    Desc->IsVolatile,
                    /*isActive=*/true, /*InUnion=*/false, Desc);
-    }
+
     IsInitialized = true;
   }
 


        


More information about the cfe-commits mailing list