[clang] [clang][bytecode] Move `Descriptor` metadata to `Block` (PR #217280)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 19 03:47:51 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
The metadata in `Descriptor`s was only ever used for "toplevel" descriptors, i.e. never for fields or array elements. Those are also the descriptors we allocate into `Block`s though, so move the metadata there and save some space in `Descriptor`.
---
Patch is 45.85 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/217280.diff
18 Files Affected:
- (modified) clang/lib/AST/ByteCode/ByteCodeEmitter.cpp (+1-1)
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+10-17)
- (modified) clang/lib/AST/ByteCode/Context.cpp (+4-4)
- (modified) clang/lib/AST/ByteCode/Descriptor.cpp (+32-41)
- (modified) clang/lib/AST/ByteCode/Descriptor.h (+14-26)
- (modified) clang/lib/AST/ByteCode/Disasm.cpp (+1-3)
- (modified) clang/lib/AST/ByteCode/DynamicAllocator.cpp (+6-10)
- (modified) clang/lib/AST/ByteCode/EvalEmitter.cpp (+4-2)
- (modified) clang/lib/AST/ByteCode/Interp.cpp (+1-1)
- (modified) clang/lib/AST/ByteCode/InterpBlock.cpp (+4-4)
- (modified) clang/lib/AST/ByteCode/InterpBlock.h (+37-37)
- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+3-3)
- (modified) clang/lib/AST/ByteCode/InterpFrame.cpp (+2-1)
- (modified) clang/lib/AST/ByteCode/MemberPointer.cpp (+1-1)
- (modified) clang/lib/AST/ByteCode/Pointer.cpp (+3-3)
- (modified) clang/lib/AST/ByteCode/Pointer.h (+6-9)
- (modified) clang/lib/AST/ByteCode/Program.cpp (+52-56)
- (modified) clang/lib/AST/ByteCode/Program.h (+2-4)
``````````diff
diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
index 9a2c1c2b496b0..f04478eb6ac16 100644
--- a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
@@ -92,7 +92,7 @@ void ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl,
Scope::Local ByteCodeEmitter::createLocal(Descriptor *D) {
NextLocalOffset += sizeof(Block);
unsigned Location = NextLocalOffset;
- NextLocalOffset += align(D->getAllocSize());
+ NextLocalOffset += align(Block::InlineDescMD + D->getAllocSize());
return {Location, D};
}
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index a8e2cb4a3c076..cbfd067bfbdd4 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4218,14 +4218,11 @@ bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) {
if (E->isArray())
Desc = nullptr; // We're not going to use it in this case.
else
- Desc = P.createDescriptor(E, *ElemT, /*SourceTy=*/nullptr,
- Descriptor::InlineDescMD);
+ Desc = P.createDescriptor(E, *ElemT);
} else {
- Desc = P.createDescriptor(
- E, ElementType.getTypePtr(),
- E->isArray() ? std::nullopt : Descriptor::InlineDescMD,
- /*IsConst=*/false, /*IsTemporary=*/false, /*IsMutable=*/false,
- /*IsVolatile=*/false, Init);
+ Desc = P.createDescriptor(E, ElementType.getTypePtr(), /*IsConst=*/false,
+ /*IsTemporary=*/false, /*IsMutable=*/false,
+ /*IsVolatile=*/false, Init);
}
}
@@ -5322,8 +5319,7 @@ unsigned Compiler<Emitter>::allocateLocalPrimitive(DeclOrExpr &&Src,
// FIXME: There are cases where Src.isExpr() is wrong, e.g.
// (int){12} in C. Consider using Expr::isTemporaryObject() instead
// or isa<MaterializeTemporaryExpr>().
- Descriptor *D = P.createDescriptor(Src, Ty, nullptr, Descriptor::InlineDescMD,
- IsConst, Src.isExpr(),
+ Descriptor *D = P.createDescriptor(Src, Ty, nullptr, IsConst, Src.isExpr(),
/*IsMutable=*/false, IsVolatile);
D->IsConstexprUnknown = this->VariablesAreConstexprUnknown;
Scope::Local Local = this->createLocal(D);
@@ -5352,9 +5348,8 @@ UnsignedOrNone Compiler<Emitter>::allocateLocal(DeclOrExpr &&Src, QualType Ty,
}
Descriptor *D = P.createDescriptor(
- Src, Ty.getTypePtr(), Descriptor::InlineDescMD, Ty.isConstQualified(),
- IsTemporary, /*IsMutable=*/false, /*IsVolatile=*/Ty.isVolatileQualified(),
- Init);
+ Src, Ty.getTypePtr(), Ty.isConstQualified(), IsTemporary,
+ /*IsMutable=*/false, /*IsVolatile=*/Ty.isVolatileQualified(), Init);
if (!D)
return std::nullopt;
D->IsConstexprUnknown = this->VariablesAreConstexprUnknown;
@@ -5371,9 +5366,8 @@ UnsignedOrNone Compiler<Emitter>::allocateTemporary(const Expr *E) {
QualType Ty = E->getType();
assert(!Ty->isRecordType());
- Descriptor *D = P.createDescriptor(
- E, Ty.getTypePtr(), Descriptor::InlineDescMD, Ty.isConstQualified(),
- /*IsTemporary=*/true);
+ Descriptor *D = P.createDescriptor(E, Ty.getTypePtr(), Ty.isConstQualified(),
+ /*IsTemporary=*/true);
if (!D)
return std::nullopt;
@@ -5680,8 +5674,7 @@ bool Compiler<Emitter>::visitDtorCall(const VarDecl *VD, const APValue &Value) {
// Create a local variable to use as the instance.
QualType Ty = VD->getType();
Descriptor *D =
- P.createDescriptor(VD, Ty.getTypePtr(), Descriptor::InlineDescMD,
- /*IsConst=*/Ty.isConstQualified(),
+ P.createDescriptor(VD, Ty.getTypePtr(), /*IsConst=*/Ty.isConstQualified(),
/*IsTemporary=*/false, /*IsMutable=*/false,
/*IsVolatile=*/Ty.isVolatileQualified(), nullptr);
if (!D)
diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp
index ce7a95ed49c06..0678b07d0bbf2 100644
--- a/clang/lib/AST/ByteCode/Context.cpp
+++ b/clang/lib/AST/ByteCode/Context.cpp
@@ -687,8 +687,8 @@ const Function *Context::getOrCreateFunction(const FunctionDecl *FuncDecl) {
OptPrimType T = classify(PD->getType());
PrimType PT = T.value_or(PT_Ptr);
- Descriptor *Desc = P->createDescriptor(PD, PT, nullptr, std::nullopt,
- IsConst, /*IsTemporary=*/false,
+ Descriptor *Desc = P->createDescriptor(PD, PT, nullptr, IsConst,
+ /*IsTemporary=*/false,
/*IsMutable=*/false, IsVolatile);
unsigned PrimTSize = align(primSize(PT));
ParamDescriptors.emplace_back(Desc, ParamOffset, BlockOffset, PT);
@@ -718,8 +718,8 @@ const Function *Context::getOrCreateObjCBlock(const BlockExpr *E) {
OptPrimType T = classify(PD->getType());
PrimType PT = T.value_or(PT_Ptr);
- Descriptor *Desc = P->createDescriptor(PD, PT, nullptr, std::nullopt,
- IsConst, /*IsTemporary=*/false,
+ Descriptor *Desc = P->createDescriptor(PD, PT, nullptr, IsConst,
+ /*IsTemporary=*/false,
/*IsMutable=*/false, IsVolatile);
ParamDescriptors.emplace_back(Desc, ParamOffset, ~0u, PT);
ParamOffset += align(primSize(PT));
diff --git a/clang/lib/AST/ByteCode/Descriptor.cpp b/clang/lib/AST/ByteCode/Descriptor.cpp
index 98be3c592f97f..d0435d4684875 100644
--- a/clang/lib/AST/ByteCode/Descriptor.cpp
+++ b/clang/lib/AST/ByteCode/Descriptor.cpp
@@ -280,37 +280,33 @@ static BlockDtorFn getDtorArrayPrim(PrimType Type) {
/// Primitives.
Descriptor::Descriptor(DeclOrExpr D, const Type *SourceTy, PrimType Type,
- MetadataSize MD, bool IsConst, bool IsTemporary,
- bool IsMutable, bool IsVolatile)
+ bool IsConst, bool IsTemporary, bool IsMutable,
+ bool IsVolatile)
: Source(D), SourceType(SourceTy), ElemSize(primSize(Type)), Size(ElemSize),
- MDSize(MD.value_or(0)), AllocSize(align(Size + MDSize)), PrimT(Type),
- IsConst(IsConst), IsMutable(IsMutable), IsTemporary(IsTemporary),
- IsVolatile(IsVolatile), CtorFn(getCtorPrim(Type)),
- DtorFn(getDtorPrim(Type)) {
- assert(AllocSize >= Size);
+ AllocSize(align(ElemSize)), PrimT(Type), IsConst(IsConst),
+ IsMutable(IsMutable), IsTemporary(IsTemporary), IsVolatile(IsVolatile),
+ CtorFn(getCtorPrim(Type)), DtorFn(getDtorPrim(Type)) {
assert(Source && "Missing source");
}
/// Primitive arrays.
Descriptor::Descriptor(DeclOrExpr D, const Type *SourceTy, PrimType Type,
- MetadataSize MD, size_t NumElems, bool IsConst,
- bool IsTemporary, bool IsMutable, bool IsVolatile)
+ size_t NumElems, bool IsConst, bool IsTemporary,
+ bool IsMutable, bool IsVolatile)
: Source(D), SourceType(SourceTy), ElemSize(primSize(Type)),
- Size(ElemSize * NumElems), MDSize(MD.value_or(0)),
- AllocSize(align(MDSize) + align(Size) + sizeof(InitMapPtr)), PrimT(Type),
- IsConst(IsConst), IsMutable(IsMutable), IsTemporary(IsTemporary),
- IsVolatile(IsVolatile), IsArray(true), CtorFn(getCtorArrayPrim(Type)),
- DtorFn(getDtorArrayPrim(Type)) {
+ Size(ElemSize * NumElems), AllocSize(align(Size) + sizeof(InitMapPtr)),
+ PrimT(Type), IsConst(IsConst), IsMutable(IsMutable),
+ IsTemporary(IsTemporary), IsVolatile(IsVolatile), IsArray(true),
+ CtorFn(getCtorArrayPrim(Type)), DtorFn(getDtorArrayPrim(Type)) {
assert(Source && "Missing source");
assert(NumElems <= (MaxArrayElemBytes / ElemSize));
}
/// Primitive unknown-size arrays.
-Descriptor::Descriptor(DeclOrExpr D, PrimType Type, MetadataSize MD,
- bool IsTemporary, bool IsConst, UnknownSize)
+Descriptor::Descriptor(DeclOrExpr D, PrimType Type, bool IsConst,
+ bool IsTemporary, UnknownSize)
: Source(D), ElemSize(primSize(Type)), Size(UnknownSizeMark),
- MDSize(MD.value_or(0)),
- AllocSize(MDSize + sizeof(InitMapPtr) + alignof(void *)), PrimT(Type),
+ AllocSize(sizeof(InitMapPtr) + alignof(void *)), PrimT(Type),
IsConst(IsConst), IsMutable(false), IsTemporary(IsTemporary),
IsArray(true), CtorFn(getCtorArrayPrim(Type)),
DtorFn(getDtorArrayPrim(Type)) {
@@ -319,47 +315,42 @@ Descriptor::Descriptor(DeclOrExpr D, PrimType Type, MetadataSize MD,
/// Arrays of composite elements.
Descriptor::Descriptor(DeclOrExpr D, const Type *SourceTy,
- const Descriptor *Elem, MetadataSize MD,
- unsigned NumElems, bool IsConst, bool IsTemporary,
- bool IsMutable)
+ const Descriptor *Elem, unsigned NumElems, bool IsConst,
+ bool IsTemporary, bool IsMutable)
: Source(D), SourceType(SourceTy),
ElemSize(Elem->getAllocSize() + sizeof(InlineDescriptor)),
- Size(ElemSize * NumElems), MDSize(MD.value_or(0)),
- AllocSize(std::max<size_t>(alignof(void *), Size) + MDSize),
- ElemDesc(Elem), IsConst(IsConst), IsMutable(IsMutable),
- IsTemporary(IsTemporary), IsArray(true), CtorFn(ctorArrayDesc),
+ Size(ElemSize * NumElems),
+ AllocSize(std::max<size_t>(alignof(void *), Size)), ElemDesc(Elem),
+ IsConst(IsConst), IsMutable(IsMutable), IsTemporary(IsTemporary),
+ IsArray(true), CtorFn(ctorArrayDesc),
DtorFn(Elem->DtorFn ? dtorArrayDesc : nullptr) {
assert(Source && "Missing source");
}
/// Unknown-size arrays of composite elements.
-Descriptor::Descriptor(DeclOrExpr D, const Descriptor *Elem, MetadataSize MD,
- bool IsTemporary, UnknownSize)
+Descriptor::Descriptor(DeclOrExpr D, const Descriptor *Elem, bool IsTemporary,
+ UnknownSize)
: Source(D), ElemSize(Elem->getAllocSize() + sizeof(InlineDescriptor)),
- Size(UnknownSizeMark), MDSize(MD.value_or(0)),
- AllocSize(MDSize + alignof(void *)), ElemDesc(Elem), IsConst(true),
- IsMutable(false), IsTemporary(IsTemporary), IsArray(true),
+ Size(UnknownSizeMark), AllocSize(alignof(void *)), ElemDesc(Elem),
+ IsConst(true), IsMutable(false), IsTemporary(IsTemporary), IsArray(true),
CtorFn(ctorArrayDesc), DtorFn(Elem->DtorFn ? dtorArrayDesc : nullptr) {
assert(Source && "Missing source");
}
/// Composite records.
-Descriptor::Descriptor(DeclOrExpr D, const Record *R, MetadataSize MD,
- bool IsConst, bool IsTemporary, bool IsMutable,
- bool IsVolatile)
+Descriptor::Descriptor(DeclOrExpr D, const Record *R, bool IsConst,
+ bool IsTemporary, bool IsMutable, bool IsVolatile)
: Source(D), ElemSize(std::max<size_t>(alignof(void *), R->getFullSize())),
- Size(ElemSize), MDSize(MD.value_or(0)), AllocSize(Size + MDSize),
- ElemRecord(R), IsConst(IsConst), IsMutable(IsMutable),
- IsTemporary(IsTemporary), IsVolatile(IsVolatile), CtorFn(ctorRecord),
- DtorFn(needsRecordDtor(R) ? dtorRecord : nullptr) {
+ Size(ElemSize), AllocSize(Size), ElemRecord(R), IsConst(IsConst),
+ IsMutable(IsMutable), IsTemporary(IsTemporary), IsVolatile(IsVolatile),
+ CtorFn(ctorRecord), DtorFn(needsRecordDtor(R) ? dtorRecord : nullptr) {
assert(Source && "Missing source");
}
/// Dummy.
-Descriptor::Descriptor(DeclOrExpr D, MetadataSize MD)
- : Source(D), ElemSize(1), Size(1), MDSize(MD.value_or(0)),
- AllocSize(MDSize), ElemRecord(nullptr), IsConst(true), IsMutable(false),
- IsTemporary(false) {
+Descriptor::Descriptor(DeclOrExpr D)
+ : Source(D), ElemSize(1), Size(1), AllocSize(0), ElemDesc(nullptr),
+ IsConst(true), IsMutable(false), IsTemporary(false) {
assert(Source && "Missing source");
}
diff --git a/clang/lib/AST/ByteCode/Descriptor.h b/clang/lib/AST/ByteCode/Descriptor.h
index 275e2aa594669..ee88b8bad3aee 100644
--- a/clang/lib/AST/ByteCode/Descriptor.h
+++ b/clang/lib/AST/ByteCode/Descriptor.h
@@ -128,9 +128,7 @@ struct Descriptor final {
const unsigned ElemSize;
/// Size of the storage, in host bytes.
const unsigned Size;
- /// Size of the metadata.
- const unsigned MDSize;
- /// Size of the allocation (storage + metadata), in host bytes.
+ /// Size of the allocation (storage), in host bytes.
const unsigned AllocSize;
/// Value to denote arrays of unknown size.
@@ -140,14 +138,9 @@ struct Descriptor final {
/// Token to denote structures of unknown size.
struct UnknownSize {};
- using MetadataSize = std::optional<unsigned>;
- static constexpr MetadataSize InlineDescMD = sizeof(InlineDescriptor);
- static constexpr MetadataSize GlobalMD = sizeof(GlobalInlineDescriptor);
-
/// Maximum number of bytes to be used for array elements.
static constexpr unsigned MaxArrayElemBytes =
- std::numeric_limits<decltype(AllocSize)>::max() - sizeof(InitMapPtr) -
- align(std::max(*InlineDescMD, *GlobalMD));
+ std::numeric_limits<decltype(AllocSize)>::max() - sizeof(InitMapPtr);
/// Pointer to the record, if block contains records.
const Record *const ElemRecord = nullptr;
@@ -173,33 +166,31 @@ struct Descriptor final {
const BlockDtorFn DtorFn = nullptr;
/// Allocates a descriptor for a primitive.
- Descriptor(DeclOrExpr D, const Type *SourceTy, PrimType Type, MetadataSize MD,
- bool IsConst, bool IsTemporary, bool IsMutable, bool IsVolatile);
+ Descriptor(DeclOrExpr D, const Type *SourceTy, PrimType Type, bool IsConst,
+ bool IsTemporary, bool IsMutable, bool IsVolatile);
/// Allocates a descriptor for an array of primitives.
- Descriptor(DeclOrExpr D, const Type *SourceTy, PrimType Type, MetadataSize MD,
- size_t NumElems, bool IsConst, bool IsTemporary, bool IsMutable,
- bool IsVolatile);
+ Descriptor(DeclOrExpr D, const Type *SourceTy, PrimType Type, size_t NumElems,
+ bool IsConst, bool IsTemporary, bool IsMutable, bool IsVolatile);
/// Allocates a descriptor for an array of primitives of unknown size.
- Descriptor(DeclOrExpr D, PrimType Type, MetadataSize MDSize, bool IsConst,
- bool IsTemporary, UnknownSize);
+ Descriptor(DeclOrExpr D, PrimType Type, bool IsConst, bool IsTemporary,
+ UnknownSize);
/// Allocates a descriptor for an array of composites.
Descriptor(DeclOrExpr D, const Type *SourceTy, const Descriptor *Elem,
- MetadataSize MD, unsigned NumElems, bool IsConst, bool IsTemporary,
- bool IsMutable);
+ unsigned NumElems, bool IsConst, bool IsTemporary, bool IsMutable);
/// Allocates a descriptor for an array of composites of unknown size.
- Descriptor(DeclOrExpr D, const Descriptor *Elem, MetadataSize MD,
- bool IsTemporary, UnknownSize);
+ Descriptor(DeclOrExpr D, const Descriptor *Elem, bool IsTemporary,
+ UnknownSize);
/// Allocates a descriptor for a record.
- Descriptor(DeclOrExpr D, const Record *R, MetadataSize MD, bool IsConst,
- bool IsTemporary, bool IsMutable, bool IsVolatile);
+ Descriptor(DeclOrExpr D, const Record *R, bool IsConst, bool IsTemporary,
+ bool IsMutable, bool IsVolatile);
/// Allocates a dummy descriptor.
- Descriptor(DeclOrExpr D, MetadataSize MD = std::nullopt);
+ Descriptor(DeclOrExpr D);
QualType getType() const;
QualType getElemQualType() const;
@@ -251,9 +242,6 @@ struct Descriptor final {
/// E.g., for PT_SInt32, that's 4 bytes.
unsigned getElemDataSize() const;
- /// Returns the size of the metadata.
- unsigned getMetadataSize() const { return MDSize; }
-
/// Returns the number of elements stored in the block.
unsigned getNumElems() const {
return Size == UnknownSizeMark ? 0 : (getSize() / getElemSize());
diff --git a/clang/lib/AST/ByteCode/Disasm.cpp b/clang/lib/AST/ByteCode/Disasm.cpp
index 4caf830a0a1b4..9499d3a246706 100644
--- a/clang/lib/AST/ByteCode/Disasm.cpp
+++ b/clang/lib/AST/ByteCode/Disasm.cpp
@@ -476,16 +476,13 @@ LLVM_DUMP_METHOD void Descriptor::dumpFull(unsigned Offset,
OS.indent(Spaces);
dump(OS);
OS << '\n';
- OS.indent(Spaces) << "Metadata: " << getMetadataSize() << " bytes\n";
OS.indent(Spaces) << "Size: " << getSize() << " bytes\n";
OS.indent(Spaces) << "AllocSize: " << getAllocSize() << " bytes\n";
- Offset += getMetadataSize();
if (isCompositeArray()) {
OS.indent(Spaces) << "Elements: " << getNumElems() << '\n';
unsigned FO = Offset;
for (unsigned I = 0; I != getNumElems(); ++I) {
FO += sizeof(InlineDescriptor);
- assert(ElemDesc->getMetadataSize() == 0);
OS.indent(Spaces) << "Element " << I << " offset: " << FO << '\n';
ElemDesc->dumpFull(FO, Indent + 1);
@@ -644,6 +641,7 @@ LLVM_DUMP_METHOD void Block::dump(llvm::raw_ostream &OS) const {
OS << " Weak: " << isWeak() << "\n";
OS << " Dummy: " << isDummy() << '\n';
OS << " Dynamic: " << isDynamic() << "\n";
+ OS << " Metadata: " << MDSize << '\n';
}
LLVM_DUMP_METHOD void EvaluationResult::dump() const {
diff --git a/clang/lib/AST/ByteCode/DynamicAllocator.cpp b/clang/lib/AST/ByteCode/DynamicAllocator.cpp
index f7909d313eaab..379df235b7fc1 100644
--- a/clang/lib/AST/ByteCode/DynamicAllocator.cpp
+++ b/clang/lib/AST/ByteCode/DynamicAllocator.cpp
@@ -39,8 +39,7 @@ Block *DynamicAllocator::allocate(const Expr *Source, PrimType T,
// Create a new descriptor for an array of the specified size and
// element type.
const Descriptor *D =
- allocateDescriptor(Source, nullptr, T, Descriptor::InlineDescMD,
- NumElements, /*IsConst=*/false,
+ allocateDescriptor(Source, nullptr, T, NumElements, /*IsConst=*/false,
/*IsTemporary=*/false, /*IsMutable=*/false,
/*IsVolatile=*/false);
@@ -50,13 +49,11 @@ Block *DynamicAllocator::allocate(const Expr *Source, PrimType T,
Block *DynamicAllocator::allocate(const Descriptor *ElementDesc,
size_t NumElements, unsigned EvalID,
Form AllocForm) {
- assert(ElementDesc->getMetadataSize() == 0);
// Create a new descriptor for an array of the specified size and
// element type.
// FIXME: Pass proper element type.
const Descriptor *D = allocateDescriptor(
- ElementDesc->asExpr(), nullptr, ElementDesc, Descriptor::InlineDescMD,
- NumElements,
+ ElementDesc->asExpr(), nullptr, ElementDesc, NumElements,
/*IsConst=*/false, /*IsTemporary=*/false, /*IsMutable=*/false);
return allocate(D, EvalID, AllocForm);
}
@@ -72,12 +69,11 @@ Block *DynamicAllocator::allocate(const Descriptor *D, unsigned EvalID,
return !Alloc.block()->hasPointers();
});
- auto Memory =
- std::make_unique<std::byte[]>(sizeof(Block) + D->getAllocSize());
- auto *B = new (Memory.get()) Block(EvalID, D, /*isStatic=*/false);
+ auto Memory = std::make_unique<std::byte[]>(
+ sizeof(Block) + D->getAllocSize() + Block::InlineDescMD);
+ auto *B = new (Memory.get()) Block(EvalID, D, Block::InlineDescMD,
+ /*isStatic=*/false);
B->invokeCtorNoMemset();
-
- assert(D->getMetadataSize() == sizeof(InlineDescriptor));
InlineDescriptor *ID = reinterpret_cast<InlineDescriptor *>(B->rawData());
ID->Desc = D;
ID->IsActive = true;
diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index a54b6d2c18fa9..59eb2731534ce 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.cpp
+++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp
@@ -151,8 +151,10 @@ EvalEmitter::LabelTy EvalEmitter::getLabel() { return NextLabel++; }
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);
+ auto Memory = std::make_unique<char[]>(sizeof(Block) + D->getAllocSize() +
+ Block::InlineDescMD);
+ auto *B = new (Memory.get()) Block(Ctx.getEvalID(), D, ...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/217280
More information about the cfe-commits
mailing list