[clang] [MS][clang] Add support for vector deleting destructors (PR #126240)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 7 04:39:02 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 83ba3740bf51347307494d013099e392c310e32b 04636bea1b873805af02dea865637d7125cee1e5 --extensions cppm,cpp,h -- clang/test/CodeGenCXX/microsoft-vector-deleting-dtors.cpp 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/CGDebugInfo.cpp clang/lib/CodeGen/CGExprCXX.cpp clang/lib/CodeGen/CGVTables.cpp clang/lib/CodeGen/CodeGenModule.cpp clang/lib/CodeGen/CodeGenModule.h clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/CodeGen/MicrosoftCXXABI.cpp clang/test/CodeGenCXX/debug-info-windows-dtor.cpp clang/test/CodeGenCXX/dllexport.cpp clang/test/CodeGenCXX/microsoft-abi-extern-template.cpp clang/test/CodeGenCXX/microsoft-abi-structors.cpp clang/test/CodeGenCXX/microsoft-abi-thunks.cpp clang/test/CodeGenCXX/microsoft-abi-vftables.cpp clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp clang/test/CodeGenCXX/microsoft-abi-vtables-multiple-nonvirtual-inheritance-vdtors.cpp clang/test/CodeGenCXX/microsoft-abi-vtables-return-thunks.cpp clang/test/CodeGenCXX/microsoft-abi-vtables-single-inheritance.cpp clang/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance-vtordisps.cpp clang/test/CodeGenCXX/microsoft-abi-vtables-virtual-inheritance.cpp clang/test/CodeGenCXX/microsoft-no-rtti-data.cpp clang/test/CodeGenCXX/vtable-consteval.cpp clang/test/Modules/vtable-windows.cppm clang/test/Profile/cxx-abc-deleting-dtor.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 d5dc7833a7..6e2be2557d 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");
}
@@ -2885,10 +2887,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/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index bb94d502c3..f78e69c4d5 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,
@@ -1570,7 +1570,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()) &&
@@ -1647,17 +1648,17 @@ void CodeGenFunction::emitImplicitAssignmentOperatorBody(FunctionArgList &Args)
}
namespace {
- /// Call the operator delete associated with the current destructor.
- struct CallDtorDelete final : EHScopeStack::Cleanup {
- CallDtorDelete() {}
+/// 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 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,
@@ -1910,7 +1911,7 @@ namespace {
*StartIndex, -1);
}
};
-} // end anonymous namespace
+ } // end anonymous namespace
/// Emit all code that comes at the end of class's
/// destructor. This is to call destructors on members and base classes
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 5b00f79b03..998d319c58 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1914,10 +1914,8 @@ static void EmitDestroyingObjectDelete(CodeGenFunction &CGF,
/// Emit the code for deleting a single object.
/// \return \c true if we started emitting UnconditionalDeleteBlock, \c false
/// if not.
-static bool EmitObjectDelete(CodeGenFunction &CGF,
- const CXXDeleteExpr *DE,
- Address Ptr,
- QualType ElementType,
+static bool EmitObjectDelete(CodeGenFunction &CGF, const CXXDeleteExpr *DE,
+ Address Ptr, QualType ElementType,
llvm::BasicBlock *UnconditionalDeleteBlock,
bool ArrayDeletion) {
// C++11 [expr.delete]p3:
@@ -2164,7 +2162,7 @@ void CodeGenFunction::EmitCXXDeleteExpr(const CXXDeleteExpr *E) {
EmitBlock(bodyBB);
if (!EmitObjectDelete(*this, E, Ptr, DeleteTy, DeleteEnd,
- /*ArrayDeletion*/true))
+ /*ArrayDeletion*/ true))
EmitBlock(DeleteEnd);
return;
}
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index ea1ec6cbc1..882090e3ea 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -182,9 +182,7 @@ public:
}
bool shouldTypeidBeNullChecked(QualType SrcRecordTy) override;
- bool hasVectorDeletingDtors() override {
- return false;
- }
+ bool hasVectorDeletingDtors() override { return false; }
void EmitBadTypeidCall(CodeGenFunction &CGF) override;
llvm::Value *EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy,
Address ThisPtr,
@@ -455,7 +453,8 @@ public:
if (!IsInlined)
continue;
- StringRef Name = CGM.getMangledName(VtableComponent.getGlobalDecl(false));
+ StringRef Name =
+ CGM.getMangledName(VtableComponent.getGlobalDecl(false));
auto *Entry = CGM.GetGlobalValue(Name);
// This checks if virtual inline function has already been emitted.
// Note that it is possible that this inline function would be emitted
@@ -1373,8 +1372,7 @@ bool ItaniumCXXABI::isZeroInitializable(const MemberPointerType *MPT) {
/// at entry -2 in the vtable.
void ItaniumCXXABI::emitVirtualObjectDelete(CodeGenFunction &CGF,
const CXXDeleteExpr *DE,
- Address Ptr,
- QualType ElementType,
+ Address Ptr, QualType ElementType,
const CXXDestructorDecl *Dtor,
bool ArrayDeletion) {
bool UseGlobalDelete = DE->isGlobalDelete();
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index daeb19071d..ed259ce2d3 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -146,9 +146,7 @@ public:
}
bool shouldTypeidBeNullChecked(QualType SrcRecordTy) override;
- bool hasVectorDeletingDtors() override {
- return true;
- }
+ bool hasVectorDeletingDtors() override { return true; }
void EmitBadTypeidCall(CodeGenFunction &CGF) override;
llvm::Value *EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy,
Address ThisPtr,
``````````
</details>
https://github.com/llvm/llvm-project/pull/126240
More information about the cfe-commits
mailing list