[clang] [lldb] Reland [MS][clang] Add support for vector deleting destructors (PR #165598)

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 5 03:27:00 PST 2025


================
@@ -8281,3 +8281,53 @@ void CodeGenModule::moveLazyEmissionStates(CodeGenModule *NewBuilder) {
 
   NewBuilder->ABI->MangleCtx = std::move(ABI->MangleCtx);
 }
+
+bool CodeGenModule::classNeedsVectorDestructor(const CXXRecordDecl *RD) {
+  if (!Context.getTargetInfo().emitVectorDeletingDtors(Context.getLangOpts()))
+    return false;
+  CXXDestructorDecl *Dtor = RD->getDestructor();
+  // The compiler can't know if new[]/delete[] will be used outside of the DLL,
+  // so just force vector deleting destructor emission if dllexport is present.
+  // This matches MSVC behavior.
+  if (Dtor && Dtor->isVirtual() && Dtor->isDefined() &&
+      Dtor->hasAttr<DLLExportAttr>())
+    return true;
+
+  return RequireVectorDeletingDtor.count(RD);
+}
+
+void CodeGenModule::requireVectorDestructorDefinition(const CXXRecordDecl *RD) {
+  if (!Context.getTargetInfo().emitVectorDeletingDtors(Context.getLangOpts()))
+    return;
+  RequireVectorDeletingDtor.insert(RD);
+
+  // To reduce code size in general case we lazily emit scalar deleting
+  // destructor definition and an alias from vector deleting destructor to
+  // scalar deleting destructor. It may happen that we first emitted the scalar
----------------
Fznamznon wrote:

The problem here is that the vtable entry should always refer to the vector deleting destructor for compatibility with MSVC. Vector deleting destructor is notably more complex and bigger than scalar deleting destructor and only required for array deletions, so we try to optimize the case when no array deletions are required by only emitting scalar deleting destructors. I suppose that won't work without an alias.
We could always emit vector deleting destructor body because it can do both scalar and array deletion but I don't know if that will have negative implications for the users that do not care about this extension.

That just implements @rnk's suggestion from https://github.com/llvm/llvm-project/issues/19772#issuecomment-2234692425 .

https://github.com/llvm/llvm-project/pull/165598


More information about the cfe-commits mailing list