Skip to content

Commit 47277d5

Browse files
committed
Revert "Reland [MS][clang] Add support for vector deleting destructors (llvm#133451)"
This reverts commit 842b57b.
1 parent 4f368fe commit 47277d5

34 files changed

+125
-534
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,6 @@ Windows Support
530530
- Clang now can process the `i128` and `ui128` integeral suffixes when MSVC
531531
extensions are enabled. This allows for properly processing ``intsafe.h`` in
532532
the Windows SDK.
533-
- Clang now supports MSVC vector deleting destructors (GH19772).
534533

535534
LoongArch Support
536535
^^^^^^^^^^^^^^^^^

clang/include/clang/AST/VTableBuilder.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class VTableComponent {
150150

151151
bool isRTTIKind() const { return isRTTIKind(getKind()); }
152152

153-
GlobalDecl getGlobalDecl(bool HasVectorDeletingDtors) const {
153+
GlobalDecl getGlobalDecl() const {
154154
assert(isUsedFunctionPointerKind() &&
155155
"GlobalDecl can be created only from virtual function");
156156

@@ -161,9 +161,7 @@ class VTableComponent {
161161
case CK_CompleteDtorPointer:
162162
return GlobalDecl(DtorDecl, CXXDtorType::Dtor_Complete);
163163
case CK_DeletingDtorPointer:
164-
return GlobalDecl(DtorDecl, (HasVectorDeletingDtors)
165-
? CXXDtorType::Dtor_VectorDeleting
166-
: CXXDtorType::Dtor_Deleting);
164+
return GlobalDecl(DtorDecl, CXXDtorType::Dtor_Deleting);
167165
case CK_VCallOffset:
168166
case CK_VBaseOffset:
169167
case CK_OffsetToTop:

clang/include/clang/Basic/ABI.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ enum CXXCtorType {
3131

3232
/// C++ destructor types.
3333
enum CXXDtorType {
34-
Dtor_Deleting, ///< Deleting dtor
35-
Dtor_Complete, ///< Complete object dtor
36-
Dtor_Base, ///< Base object dtor
37-
Dtor_Comdat, ///< The COMDAT used for dtors
38-
Dtor_VectorDeleting ///< Vector deleting dtor
34+
Dtor_Deleting, ///< Deleting dtor
35+
Dtor_Complete, ///< Complete object dtor
36+
Dtor_Base, ///< Base object dtor
37+
Dtor_Comdat ///< The COMDAT used for dtors
3938
};
4039

4140
} // end namespace clang

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6047,8 +6047,6 @@ void CXXNameMangler::mangleCXXDtorType(CXXDtorType T) {
60476047
case Dtor_Comdat:
60486048
Out << "D5";
60496049
break;
6050-
case Dtor_VectorDeleting:
6051-
llvm_unreachable("Itanium ABI does not use vector deleting dtors");
60526050
}
60536051
}
60546052

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,9 +1490,8 @@ void MicrosoftCXXNameMangler::mangleCXXDtorType(CXXDtorType T) {
14901490
// <operator-name> ::= ?_G # scalar deleting destructor
14911491
case Dtor_Deleting: Out << "?_G"; return;
14921492
// <operator-name> ::= ?_E # vector deleting destructor
1493-
case Dtor_VectorDeleting:
1494-
Out << "?_E";
1495-
return;
1493+
// FIXME: Add a vector deleting dtor type. It goes in the vtable, so we need
1494+
// it.
14961495
case Dtor_Comdat:
14971496
llvm_unreachable("not expecting a COMDAT");
14981497
}
@@ -2893,12 +2892,9 @@ void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T,
28932892
// ::= @ # structors (they have no declared return type)
28942893
if (IsStructor) {
28952894
if (isa<CXXDestructorDecl>(D) && isStructorDecl(D)) {
2896-
// The deleting destructors take an extra argument of type int that
2897-
// indicates whether the storage for the object should be deleted and
2898-
// whether a single object or an array of objects is being destroyed. This
2899-
// extra argument is not reflected in the AST.
2900-
if (StructorType == Dtor_Deleting ||
2901-
StructorType == Dtor_VectorDeleting) {
2895+
// The scalar deleting destructor takes an extra int argument which is not
2896+
// reflected in the AST.
2897+
if (StructorType == Dtor_Deleting) {
29022898
Out << (PointersAre64Bit ? "PEAXI@Z" : "PAXI@Z");
29032899
return;
29042900
}
@@ -3871,10 +3867,10 @@ void MicrosoftMangleContextImpl::mangleCXXDtorThunk(const CXXDestructorDecl *DD,
38713867
const ThunkInfo &Thunk,
38723868
bool /*ElideOverrideInfo*/,
38733869
raw_ostream &Out) {
3874-
// The dtor thunk should use vector deleting dtor mangling, however as an
3875-
// optimization we may end up emitting only scalar deleting dtor body, so just
3876-
// use the vector deleting dtor mangling manually.
3877-
assert(Type == Dtor_Deleting || Type == Dtor_VectorDeleting);
3870+
// FIXME: Actually, the dtor thunk should be emitted for vector deleting
3871+
// dtors rather than scalar deleting dtors. Just use the vector deleting dtor
3872+
// mangling manually until we support both deleting dtor types.
3873+
assert(Type == Dtor_Deleting);
38783874
msvc_hashing_ostream MHO(Out);
38793875
MicrosoftCXXNameMangler Mangler(*this, MHO, DD, Type);
38803876
Mangler.getStream() << "??_E";

clang/lib/AST/VTableBuilder.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,8 +1735,8 @@ void ItaniumVTableBuilder::LayoutPrimaryAndSecondaryVTables(
17351735
const CXXMethodDecl *MD = I.first;
17361736
const MethodInfo &MI = I.second;
17371737
if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD)) {
1738-
MethodVTableIndices[GlobalDecl(DD, Dtor_Complete)] =
1739-
MI.VTableIndex - AddressPoint;
1738+
MethodVTableIndices[GlobalDecl(DD, Dtor_Complete)]
1739+
= MI.VTableIndex - AddressPoint;
17401740
MethodVTableIndices[GlobalDecl(DD, Dtor_Deleting)]
17411741
= MI.VTableIndex + 1 - AddressPoint;
17421742
} else {
@@ -2657,11 +2657,7 @@ class VFTableBuilder {
26572657
MethodVFTableLocation Loc(MI.VBTableIndex, WhichVFPtr.getVBaseWithVPtr(),
26582658
WhichVFPtr.NonVirtualOffset, MI.VFTableIndex);
26592659
if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD)) {
2660-
// In Microsoft ABI vftable always references vector deleting dtor.
2661-
CXXDtorType DtorTy = Context.getTargetInfo().getCXXABI().isMicrosoft()
2662-
? Dtor_VectorDeleting
2663-
: Dtor_Deleting;
2664-
MethodVFTableLocations[GlobalDecl(DD, DtorTy)] = Loc;
2660+
MethodVFTableLocations[GlobalDecl(DD, Dtor_Deleting)] = Loc;
26652661
} else {
26662662
MethodVFTableLocations[MD] = Loc;
26672663
}
@@ -3291,10 +3287,7 @@ void VFTableBuilder::dumpLayout(raw_ostream &Out) {
32913287
const CXXDestructorDecl *DD = Component.getDestructorDecl();
32923288

32933289
DD->printQualifiedName(Out);
3294-
if (Context.getTargetInfo().getCXXABI().isMicrosoft())
3295-
Out << "() [vector deleting]";
3296-
else
3297-
Out << "() [scalar deleting]";
3290+
Out << "() [scalar deleting]";
32983291

32993292
if (DD->isPureVirtual())
33003293
Out << " [pure]";
@@ -3764,7 +3757,7 @@ void MicrosoftVTableContext::dumpMethodLocations(
37643757
PredefinedIdentKind::PrettyFunctionNoVirtual, MD);
37653758

37663759
if (isa<CXXDestructorDecl>(MD)) {
3767-
IndicesMap[I.second] = MethodName + " [vector deleting]";
3760+
IndicesMap[I.second] = MethodName + " [scalar deleting]";
37683761
} else {
37693762
IndicesMap[I.second] = MethodName;
37703763
}
@@ -3880,7 +3873,7 @@ MicrosoftVTableContext::getMethodVFTableLocation(GlobalDecl GD) {
38803873
assert(hasVtableSlot(cast<CXXMethodDecl>(GD.getDecl())) &&
38813874
"Only use this method for virtual methods or dtors");
38823875
if (isa<CXXDestructorDecl>(GD.getDecl()))
3883-
assert(GD.getDtorType() == Dtor_VectorDeleting);
3876+
assert(GD.getDtorType() == Dtor_Deleting);
38843877

38853878
GD = GD.getCanonicalDecl();
38863879

clang/lib/CodeGen/CGCXX.cpp

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ bool CodeGenModule::TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) {
175175
// requires explicit comdat support in the IL.
176176
if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))
177177
return true;
178+
178179
// Create the alias with no name.
179180
auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0, Linkage, "",
180181
Aliasee, &getModule());
@@ -200,42 +201,6 @@ bool CodeGenModule::TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) {
200201
return false;
201202
}
202203

203-
/// Emit a definition as a global alias for another definition, unconditionally.
204-
void CodeGenModule::EmitDefinitionAsAlias(GlobalDecl AliasDecl,
205-
GlobalDecl TargetDecl) {
206-
207-
llvm::Type *AliasValueType = getTypes().GetFunctionType(AliasDecl);
208-
209-
StringRef MangledName = getMangledName(AliasDecl);
210-
llvm::GlobalValue *Entry = GetGlobalValue(MangledName);
211-
if (Entry && !Entry->isDeclaration())
212-
return;
213-
auto *Aliasee = cast<llvm::GlobalValue>(GetAddrOfGlobal(TargetDecl));
214-
215-
// Determine the linkage type for the alias.
216-
llvm::GlobalValue::LinkageTypes Linkage = getFunctionLinkage(AliasDecl);
217-
218-
// Create the alias with no name.
219-
auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0, Linkage, "",
220-
Aliasee, &getModule());
221-
// Destructors are always unnamed_addr.
222-
Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
223-
224-
if (Entry) {
225-
assert(Entry->getValueType() == AliasValueType &&
226-
Entry->getAddressSpace() == Alias->getAddressSpace() &&
227-
"declaration exists with different type");
228-
Alias->takeName(Entry);
229-
Entry->replaceAllUsesWith(Alias);
230-
Entry->eraseFromParent();
231-
} else {
232-
Alias->setName(MangledName);
233-
}
234-
235-
// Set any additional necessary attributes for the alias.
236-
SetCommonAttributes(AliasDecl, Alias);
237-
}
238-
239204
llvm::Function *CodeGenModule::codegenCXXStructor(GlobalDecl GD) {
240205
const CGFunctionInfo &FnInfo = getTypes().arrangeCXXStructorDeclaration(GD);
241206
auto *Fn = cast<llvm::Function>(

clang/lib/CodeGen/CGCXXABI.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -271,20 +271,6 @@ void CGCXXABI::ReadArrayCookie(CodeGenFunction &CGF, Address ptr,
271271
numElements = readArrayCookieImpl(CGF, allocAddr, cookieSize);
272272
}
273273

274-
void CGCXXABI::ReadArrayCookie(CodeGenFunction &CGF, Address ptr,
275-
QualType eltTy, llvm::Value *&numElements,
276-
llvm::Value *&allocPtr, CharUnits &cookieSize) {
277-
assert(eltTy.isDestructedType());
278-
279-
// Derive a char* in the same address space as the pointer.
280-
ptr = ptr.withElementType(CGF.Int8Ty);
281-
282-
cookieSize = getArrayCookieSizeImpl(eltTy);
283-
Address allocAddr = CGF.Builder.CreateConstInBoundsByteGEP(ptr, -cookieSize);
284-
allocPtr = allocAddr.emitRawPointer(CGF);
285-
numElements = readArrayCookieImpl(CGF, allocAddr, cookieSize);
286-
}
287-
288274
llvm::Value *CGCXXABI::readArrayCookieImpl(CodeGenFunction &CGF,
289275
Address ptr,
290276
CharUnits cookieSize) {

clang/lib/CodeGen/CGCXXABI.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ class CGCXXABI {
275275
virtual CatchTypeInfo getCatchAllTypeInfo();
276276

277277
virtual bool shouldTypeidBeNullChecked(QualType SrcRecordTy) = 0;
278-
virtual bool hasVectorDeletingDtors() = 0;
279278
virtual void EmitBadTypeidCall(CodeGenFunction &CGF) = 0;
280279
virtual llvm::Value *EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy,
281280
Address ThisPtr,
@@ -576,12 +575,6 @@ class CGCXXABI {
576575
QualType ElementType, llvm::Value *&NumElements,
577576
llvm::Value *&AllocPtr, CharUnits &CookieSize);
578577

579-
/// Reads the array cookie associated with the given pointer,
580-
/// that should have one.
581-
void ReadArrayCookie(CodeGenFunction &CGF, Address Ptr, QualType ElementType,
582-
llvm::Value *&NumElements, llvm::Value *&AllocPtr,
583-
CharUnits &CookieSize);
584-
585578
/// Return whether the given global decl needs a VTT parameter.
586579
virtual bool NeedsVTTParameter(GlobalDecl GD);
587580

clang/lib/CodeGen/CGClass.cpp

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,70 +1429,6 @@ static bool CanSkipVTablePointerInitialization(CodeGenFunction &CGF,
14291429
return true;
14301430
}
14311431

1432-
static void EmitConditionalArrayDtorCall(const CXXDestructorDecl *DD,
1433-
CodeGenFunction &CGF,
1434-
llvm::Value *ShouldDeleteCondition) {
1435-
Address ThisPtr = CGF.LoadCXXThisAddress();
1436-
llvm::BasicBlock *ScalarBB = CGF.createBasicBlock("dtor.scalar");
1437-
llvm::BasicBlock *callDeleteBB =
1438-
CGF.createBasicBlock("dtor.call_delete_after_array_destroy");
1439-
llvm::BasicBlock *VectorBB = CGF.createBasicBlock("dtor.vector");
1440-
auto *CondTy = cast<llvm::IntegerType>(ShouldDeleteCondition->getType());
1441-
llvm::Value *CheckTheBitForArrayDestroy = CGF.Builder.CreateAnd(
1442-
ShouldDeleteCondition, llvm::ConstantInt::get(CondTy, 2));
1443-
llvm::Value *ShouldDestroyArray =
1444-
CGF.Builder.CreateIsNull(CheckTheBitForArrayDestroy);
1445-
CGF.Builder.CreateCondBr(ShouldDestroyArray, ScalarBB, VectorBB);
1446-
1447-
CGF.EmitBlock(VectorBB);
1448-
1449-
llvm::Value *numElements = nullptr;
1450-
llvm::Value *allocatedPtr = nullptr;
1451-
CharUnits cookieSize;
1452-
QualType EltTy = DD->getThisType()->getPointeeType();
1453-
CGF.CGM.getCXXABI().ReadArrayCookie(CGF, ThisPtr, EltTy, numElements,
1454-
allocatedPtr, cookieSize);
1455-
1456-
// Destroy the elements.
1457-
QualType::DestructionKind dtorKind = EltTy.isDestructedType();
1458-
1459-
assert(dtorKind);
1460-
assert(numElements && "no element count for a type with a destructor!");
1461-
1462-
CharUnits elementSize = CGF.getContext().getTypeSizeInChars(EltTy);
1463-
CharUnits elementAlign =
1464-
ThisPtr.getAlignment().alignmentOfArrayElement(elementSize);
1465-
1466-
llvm::Value *arrayBegin = ThisPtr.emitRawPointer(CGF);
1467-
llvm::Value *arrayEnd = CGF.Builder.CreateInBoundsGEP(
1468-
ThisPtr.getElementType(), arrayBegin, numElements, "delete.end");
1469-
1470-
// We already checked that the array is not 0-length before entering vector
1471-
// deleting dtor.
1472-
CGF.emitArrayDestroy(arrayBegin, arrayEnd, EltTy, elementAlign,
1473-
CGF.getDestroyer(dtorKind),
1474-
/*checkZeroLength*/ false, CGF.needsEHCleanup(dtorKind));
1475-
1476-
llvm::BasicBlock *VectorBBCont = CGF.createBasicBlock("dtor.vector.cont");
1477-
CGF.EmitBlock(VectorBBCont);
1478-
1479-
llvm::Value *CheckTheBitForDeleteCall = CGF.Builder.CreateAnd(
1480-
ShouldDeleteCondition, llvm::ConstantInt::get(CondTy, 1));
1481-
1482-
llvm::Value *ShouldCallDelete =
1483-
CGF.Builder.CreateIsNull(CheckTheBitForDeleteCall);
1484-
CGF.Builder.CreateCondBr(ShouldCallDelete, CGF.ReturnBlock.getBlock(),
1485-
callDeleteBB);
1486-
CGF.EmitBlock(callDeleteBB);
1487-
const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(CGF.CurCodeDecl);
1488-
const CXXRecordDecl *ClassDecl = Dtor->getParent();
1489-
CGF.EmitDeleteCall(Dtor->getOperatorDelete(), allocatedPtr,
1490-
CGF.getContext().getTagDeclType(ClassDecl));
1491-
1492-
CGF.EmitBranchThroughCleanup(CGF.ReturnBlock);
1493-
CGF.EmitBlock(ScalarBB);
1494-
}
1495-
14961432
/// EmitDestructorBody - Emits the body of the current destructor.
14971433
void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) {
14981434
const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(CurGD.getDecl());
@@ -1522,9 +1458,7 @@ void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) {
15221458
// outside of the function-try-block, which means it's always
15231459
// possible to delegate the destructor body to the complete
15241460
// destructor. Do so.
1525-
if (DtorType == Dtor_Deleting || DtorType == Dtor_VectorDeleting) {
1526-
if (CXXStructorImplicitParamValue && DtorType == Dtor_VectorDeleting)
1527-
EmitConditionalArrayDtorCall(Dtor, *this, CXXStructorImplicitParamValue);
1461+
if (DtorType == Dtor_Deleting) {
15281462
RunCleanupsScope DtorEpilogue(*this);
15291463
EnterDtorCleanups(Dtor, Dtor_Deleting);
15301464
if (HaveInsertPoint()) {
@@ -1553,8 +1487,6 @@ void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) {
15531487
switch (DtorType) {
15541488
case Dtor_Comdat: llvm_unreachable("not expecting a COMDAT");
15551489
case Dtor_Deleting: llvm_unreachable("already handled deleting case");
1556-
case Dtor_VectorDeleting:
1557-
llvm_unreachable("already handled vector deleting case");
15581490

15591491
case Dtor_Complete:
15601492
assert((Body || getTarget().getCXXABI().isMicrosoft()) &&
@@ -1637,6 +1569,7 @@ namespace {
16371569
return CGF.EmitScalarExpr(ThisArg);
16381570
return CGF.LoadCXXThis();
16391571
}
1572+
16401573
/// Call the operator delete associated with the current destructor.
16411574
struct CallDtorDelete final : EHScopeStack::Cleanup {
16421575
CallDtorDelete() {}
@@ -1655,10 +1588,8 @@ namespace {
16551588
bool ReturnAfterDelete) {
16561589
llvm::BasicBlock *callDeleteBB = CGF.createBasicBlock("dtor.call_delete");
16571590
llvm::BasicBlock *continueBB = CGF.createBasicBlock("dtor.continue");
1658-
auto *CondTy = cast<llvm::IntegerType>(ShouldDeleteCondition->getType());
1659-
llvm::Value *CheckTheBit = CGF.Builder.CreateAnd(
1660-
ShouldDeleteCondition, llvm::ConstantInt::get(CondTy, 1));
1661-
llvm::Value *ShouldCallDelete = CGF.Builder.CreateIsNull(CheckTheBit);
1591+
llvm::Value *ShouldCallDelete
1592+
= CGF.Builder.CreateIsNull(ShouldDeleteCondition);
16621593
CGF.Builder.CreateCondBr(ShouldCallDelete, continueBB, callDeleteBB);
16631594

16641595
CGF.EmitBlock(callDeleteBB);

0 commit comments

Comments
 (0)