release/22.x: [Clang] Profile the NNS of UnresolvedUsingType and CXXThisType correctly in concept hashing (#199617)#200988
Merged
Merged
Conversation
Member
Author
|
@cor3ntin What do you think about merging this PR to the release branch? |
|
@llvm/pr-subscribers-clang Author: llvmbot ChangesBackport 06ffb65 Requested by: @zyn0217 2 Files Affected:
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>);
+
+}
|
cor3ntin
approved these changes
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport 06ffb65
Requested by: @zyn0217