summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGExprCXX.cpp
diff options
context:
space:
mode:
authorHans Wennborg <hans@chromium.org>2025-03-12 16:18:07 +0100
committerHans Wennborg <hans@chromium.org>2025-03-12 16:26:00 +0100
commite11ede5e90ee193dde179fe1a9ac9af718ede3db (patch)
treed719a4919d44cc8f4a5665a199a96bf98863b711 /clang/lib/CodeGen/CGExprCXX.cpp
parent90a8322399c7beb021cfe704003d36fafb1a7d29 (diff)
Revert "[MS][clang] Add support for vector deleting destructors (#126240)"
This caused link errors when building with sancov. See comment on the PR. > Whereas it is UB in terms of the standard to delete an array of objects > via pointer whose static type doesn't match its dynamic type, MSVC > supports an extension allowing to do it. > Aside from array deletion not working correctly in the mentioned case, > currently not having this extension implemented causes clang to generate > code that is not compatible with the code generated by MSVC, because > clang always puts scalar deleting destructor to the vftable. This PR > aims to resolve these problems. > > Fixes https://github.com/llvm/llvm-project/issues/19772 This reverts commit d6942d54f677000cf713d2b0eba57b641452beb4.
Diffstat (limited to 'clang/lib/CodeGen/CGExprCXX.cpp')
-rw-r--r--clang/lib/CodeGen/CGExprCXX.cpp42
1 files changed, 4 insertions, 38 deletions
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index d4e14f4574b8..f71c18a8041b 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1209,8 +1209,6 @@ void CodeGenFunction::EmitNewArrayInitializer(
EmitCXXAggrConstructorCall(Ctor, NumElements, CurPtr, CCE,
/*NewPointerIsChecked*/true,
CCE->requiresZeroInitialization());
- if (CGM.getCXXABI().hasVectorDeletingDtors())
- CGM.requireVectorDestructorDefinition(Ctor->getParent());
return;
}
@@ -1914,8 +1912,10 @@ 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) {
// C++11 [expr.delete]p3:
// If the static type of the object to be deleted is different from its
@@ -2131,40 +2131,6 @@ void CodeGenFunction::EmitCXXDeleteExpr(const CXXDeleteExpr *E) {
assert(ConvertTypeForMem(DeleteTy) == Ptr.getElementType());
- if (E->isArrayForm() && CGM.getCXXABI().hasVectorDeletingDtors()) {
- if (auto *RD = DeleteTy->getAsCXXRecordDecl()) {
- auto *Dtor = RD->getDestructor();
- if (Dtor && Dtor->isVirtual()) {
- llvm::Value *NumElements = nullptr;
- llvm::Value *AllocatedPtr = nullptr;
- CharUnits CookieSize;
- llvm::BasicBlock *bodyBB = createBasicBlock("vdtor.call");
- llvm::BasicBlock *doneBB = createBasicBlock("vdtor.nocall");
- // Check array cookie to see if the array has 0 length. Don't call
- // the destructor in that case.
- CGM.getCXXABI().ReadArrayCookie(*this, Ptr, E, DeleteTy, NumElements,
- AllocatedPtr, CookieSize);
-
- auto *CondTy = cast<llvm::IntegerType>(NumElements->getType());
- llvm::Value *isEmpty = Builder.CreateICmpEQ(
- NumElements, llvm::ConstantInt::get(CondTy, 0));
- Builder.CreateCondBr(isEmpty, doneBB, bodyBB);
-
- // Delete cookie for empty array.
- const FunctionDecl *operatorDelete = E->getOperatorDelete();
- EmitBlock(doneBB);
- EmitDeleteCall(operatorDelete, AllocatedPtr, DeleteTy, NumElements,
- CookieSize);
- EmitBranch(DeleteEnd);
-
- EmitBlock(bodyBB);
- if (!EmitObjectDelete(*this, E, Ptr, DeleteTy, DeleteEnd))
- EmitBlock(DeleteEnd);
- return;
- }
- }
- }
-
if (E->isArrayForm()) {
EmitArrayDelete(*this, E, Ptr, DeleteTy);
EmitBlock(DeleteEnd);