[clang] [CUDA][HIP] check dtor in deferred diag (PR #129117)
Artem Belevich via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 27 14:08:57 PST 2025
================
@@ -1798,6 +1798,62 @@ class DeferredDiagnosticsEmitter
Inherited::visitUsedDecl(Loc, D);
}
+ // Visitor member and parent dtors called by this dtor.
+ void VisitCalledDestructors(CXXDestructorDecl *DD) {
+ const CXXRecordDecl *RD = DD->getParent();
+
+ // Visit the dtors of all members
+ for (const FieldDecl *FD : RD->fields()) {
+ QualType FT = FD->getType();
+ if (const auto *RT = FT->getAs<RecordType>()) {
+ if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
+ if (ClassDecl->hasDefinition()) {
+ if (CXXDestructorDecl *MemberDtor = ClassDecl->getDestructor()) {
+ asImpl().visitUsedDecl(MemberDtor->getLocation(), MemberDtor);
+ }
+ }
+ }
+ }
+ }
+
+ // Also visit base class dtors
+ for (const auto &Base : RD->bases()) {
+ QualType BaseType = Base.getType();
+ if (const auto *RT = BaseType->getAs<RecordType>()) {
+ if (const auto *BaseDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
+ if (BaseDecl->hasDefinition()) {
+ if (CXXDestructorDecl *BaseDtor = BaseDecl->getDestructor()) {
+ asImpl().visitUsedDecl(BaseDtor->getLocation(), BaseDtor);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ void VisitDeclStmt(DeclStmt *DS) {
+ // Visit dtors called by variables that need destruction
+ for (auto *D : DS->decls()) {
+ if (auto *VD = dyn_cast<VarDecl>(D)) {
+ if (VD->isThisDeclarationADefinition() &&
+ VD->needsDestruction(S.Context)) {
+ QualType VT = VD->getType();
+ if (const auto *RT = VT->getAs<RecordType>()) {
+ if (const auto *ClassDecl =
+ dyn_cast<CXXRecordDecl>(RT->getDecl())) {
+ if (ClassDecl->hasDefinition()) {
+ if (CXXDestructorDecl *Dtor = ClassDecl->getDestructor()) {
+ asImpl().visitUsedDecl(Dtor->getLocation(), Dtor);
+ }
+ }
+ }
+ }
----------------
Artem-B wrote:
Ditto.
https://github.com/llvm/llvm-project/pull/129117
More information about the cfe-commits
mailing list