Skip to content

Commit 4f368fe

Browse files
committed
Revert "[MS][clang] Make sure vector deleting dtor calls correct operator delete (llvm#133950)"
This reverts commit 8a691cc.
1 parent 29e534d commit 4f368fe

File tree

7 files changed

+7
-50
lines changed

7 files changed

+7
-50
lines changed

clang/include/clang/AST/DeclCXX.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,7 +2852,6 @@ class CXXDestructorDecl : public CXXMethodDecl {
28522852
// FIXME: Don't allocate storage for these except in the first declaration
28532853
// of a virtual destructor.
28542854
FunctionDecl *OperatorDelete = nullptr;
2855-
FunctionDecl *OperatorArrayDelete = nullptr;
28562855
Expr *OperatorDeleteThisArg = nullptr;
28572856

28582857
CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
@@ -2878,16 +2877,11 @@ class CXXDestructorDecl : public CXXMethodDecl {
28782877
static CXXDestructorDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
28792878

28802879
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg);
2881-
void setOperatorArrayDelete(FunctionDecl *OD, Expr *ThisArg);
28822880

28832881
const FunctionDecl *getOperatorDelete() const {
28842882
return getCanonicalDecl()->OperatorDelete;
28852883
}
28862884

2887-
const FunctionDecl *getArrayOperatorDelete() const {
2888-
return getCanonicalDecl()->OperatorArrayDelete;
2889-
}
2890-
28912885
Expr *getOperatorDeleteThisArg() const {
28922886
return getCanonicalDecl()->OperatorDeleteThisArg;
28932887
}

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8366,7 +8366,6 @@ class Sema final : public SemaBase {
83668366
DeclarationName Name);
83678367
FunctionDecl *FindDeallocationFunctionForDestructor(SourceLocation StartLoc,
83688368
CXXRecordDecl *RD,
8369-
DeclarationName Name,
83708369
bool Diagnose = true);
83718370

83728371
/// ActOnCXXDelete - Parsed a C++ 'delete' expression (C++ 5.3.5), as in:

clang/lib/AST/DeclCXX.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3064,13 +3064,6 @@ void CXXDestructorDecl::setOperatorDelete(FunctionDecl *OD, Expr *ThisArg) {
30643064
}
30653065
}
30663066

3067-
void CXXDestructorDecl::setOperatorArrayDelete(FunctionDecl *OD,
3068-
Expr *ThisArg) {
3069-
auto *First = cast<CXXDestructorDecl>(getFirstDecl());
3070-
if (OD && !First->OperatorArrayDelete)
3071-
First->OperatorArrayDelete = OD;
3072-
}
3073-
30743067
bool CXXDestructorDecl::isCalledByDelete(const FunctionDecl *OpDel) const {
30753068
// C++20 [expr.delete]p6: If the value of the operand of the delete-
30763069
// expression is not a null pointer value and the selected deallocation

clang/lib/CodeGen/CGClass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,7 @@ static void EmitConditionalArrayDtorCall(const CXXDestructorDecl *DD,
14861486
CGF.EmitBlock(callDeleteBB);
14871487
const CXXDestructorDecl *Dtor = cast<CXXDestructorDecl>(CGF.CurCodeDecl);
14881488
const CXXRecordDecl *ClassDecl = Dtor->getParent();
1489-
CGF.EmitDeleteCall(Dtor->getArrayOperatorDelete(), allocatedPtr,
1489+
CGF.EmitDeleteCall(Dtor->getOperatorDelete(), allocatedPtr,
14901490
CGF.getContext().getTagDeclType(ClassDecl));
14911491

14921492
CGF.EmitBranchThroughCleanup(CGF.ReturnBlock);

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11058,11 +11058,9 @@ bool Sema::CheckDestructor(CXXDestructorDecl *Destructor) {
1105811058
else
1105911059
Loc = RD->getLocation();
1106011060

11061-
DeclarationName Name =
11062-
Context.DeclarationNames.getCXXOperatorName(OO_Delete);
1106311061
// If we have a virtual destructor, look up the deallocation function
1106411062
if (FunctionDecl *OperatorDelete =
11065-
FindDeallocationFunctionForDestructor(Loc, RD, Name)) {
11063+
FindDeallocationFunctionForDestructor(Loc, RD)) {
1106611064
Expr *ThisArg = nullptr;
1106711065

1106811066
// If the notional 'delete this' expression requires a non-trivial
@@ -11097,15 +11095,6 @@ bool Sema::CheckDestructor(CXXDestructorDecl *Destructor) {
1109711095
DiagnoseUseOfDecl(OperatorDelete, Loc);
1109811096
MarkFunctionReferenced(Loc, OperatorDelete);
1109911097
Destructor->setOperatorDelete(OperatorDelete, ThisArg);
11100-
// Lookup delete[] too in case we have to emit a vector deleting dtor;
11101-
DeclarationName VDeleteName =
11102-
Context.DeclarationNames.getCXXOperatorName(OO_Array_Delete);
11103-
FunctionDecl *ArrOperatorDelete =
11104-
FindDeallocationFunctionForDestructor(Loc, RD, VDeleteName);
11105-
// delete[] in the TU will make sure the operator is referenced and its
11106-
// uses diagnosed, otherwise vector deleting dtor won't be called anyway,
11107-
// so just record it in the destructor.
11108-
Destructor->setOperatorArrayDelete(ArrOperatorDelete, ThisArg);
1110911098
}
1111011099
}
1111111100

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3576,8 +3576,8 @@ Sema::FindUsualDeallocationFunction(SourceLocation StartLoc,
35763576

35773577
FunctionDecl *Sema::FindDeallocationFunctionForDestructor(SourceLocation Loc,
35783578
CXXRecordDecl *RD,
3579-
DeclarationName Name,
35803579
bool Diagnose) {
3580+
DeclarationName Name = Context.DeclarationNames.getCXXOperatorName(OO_Delete);
35813581

35823582
FunctionDecl *OperatorDelete = nullptr;
35833583
QualType DeallocType = Context.getRecordType(RD);
@@ -3591,7 +3591,8 @@ FunctionDecl *Sema::FindDeallocationFunctionForDestructor(SourceLocation Loc,
35913591
if (OperatorDelete)
35923592
return OperatorDelete;
35933593

3594-
// If there's no class-specific operator delete, look up the global delete.
3594+
// If there's no class-specific operator delete, look up the global
3595+
// non-array delete.
35953596
QualType RecordType = Context.getRecordType(RD);
35963597
IDP.PassAlignment =
35973598
alignedAllocationModeFromBool(hasNewExtendedAlignment(*this, RecordType));

clang/test/CodeGenCXX/microsoft-vector-deleting-dtors.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ struct JustAWeirdBird {
2828
}
2929
};
3030

31-
int i = 0;
32-
struct HasOperatorDelete : public Bird{
33-
~HasOperatorDelete() { }
34-
void operator delete(void *p) { i-=2; }
35-
void operator delete[](void *p) { i--; }
36-
};
37-
3831
// Vector deleting dtor for Bird is an alias because no new Bird[] expressions
3932
// in the TU.
4033
// X64: @"??_EBird@@UEAAPEAXI@Z" = weak dso_local unnamed_addr alias ptr (ptr, i32), ptr @"??_GBird@@UEAAPEAXI@Z"
@@ -60,9 +53,6 @@ void bar() {
6053

6154
JustAWeirdBird B;
6255
B.doSmth(38);
63-
64-
Bird *p = new HasOperatorDelete[2];
65-
dealloc(p);
6656
}
6757

6858
// CHECK-LABEL: define dso_local void @{{.*}}dealloc{{.*}}(
@@ -139,8 +129,8 @@ void bar() {
139129
// CHECK-NEXT: %[[ISFIRSTBITZERO:.*]] = icmp eq i32 %[[FIRSTBIT]], 0
140130
// CHECK-NEXT: br i1 %[[ISFIRSTBITZERO]], label %dtor.continue, label %dtor.call_delete_after_array_destroy
141131
// CHECK: dtor.call_delete_after_array_destroy:
142-
// X64-NEXT: call void @"??_V@YAXPEAX_K@Z"(ptr noundef %[[COOKIEGEP]], i64 noundef 8)
143-
// X86-NEXT: call void @"??_V@YAXPAXI@Z"(ptr noundef %[[COOKIEGEP]], i32 noundef 4)
132+
// X64-NEXT: call void @"??3@YAXPEAX_K@Z"(ptr noundef %[[COOKIEGEP]], i64 noundef 8)
133+
// X86-NEXT: call void @"??3@YAXPAXI@Z"(ptr noundef %[[COOKIEGEP]], i32 noundef 4)
144134
// CHECK-NEXT: br label %dtor.continue
145135
// CHECK: dtor.scalar:
146136
// X64-NEXT: call void @"??1Parrot@@UEAA@XZ"(ptr noundef nonnull align 8 dereferenceable(8) %[[LTHIS]])
@@ -160,12 +150,3 @@ void bar() {
160150
// X64-SAME: ptr noundef nonnull align 8 dereferenceable(8) %this, i32 noundef %should_call_delete)
161151
// X86: define weak dso_local x86_thiscallcc noundef ptr @"??_EJustAWeirdBird@@UAEPAXI@Z"(
162152
// X86-SAME: ptr noundef nonnull align 4 dereferenceable(4) %this, i32 noundef %should_call_delete) unnamed_addr
163-
164-
// X64-LABEL: define weak dso_local noundef ptr @"??_EHasOperatorDelete@@UEAAPEAXI@Z"
165-
// X86-LABEL: define weak dso_local x86_thiscallcc noundef ptr @"??_EHasOperatorDelete@@UAEPAXI@Z"
166-
// CHECK: dtor.call_delete_after_array_destroy:
167-
// X64-NEXT: call void @"??_VHasOperatorDelete@@SAXPEAX@Z"
168-
// X86-NEXT: call void @"??_VHasOperatorDelete@@SAXPAX@Z"
169-
// CHECK: dtor.call_delete:
170-
// X64-NEXT: call void @"??3HasOperatorDelete@@SAXPEAX@Z"
171-
// X86-NEXT: call void @"??3HasOperatorDelete@@SAXPAX@Z"

0 commit comments

Comments
 (0)