Skip to content

Commit 001d1bc

Browse files
committed
Make destructor referencing methods static
1 parent d7b5cd2 commit 001d1bc

File tree

2 files changed

+100
-103
lines changed

2 files changed

+100
-103
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5445,9 +5445,6 @@ class Sema final : public SemaBase {
54455445
void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
54465446
CXXRecordDecl *Record);
54475447

5448-
void MarkBaseDestructorsReferenced(SourceLocation Loc, CXXRecordDecl *Record);
5449-
void MarkFieldDestructorReferenced(SourceLocation Loc, FieldDecl *Field);
5450-
54515448
/// Mark destructors of virtual bases of this class referenced. In the Itanium
54525449
/// C++ ABI, this is done when emitting a destructor for any non-abstract
54535450
/// class. In the Microsoft C++ ABI, this is done any time a class's

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 100 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -5289,6 +5289,102 @@ Sema::SetDelegatingInitializer(CXXConstructorDecl *Constructor,
52895289
return false;
52905290
}
52915291

5292+
static void MarkFieldDestructorReferenced(Sema &S, SourceLocation Location,
5293+
FieldDecl *Field) {
5294+
if (Field->isInvalidDecl())
5295+
return;
5296+
5297+
// Don't destroy incomplete or zero-length arrays.
5298+
if (isIncompleteOrZeroLengthArrayType(S.Context, Field->getType()))
5299+
return;
5300+
5301+
QualType FieldType = S.Context.getBaseElementType(Field->getType());
5302+
5303+
const RecordType *RT = FieldType->getAs<RecordType>();
5304+
if (!RT)
5305+
return;
5306+
5307+
CXXRecordDecl *FieldClassDecl = cast<CXXRecordDecl>(RT->getDecl());
5308+
if (FieldClassDecl->isInvalidDecl())
5309+
return;
5310+
if (FieldClassDecl->hasIrrelevantDestructor())
5311+
return;
5312+
// The destructor for an implicit anonymous union member is never invoked.
5313+
if (FieldClassDecl->isUnion() && FieldClassDecl->isAnonymousStructOrUnion())
5314+
return;
5315+
5316+
CXXDestructorDecl *Dtor = S.LookupDestructor(FieldClassDecl);
5317+
// Dtor might still be missing, e.g because it's invalid.
5318+
if (!Dtor)
5319+
return;
5320+
S.CheckDestructorAccess(Field->getLocation(), Dtor,
5321+
S.PDiag(diag::err_access_dtor_field)
5322+
<< Field->getDeclName() << FieldType);
5323+
5324+
S.MarkFunctionReferenced(Location, Dtor);
5325+
S.DiagnoseUseOfDecl(Dtor, Location);
5326+
}
5327+
5328+
static void MarkBaseDestructorsReferenced(Sema &S, SourceLocation Location,
5329+
CXXRecordDecl *ClassDecl) {
5330+
if (ClassDecl->isDependentContext())
5331+
return;
5332+
5333+
// We only potentially invoke the destructors of potentially constructed
5334+
// subobjects.
5335+
bool VisitVirtualBases = !ClassDecl->isAbstract();
5336+
5337+
// If the destructor exists and has already been marked used in the MS ABI,
5338+
// then virtual base destructors have already been checked and marked used.
5339+
// Skip checking them again to avoid duplicate diagnostics.
5340+
if (S.Context.getTargetInfo().getCXXABI().isMicrosoft()) {
5341+
CXXDestructorDecl *Dtor = ClassDecl->getDestructor();
5342+
if (Dtor && Dtor->isUsed())
5343+
VisitVirtualBases = false;
5344+
}
5345+
5346+
llvm::SmallPtrSet<const RecordType *, 8> DirectVirtualBases;
5347+
5348+
// Bases.
5349+
for (const auto &Base : ClassDecl->bases()) {
5350+
const RecordType *RT = Base.getType()->getAs<RecordType>();
5351+
if (!RT)
5352+
continue;
5353+
5354+
// Remember direct virtual bases.
5355+
if (Base.isVirtual()) {
5356+
if (!VisitVirtualBases)
5357+
continue;
5358+
DirectVirtualBases.insert(RT);
5359+
}
5360+
5361+
CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(RT->getDecl());
5362+
// If our base class is invalid, we probably can't get its dtor anyway.
5363+
if (BaseClassDecl->isInvalidDecl())
5364+
continue;
5365+
if (BaseClassDecl->hasIrrelevantDestructor())
5366+
continue;
5367+
5368+
CXXDestructorDecl *Dtor = S.LookupDestructor(BaseClassDecl);
5369+
// Dtor might still be missing, e.g because it's invalid.
5370+
if (!Dtor)
5371+
continue;
5372+
5373+
// FIXME: caret should be on the start of the class name
5374+
S.CheckDestructorAccess(Base.getBeginLoc(), Dtor,
5375+
S.PDiag(diag::err_access_dtor_base)
5376+
<< Base.getType() << Base.getSourceRange(),
5377+
S.Context.getTypeDeclType(ClassDecl));
5378+
5379+
S.MarkFunctionReferenced(Location, Dtor);
5380+
S.DiagnoseUseOfDecl(Dtor, Location);
5381+
}
5382+
5383+
if (VisitVirtualBases)
5384+
S.MarkVirtualBaseDestructorsReferenced(Location, ClassDecl,
5385+
&DirectVirtualBases);
5386+
}
5387+
52925388
bool Sema::SetCtorInitializers(CXXConstructorDecl *Constructor, bool AnyErrors,
52935389
ArrayRef<CXXCtorInitializer *> Initializers) {
52945390
if (Constructor->isDependentContext()) {
@@ -5471,10 +5567,10 @@ bool Sema::SetCtorInitializers(CXXConstructorDecl *Constructor, bool AnyErrors,
54715567
// potentially constructed subobject of class type is potentially
54725568
// invoked
54735569
// ([class.dtor]).
5474-
MarkFieldDestructorReferenced(Location, Field);
5570+
MarkFieldDestructorReferenced(*this, Location, Field);
54755571
}
54765572

5477-
MarkBaseDestructorsReferenced(Location, Constructor->getParent());
5573+
MarkBaseDestructorsReferenced(*this, Location, Constructor->getParent());
54785574
}
54795575

54805576
return HadError;
@@ -5779,102 +5875,6 @@ void Sema::ActOnMemInitializers(Decl *ConstructorDecl,
57795875
DiagnoseUninitializedFields(*this, Constructor);
57805876
}
57815877

5782-
void Sema::MarkFieldDestructorReferenced(SourceLocation Location,
5783-
FieldDecl *Field) {
5784-
if (Field->isInvalidDecl())
5785-
return;
5786-
5787-
// Don't destroy incomplete or zero-length arrays.
5788-
if (isIncompleteOrZeroLengthArrayType(Context, Field->getType()))
5789-
return;
5790-
5791-
QualType FieldType = Context.getBaseElementType(Field->getType());
5792-
5793-
const RecordType *RT = FieldType->getAs<RecordType>();
5794-
if (!RT)
5795-
return;
5796-
5797-
CXXRecordDecl *FieldClassDecl = cast<CXXRecordDecl>(RT->getDecl());
5798-
if (FieldClassDecl->isInvalidDecl())
5799-
return;
5800-
if (FieldClassDecl->hasIrrelevantDestructor())
5801-
return;
5802-
// The destructor for an implicit anonymous union member is never invoked.
5803-
if (FieldClassDecl->isUnion() && FieldClassDecl->isAnonymousStructOrUnion())
5804-
return;
5805-
5806-
CXXDestructorDecl *Dtor = LookupDestructor(FieldClassDecl);
5807-
// Dtor might still be missing, e.g because it's invalid.
5808-
if (!Dtor)
5809-
return;
5810-
CheckDestructorAccess(Field->getLocation(), Dtor,
5811-
PDiag(diag::err_access_dtor_field)
5812-
<< Field->getDeclName() << FieldType);
5813-
5814-
MarkFunctionReferenced(Location, Dtor);
5815-
DiagnoseUseOfDecl(Dtor, Location);
5816-
}
5817-
5818-
void Sema::MarkBaseDestructorsReferenced(SourceLocation Location,
5819-
CXXRecordDecl *ClassDecl) {
5820-
if (ClassDecl->isDependentContext())
5821-
return;
5822-
5823-
// We only potentially invoke the destructors of potentially constructed
5824-
// subobjects.
5825-
bool VisitVirtualBases = !ClassDecl->isAbstract();
5826-
5827-
// If the destructor exists and has already been marked used in the MS ABI,
5828-
// then virtual base destructors have already been checked and marked used.
5829-
// Skip checking them again to avoid duplicate diagnostics.
5830-
if (Context.getTargetInfo().getCXXABI().isMicrosoft()) {
5831-
CXXDestructorDecl *Dtor = ClassDecl->getDestructor();
5832-
if (Dtor && Dtor->isUsed())
5833-
VisitVirtualBases = false;
5834-
}
5835-
5836-
llvm::SmallPtrSet<const RecordType *, 8> DirectVirtualBases;
5837-
5838-
// Bases.
5839-
for (const auto &Base : ClassDecl->bases()) {
5840-
const RecordType *RT = Base.getType()->getAs<RecordType>();
5841-
if (!RT)
5842-
continue;
5843-
5844-
// Remember direct virtual bases.
5845-
if (Base.isVirtual()) {
5846-
if (!VisitVirtualBases)
5847-
continue;
5848-
DirectVirtualBases.insert(RT);
5849-
}
5850-
5851-
CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(RT->getDecl());
5852-
// If our base class is invalid, we probably can't get its dtor anyway.
5853-
if (BaseClassDecl->isInvalidDecl())
5854-
continue;
5855-
if (BaseClassDecl->hasIrrelevantDestructor())
5856-
continue;
5857-
5858-
CXXDestructorDecl *Dtor = LookupDestructor(BaseClassDecl);
5859-
// Dtor might still be missing, e.g because it's invalid.
5860-
if (!Dtor)
5861-
continue;
5862-
5863-
// FIXME: caret should be on the start of the class name
5864-
CheckDestructorAccess(Base.getBeginLoc(), Dtor,
5865-
PDiag(diag::err_access_dtor_base)
5866-
<< Base.getType() << Base.getSourceRange(),
5867-
Context.getTypeDeclType(ClassDecl));
5868-
5869-
MarkFunctionReferenced(Location, Dtor);
5870-
DiagnoseUseOfDecl(Dtor, Location);
5871-
}
5872-
5873-
if (VisitVirtualBases)
5874-
MarkVirtualBaseDestructorsReferenced(Location, ClassDecl,
5875-
&DirectVirtualBases);
5876-
}
5877-
58785878
void Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
58795879
CXXRecordDecl *ClassDecl) {
58805880
// Ignore dependent contexts. Also ignore unions, since their members never
@@ -5889,10 +5889,10 @@ void Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
58895889

58905890
// Non-static data members.
58915891
for (auto *Field : ClassDecl->fields()) {
5892-
MarkFieldDestructorReferenced(Location, Field);
5892+
MarkFieldDestructorReferenced(*this, Location, Field);
58935893
}
58945894

5895-
MarkBaseDestructorsReferenced(Location, ClassDecl);
5895+
MarkBaseDestructorsReferenced(*this, Location, ClassDecl);
58965896
}
58975897

58985898
void Sema::MarkVirtualBaseDestructorsReferenced(

0 commit comments

Comments
 (0)