[clang] b311ab0 - [Clang] Fix canonicalization of pack indexing types (#123209)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 16 08:50:34 PST 2025
Author: cor3ntin
Date: 2025-01-16T17:50:31+01:00
New Revision: b311ab0f89980105a11f7bff5c6e7dd95d5c86fa
URL: https://github.com/llvm/llvm-project/commit/b311ab0f89980105a11f7bff5c6e7dd95d5c86fa
DIFF: https://github.com/llvm/llvm-project/commit/b311ab0f89980105a11f7bff5c6e7dd95d5c86fa.diff
LOG: [Clang] Fix canonicalization of pack indexing types (#123209)
A canonicalized pack indexing should refer to a canonicalized pattern
Fixes #123033
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/AST/ASTContext.cpp
clang/test/SemaCXX/cxx2c-pack-indexing.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f6be841035db18..14fe920985d6a9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -952,6 +952,8 @@ Bug Fixes to C++ Support
- Fixed a crash when __PRETTY_FUNCTION__ or __FUNCSIG__ (clang-cl) appears in the trailing return type of the lambda (#GH121274)
- Fixed a crash caused by the incorrect construction of template arguments for CTAD alias guides when type
constraints are applied. (#GH122134)
+- Fixed canonicalization of pack indexing types - Clang did not always recognized identical pack indexing. (#GH123033)
+
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index be1dd29d462788..d0ce4c511aedd0 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -6248,7 +6248,8 @@ QualType ASTContext::getPackIndexingType(QualType Pattern, Expr *IndexExpr,
Canonical = getCanonicalType(Expansions[Index]);
} else {
llvm::FoldingSetNodeID ID;
- PackIndexingType::Profile(ID, *this, Pattern, IndexExpr, FullySubstituted);
+ PackIndexingType::Profile(ID, *this, Pattern.getCanonicalType(), IndexExpr,
+ FullySubstituted);
void *InsertPos = nullptr;
PackIndexingType *Canon =
DependentPackIndexingTypes.FindNodeOrInsertPos(ID, InsertPos);
@@ -6256,8 +6257,9 @@ QualType ASTContext::getPackIndexingType(QualType Pattern, Expr *IndexExpr,
void *Mem = Allocate(
PackIndexingType::totalSizeToAlloc<QualType>(Expansions.size()),
TypeAlignment);
- Canon = new (Mem) PackIndexingType(*this, QualType(), Pattern, IndexExpr,
- FullySubstituted, Expansions);
+ Canon = new (Mem)
+ PackIndexingType(*this, QualType(), Pattern.getCanonicalType(),
+ IndexExpr, FullySubstituted, Expansions);
DependentPackIndexingTypes.InsertNode(Canon, InsertPos);
}
Canonical = QualType(Canon, 0);
diff --git a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
index 58b642d2735b6e..202a819655217b 100644
--- a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
+++ b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
@@ -321,3 +321,26 @@ namespace GH121242 {
(void)z<X{}>;
}
} // namespace GH121242
+
+namespace GH123033 {
+ template <class... Types>
+ requires __is_same_as(Types...[0], int)
+ void print(double d);
+
+ template <class... Types>
+ requires __is_same_as(Types...[0], int)
+ void print(double d);
+
+ template <class... Types>
+ Types...[0] convert(double d);
+
+ template <class... Types>
+ Types...[0] convert(double d) {
+ return static_cast<Types...[0]>(d);
+ }
+
+ void f() {
+ print<int, int>(12.34);
+ convert<int, int>(12.34);
+ }
+}
More information about the cfe-commits
mailing list