Timm =?utf-8?q?Bäder?= <tbae...@redhat.com> Message-ID: In-Reply-To: <llvm.org/llvm/llvm-project/pull/146...@github.com>
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/146286 >From a034db206e38bc4473bb47e152a7078e7348649a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Wed, 25 Jun 2025 10:27:56 +0200 Subject: [PATCH 1/2] Descriptor::hasTrivialDtor() --- clang/lib/AST/ByteCode/Compiler.h | 18 +++++++++--------- clang/lib/AST/ByteCode/Descriptor.cpp | 15 +++++++++++++++ clang/lib/AST/ByteCode/Descriptor.h | 3 +++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/clang/lib/AST/ByteCode/Compiler.h b/clang/lib/AST/ByteCode/Compiler.h index a1d068cc7e0ae..1a5fd86785872 100644 --- a/clang/lib/AST/ByteCode/Compiler.h +++ b/clang/lib/AST/ByteCode/Compiler.h @@ -574,17 +574,17 @@ template <class Emitter> class LocalScope : public VariableScope<Emitter> { // Emit destructor calls for local variables of record // type with a destructor. for (Scope::Local &Local : llvm::reverse(this->Ctx->Descriptors[*Idx])) { - if (!Local.Desc->isPrimitive() && !Local.Desc->isPrimitiveArray()) { - if (!this->Ctx->emitGetPtrLocal(Local.Offset, E)) - return false; + if (Local.Desc->hasTrivialDtor()) + continue; + if (!this->Ctx->emitGetPtrLocal(Local.Offset, E)) + return false; - if (!this->Ctx->emitDestruction(Local.Desc, Local.Desc->getLoc())) - return false; + if (!this->Ctx->emitDestruction(Local.Desc, Local.Desc->getLoc())) + return false; - if (!this->Ctx->emitPopPtr(E)) - return false; - removeIfStoredOpaqueValue(Local); - } + if (!this->Ctx->emitPopPtr(E)) + return false; + removeIfStoredOpaqueValue(Local); } return true; } diff --git a/clang/lib/AST/ByteCode/Descriptor.cpp b/clang/lib/AST/ByteCode/Descriptor.cpp index 46e4d0d940b3e..ec0c838fd1ae5 100644 --- a/clang/lib/AST/ByteCode/Descriptor.cpp +++ b/clang/lib/AST/ByteCode/Descriptor.cpp @@ -502,6 +502,21 @@ SourceInfo Descriptor::getLoc() const { llvm_unreachable("Invalid descriptor type"); } +bool Descriptor::hasTrivialDtor() const { + if (isPrimitive() || isPrimitiveArray()) + return true; + + if (isRecord()) { + assert(ElemRecord); + const CXXDestructorDecl *Dtor = ElemRecord->getDestructor(); + return !Dtor || Dtor->isTrivial(); + } + + // Composite arrays. + assert(ElemDesc); + return ElemDesc->hasTrivialDtor(); +} + bool Descriptor::isUnion() const { return isRecord() && ElemRecord->isUnion(); } InitMap::InitMap(unsigned N) diff --git a/clang/lib/AST/ByteCode/Descriptor.h b/clang/lib/AST/ByteCode/Descriptor.h index f25ad8f4c758c..4591eabb69bb4 100644 --- a/clang/lib/AST/ByteCode/Descriptor.h +++ b/clang/lib/AST/ByteCode/Descriptor.h @@ -281,6 +281,9 @@ struct Descriptor final { /// Checks if this is a dummy descriptor. bool isDummy() const { return IsDummy; } + /// Whether variables of this descriptor need their destructor called or not. + bool hasTrivialDtor() const; + void dump() const; void dump(llvm::raw_ostream &OS) const; void dumpFull(unsigned Offset = 0, unsigned Indent = 0) const; >From 3dbbe89297da29c5397e9a00b3beb5452da53ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Sun, 29 Jun 2025 22:49:36 +0200 Subject: [PATCH 2/2] Handly dummy descriptors --- clang/lib/AST/ByteCode/Descriptor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/AST/ByteCode/Descriptor.cpp b/clang/lib/AST/ByteCode/Descriptor.cpp index ec0c838fd1ae5..c89eca9bef440 100644 --- a/clang/lib/AST/ByteCode/Descriptor.cpp +++ b/clang/lib/AST/ByteCode/Descriptor.cpp @@ -503,7 +503,7 @@ SourceInfo Descriptor::getLoc() const { } bool Descriptor::hasTrivialDtor() const { - if (isPrimitive() || isPrimitiveArray()) + if (isPrimitive() || isPrimitiveArray() || isDummy()) return true; if (isRecord()) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits