Skip to content

release/22.x: [Clang] Profile the NNS of UnresolvedUsingType and CXXThisType correctly in concept hashing (#199617)#200988

Merged
dyung merged 1 commit into
llvm:release/22.xfrom
llvmbot:issue199617
Jun 2, 2026
Merged

release/22.x: [Clang] Profile the NNS of UnresolvedUsingType and CXXThisType correctly in concept hashing (#199617)#200988
dyung merged 1 commit into
llvm:release/22.xfrom
llvmbot:issue199617

Conversation

@llvmbot
Copy link
Copy Markdown
Member

@llvmbot llvmbot commented Jun 2, 2026

Backport 06ffb65

Requested by: @zyn0217

@llvmbot
Copy link
Copy Markdown
Member Author

llvmbot commented Jun 2, 2026

@cor3ntin What do you think about merging this PR to the release branch?

@llvmbot llvmbot requested a review from cor3ntin June 2, 2026 02:35
@llvmorg-github-actions llvmorg-github-actions Bot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jun 2, 2026
@llvmorg-github-actions
Copy link
Copy Markdown

@llvm/pr-subscribers-clang

Author: llvmbot

Changes

Backport 06ffb65

Requested by: @zyn0217


Full diff: https://github.com/llvm/llvm-project/pull/200988.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaConcept.cpp (+14)
  • (modified) clang/test/SemaTemplate/concepts-using-decl.cpp (+98)
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index fdaad31233b29..9ffecaca04a18 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -381,6 +381,10 @@ class HashParameterMapping : public RecursiveASTVisitor<HashParameterMapping> {
     return true;
   }
 
+  bool TraverseCXXThisExpr(CXXThisExpr *E) {
+    return inherited::TraverseType(E->getType());
+  }
+
   bool TraverseTypeLoc(TypeLoc TL, bool TraverseQualifier = true) {
     // We don't care about TypeLocs. So traverse Types instead.
     return TraverseType(TL.getType().getCanonicalType(), TraverseQualifier);
@@ -394,6 +398,16 @@ class HashParameterMapping : public RecursiveASTVisitor<HashParameterMapping> {
     return true;
   }
 
+  bool TraverseUnresolvedUsingType(UnresolvedUsingType *T,
+                                   bool TraverseQualifier) {
+    // Sometimes the written type doesn't contain a qualifier which contains
+    // necessary template arguments, whereas the declaration does.
+    if (NestedNameSpecifier NNS = T->getDecl()->getQualifier();
+        TraverseQualifier && NNS)
+      return inherited::TraverseNestedNameSpecifier(NNS);
+    return inherited::TraverseUnresolvedUsingType(T, TraverseQualifier);
+  }
+
   bool TraverseInjectedClassNameType(InjectedClassNameType *T,
                                      bool TraverseQualifier) {
     return TraverseTemplateArguments(T->getTemplateArgs(SemaRef.Context));
diff --git a/clang/test/SemaTemplate/concepts-using-decl.cpp b/clang/test/SemaTemplate/concepts-using-decl.cpp
index 41f7b6d2f8faa..5ccec3cee9402 100644
--- a/clang/test/SemaTemplate/concepts-using-decl.cpp
+++ b/clang/test/SemaTemplate/concepts-using-decl.cpp
@@ -197,3 +197,101 @@ struct child : base<int> {
 };
 
 }
+
+namespace GH198663 {
+
+template <class T>
+concept HasIsTransparent = requires { typename T::is_transparent; };
+
+template <class K, class V, class Compare>
+struct FlatMapBase {
+    using key_compare = Compare;
+};
+
+template <class K, class V, class Compare>
+struct FlatMap : FlatMapBase<K, V, Compare> {
+    using Base = FlatMapBase<K, V, Compare>;
+
+    using typename Base::key_compare;
+
+    void at(const K&) {}
+    void at(const K&) const {}
+    template <class Other>
+    void at(const Other&)
+        requires HasIsTransparent<key_compare>
+    {}
+    template <class Other>
+    void at(const Other&) const
+        requires HasIsTransparent<key_compare>
+    {}
+};
+
+template <class T>
+struct Transparent {
+    T t;
+};
+
+struct TransparentComparator {
+    using is_transparent = void;
+
+    template <class T>
+    bool operator()(const T&, const Transparent<T>&) const;
+
+    template <class T>
+    bool operator()(const Transparent<T>&, const T& t) const;
+
+    template <class T>
+    bool operator()(const T&, const T&) const;
+};
+
+struct NonTransparentComparator {
+    template <class T>
+    bool operator()(const T&, const Transparent<T>&) const;
+
+    template <class T>
+    bool operator()(const Transparent<T>&, const T&) const;
+
+    template <class T>
+    bool operator()(const T&, const T&) const;
+};
+
+template <class M>
+concept CanAt = requires(M m, Transparent<int> k) { m.at(k); };
+
+using TransparentMap = FlatMap<int, double, TransparentComparator>;
+using NonTransparentMap = FlatMap<int, double, NonTransparentComparator>;
+
+static_assert(CanAt<TransparentMap>);
+
+static_assert(!CanAt<NonTransparentMap>);
+
+}
+
+namespace GH198663_2 {
+
+template<typename T>
+auto mv(T& t) -> T&&;
+
+template<typename S, typename T>
+concept does_foo = requires(S s) {
+	s.template foo<T>();
+};
+
+template<typename S>
+struct type {
+	S member;
+	template<typename T>
+	auto foo() -> T requires does_foo<decltype(mv(member)), T>;
+};
+
+struct returns_int {
+	template<typename T>
+	auto foo() -> T;
+};
+
+struct nothing {};
+
+static_assert(does_foo<type<returns_int>&, int>);
+static_assert(not does_foo<type<nothing>&, int>);
+
+}

@c-rhodes c-rhodes moved this from Needs Triage to Needs Review in LLVM Release Status Jun 2, 2026
@github-project-automation github-project-automation Bot moved this from Needs Review to Needs Merge in LLVM Release Status Jun 2, 2026
…tly in concept hashing (llvm#199617)

They were sometimes incorrect because the written type doesn't contain
an NNS which contains template parameters we're interested in.

No release note because the bug broke MS STL and I want to backport it
to the last 22.x release

Fixes llvm#198663

(cherry picked from commit 06ffb65)
@dyung dyung merged commit b65aa9b into llvm:release/22.x Jun 2, 2026
14 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Merge to Done in LLVM Release Status Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

Development

Successfully merging this pull request may close these issues.

5 participants