[clang] WIP on vector deleting destructors (PR #121490)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 2 08:00:14 PST 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 207e485f4b7e8113b8b329ddcde423aafc0a8832 6b6ff040c875fd12614409927f39e37920089070 --extensions cpp,h -- clang/include/clang/AST/VTableBuilder.h clang/include/clang/Basic/ABI.h clang/lib/AST/ItaniumMangle.cpp clang/lib/AST/MicrosoftMangle.cpp clang/lib/AST/VTableBuilder.cpp clang/lib/CodeGen/CGCXX.cpp clang/lib/CodeGen/CGCXXABI.cpp clang/lib/CodeGen/CGCXXABI.h clang/lib/CodeGen/CGClass.cpp clang/lib/CodeGen/CodeGenModule.h clang/lib/CodeGen/MicrosoftCXXABI.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index 0f878c2de6..0b42738548 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -1484,7 +1484,9 @@ void MicrosoftCXXNameMangler::mangleCXXDtorType(CXXDtorType T) {
   // <operator-name> ::= ?_G # scalar deleting destructor
   case Dtor_Deleting: Out << "?_G"; return;
   // <operator-name> ::= ?_E # vector deleting destructor
-  case Dtor_VectorDeleting: Out << "?_E"; return;
+  case Dtor_VectorDeleting:
+    Out << "?_E";
+    return;
   case Dtor_Comdat:
     llvm_unreachable("not expecting a COMDAT");
   }
@@ -2916,10 +2918,10 @@ void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T,
   //               ::= @ # structors (they have no declared return type)
   if (IsStructor) {
     if (isa<CXXDestructorDecl>(D) && isStructorDecl(D)) {
-      // The deleting destructors take an extra argument of type int that indicates
-      // whether the storage for the object should be deleted and whether a single
-      // object or an array of objects is being destroyed. This extra argument is not
-      // reflected in the AST.
+      // The deleting destructors take an extra argument of type int that
+      // indicates whether the storage for the object should be deleted and
+      // whether a single object or an array of objects is being destroyed. This
+      // extra argument is not reflected in the AST.
       if (StructorType == Dtor_Deleting ||
           StructorType == Dtor_VectorDeleting) {
         Out << (PointersAre64Bit ? "PEAXI at Z" : "PAXI at Z");
diff --git a/clang/lib/AST/VTableBuilder.cpp b/clang/lib/AST/VTableBuilder.cpp
index d2a3128c28..22eb470334 100644
--- a/clang/lib/AST/VTableBuilder.cpp
+++ b/clang/lib/AST/VTableBuilder.cpp
@@ -1732,8 +1732,8 @@ void ItaniumVTableBuilder::LayoutPrimaryAndSecondaryVTables(
       const CXXMethodDecl *MD = I.first;
       const MethodInfo &MI = I.second;
       if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD)) {
-	MethodVTableIndices[GlobalDecl(DD, Dtor_Complete)]
-            = MI.VTableIndex - AddressPoint;
+        MethodVTableIndices[GlobalDecl(DD, Dtor_Complete)] =
+            MI.VTableIndex - AddressPoint;
         MethodVTableIndices[GlobalDecl(DD, Dtor_Deleting)]
             = MI.VTableIndex + 1 - AddressPoint;
       } else {
@@ -3291,7 +3291,7 @@ void VFTableBuilder::dumpLayout(raw_ostream &Out) {
       if (Context.getTargetInfo().getCXXABI().isMicrosoft())
         Out << "() [vector deleting]";
       else
-      Out << "() [deleting]";
+        Out << "() [deleting]";
 
       if (DD->isPureVirtual())
         Out << " [pure]";
diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp
index 2c83a87897..04c6e44993 100644
--- a/clang/lib/CodeGen/CGCXX.cpp
+++ b/clang/lib/CodeGen/CGCXX.cpp
@@ -204,7 +204,8 @@ bool CodeGenModule::TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) {
 /// Use this function with care as it can produce invalid aliases.  Generally
 /// this function should be used only where there is an ABI requirement to emit
 /// an alias.
-void CodeGenModule::EmitDefinitionAsAlias(GlobalDecl AliasDecl, GlobalDecl TargetDecl) {
+void CodeGenModule::EmitDefinitionAsAlias(GlobalDecl AliasDecl,
+                                          GlobalDecl TargetDecl) {
 
   // Derive the type for the alias.
   llvm::PointerType *AliasValueType =
@@ -240,7 +241,6 @@ llvm::Function *CodeGenModule::codegenCXXStructor(GlobalDecl GD) {
     // Emit an alias from the vector deleting destructor to the scalar deleting
     // destructor.
     EmitDefinitionAsAlias(VectorDtorGD, ScalarDtorGD);
-
   }
   const CGFunctionInfo &FnInfo = getTypes().arrangeCXXStructorDeclaration(GD);
   auto *Fn = cast<llvm::Function>(
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index 8b9cdf9111..b705660476 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -1440,7 +1440,7 @@ llvm::Value *LoadThisForDtorDelete(CodeGenFunction &CGF,
     return CGF.EmitScalarExpr(ThisArg);
   return CGF.LoadCXXThis();
 }
-}
+} // namespace
 
 void EmitConditionalArrayDtorCall(const CXXDestructorDecl *DD,
                                   CodeGenFunction &CGF,
@@ -1577,7 +1577,8 @@ void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) {
   switch (DtorType) {
   case Dtor_Comdat: llvm_unreachable("not expecting a COMDAT");
   case Dtor_Deleting: llvm_unreachable("already handled deleting case");
-  case Dtor_VectorDeleting: llvm_unreachable("already handled vector deleting case");
+  case Dtor_VectorDeleting:
+    llvm_unreachable("already handled vector deleting case");
 
   case Dtor_Complete:
     assert((Body || getTarget().getCXXABI().isMicrosoft()) &&
@@ -1654,24 +1655,24 @@ void CodeGenFunction::emitImplicitAssignmentOperatorBody(FunctionArgList &Args)
 }
 
 namespace {
-  // llvm::Value *LoadThisForDtorDelete(CodeGenFunction &CGF,
-  //                                    const CXXDestructorDecl *DD) {
-  //   if (Expr *ThisArg = DD->getOperatorDeleteThisArg())
-  //     return CGF.EmitScalarExpr(ThisArg);
-  //   return CGF.LoadCXXThis();
-  // }
-
-  /// Call the operator delete associated with the current destructor.
-  struct CallDtorDelete final : EHScopeStack::Cleanup {
-    CallDtorDelete() {}
-
-    void Emit(CodeGenFunction &CGF, Flags flags) override {
-      const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(CGF.CurCodeDecl);
-      const CXXRecordDecl *ClassDecl = Dtor->getParent();
-      CGF.EmitDeleteCall(Dtor->getOperatorDelete(),
-                         LoadThisForDtorDelete(CGF, Dtor),
-                         CGF.getContext().getTagDeclType(ClassDecl));
-    }
+// llvm::Value *LoadThisForDtorDelete(CodeGenFunction &CGF,
+//                                    const CXXDestructorDecl *DD) {
+//   if (Expr *ThisArg = DD->getOperatorDeleteThisArg())
+//     return CGF.EmitScalarExpr(ThisArg);
+//   return CGF.LoadCXXThis();
+// }
+
+/// Call the operator delete associated with the current destructor.
+struct CallDtorDelete final : EHScopeStack::Cleanup {
+  CallDtorDelete() {}
+
+  void Emit(CodeGenFunction &CGF, Flags flags) override {
+    const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(CGF.CurCodeDecl);
+    const CXXRecordDecl *ClassDecl = Dtor->getParent();
+    CGF.EmitDeleteCall(Dtor->getOperatorDelete(),
+                       LoadThisForDtorDelete(CGF, Dtor),
+                       CGF.getContext().getTagDeclType(ClassDecl));
+  }
   };
 
   void EmitConditionalDtorDeleteCall(CodeGenFunction &CGF,

``````````

</details>


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


More information about the cfe-commits mailing list