https://github.com/Backl1ght updated 
https://github.com/llvm/llvm-project/pull/143244

>From 51177d373e726b001bafaf6c2f8242b24136f608 Mon Sep 17 00:00:00 2001
From: Backl1ght <backlight....@gmail.com>
Date: Sat, 7 Jun 2025 16:15:04 +0800
Subject: [PATCH 1/4] add visit check

---
 clang/lib/Sema/SemaDeclCXX.cpp  | 14 ++++++--------
 clang/test/SemaCXX/gh102293.cpp | 17 +++++++++++++++++
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 39d4d49a0fe79..c6f248332de5e 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7172,7 +7172,10 @@ void Sema::CheckCompletedCXXClass(Scope *S, 
CXXRecordDecl *Record) {
     // "effectively constexpr" for better compatibility.
     // See https://github.com/llvm/llvm-project/issues/102293 for more info.
     if (isa<CXXDestructorDecl>(M)) {
-      auto Check = [](QualType T, auto &&Check) -> bool {
+      llvm::DenseSet<QualType> Visited;
+      auto Check = [&Visited](QualType T, auto &&Check) -> bool {
+        if (!Visited.insert(T).second)
+          return false;
         const CXXRecordDecl *RD =
             T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();
         if (!RD || !RD->isCompleteDefinition())
@@ -7181,16 +7184,11 @@ void Sema::CheckCompletedCXXClass(Scope *S, 
CXXRecordDecl *Record) {
         if (!RD->hasConstexprDestructor())
           return false;
 
-        QualType CanUnqualT = T.getCanonicalType().getUnqualifiedType();
         for (const CXXBaseSpecifier &B : RD->bases())
-          if (B.getType().getCanonicalType().getUnqualifiedType() !=
-                  CanUnqualT &&
-              !Check(B.getType(), Check))
+          if (!Check(B.getType(), Check))
             return false;
         for (const FieldDecl *FD : RD->fields())
-          if (FD->getType().getCanonicalType().getUnqualifiedType() !=
-                  CanUnqualT &&
-              !Check(FD->getType(), Check))
+          if (!Check(FD->getType(), Check))
             return false;
         return true;
       };
diff --git a/clang/test/SemaCXX/gh102293.cpp b/clang/test/SemaCXX/gh102293.cpp
index d4218cc13dcec..fe417e697841b 100644
--- a/clang/test/SemaCXX/gh102293.cpp
+++ b/clang/test/SemaCXX/gh102293.cpp
@@ -45,3 +45,20 @@ class quux : quux { // expected-error {{base class has 
incomplete type}} \
   virtual int c();
 };
 }
+
+// Ensure we don't get infinite recursion from the check, however. See GH141789
+namespace GH141789 {
+template <typename Ty>
+struct S {
+  Ty t; // expected-error {{field has incomplete type 'GH141789::X'}}
+};
+
+struct T {
+  ~T();
+};
+
+struct X { // expected-note {{definition of 'GH141789::X' is not complete 
until the closing '}'}}
+  S<X> next; // expected-note {{in instantiation of template class 
'GH141789::S<GH141789::X>' requested here}}
+  T m;
+};
+}

>From 37639512fc68a934466e4262bb251029e600071f Mon Sep 17 00:00:00 2001
From: Backl1ght <backlight....@gmail.com>
Date: Tue, 10 Jun 2025 21:42:01 +0800
Subject: [PATCH 2/4] add release note

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b5e6cf088a4b1..81dc6050c7510 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -694,6 +694,7 @@ Bug Fixes in This Version
 - Constant evaluation now correctly runs the destructor of a variable declared 
in
   the second clause of a C-style ``for`` loop. (#GH139818)
 - Fixed a bug with constexpr evaluation for structs containing unions in case 
of C++ modules. (#GH143168)
+- Fixed an infinite recursion about defaulted constexpr dtor. (#GH141789)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

>From be7d47f69978fa528a375f03ebc8b0eca29b027e Mon Sep 17 00:00:00 2001
From: Backl1ght <backlight....@gmail.com>
Date: Tue, 10 Jun 2025 22:06:14 +0800
Subject: [PATCH 3/4] use small dense set and store the canonical type

---
 clang/lib/Sema/SemaDeclCXX.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index c6f248332de5e..13b32fb514d1b 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7172,9 +7172,9 @@ void Sema::CheckCompletedCXXClass(Scope *S, CXXRecordDecl 
*Record) {
     // "effectively constexpr" for better compatibility.
     // See https://github.com/llvm/llvm-project/issues/102293 for more info.
     if (isa<CXXDestructorDecl>(M)) {
-      llvm::DenseSet<QualType> Visited;
+      llvm::SmallDenseSet<QualType> Visited;
       auto Check = [&Visited](QualType T, auto &&Check) -> bool {
-        if (!Visited.insert(T).second)
+        if (!Visited.insert(T.getCanonicalType().getUnqualifiedType()).second)
           return false;
         const CXXRecordDecl *RD =
             T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();

>From 7b47a29d40867f06e4b8033eba2b10d5f3604d02 Mon Sep 17 00:00:00 2001
From: Backl1ght <backlight....@gmail.com>
Date: Wed, 11 Jun 2025 18:50:54 +0800
Subject: [PATCH 4/4] address comments

---
 clang/docs/ReleaseNotes.rst    | 2 +-
 clang/lib/Sema/SemaDeclCXX.cpp | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 81dc6050c7510..02b7b942a7b9a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -694,7 +694,7 @@ Bug Fixes in This Version
 - Constant evaluation now correctly runs the destructor of a variable declared 
in
   the second clause of a C-style ``for`` loop. (#GH139818)
 - Fixed a bug with constexpr evaluation for structs containing unions in case 
of C++ modules. (#GH143168)
-- Fixed an infinite recursion about defaulted constexpr dtor. (#GH141789)
+- Fixed an infinite recursion when checking constexpr destructors. (#GH141789)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 13b32fb514d1b..750513fa1b4c4 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7174,7 +7174,7 @@ void Sema::CheckCompletedCXXClass(Scope *S, CXXRecordDecl 
*Record) {
     if (isa<CXXDestructorDecl>(M)) {
       llvm::SmallDenseSet<QualType> Visited;
       auto Check = [&Visited](QualType T, auto &&Check) -> bool {
-        if (!Visited.insert(T.getCanonicalType().getUnqualifiedType()).second)
+        if (!Visited.insert(T->getCanonicalTypeUnqualified()).second)
           return false;
         const CXXRecordDecl *RD =
             T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to