[llvm-branch-commits] [clang] release/23.x: [clang][Index][USR] Generate USRs for class-type non-type template arguments (#212356) (PR #212387)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Jul 27 18:32:38 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Patryk Stefanski (patrykstefanski)
<details>
<summary>Changes</summary>
Backport 912128312f026605bce4ff11ef8a37d56a1a03f8
---
Full diff: https://github.com/llvm/llvm-project/pull/212387.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.md (+2)
- (modified) clang/lib/UnifiedSymbolResolution/USRGeneration.cpp (+10)
- (added) clang/test/Index/USR/class-type-tpl-arg.cpp (+27)
``````````diff
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 2ea954b442678..501a421896636 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -835,6 +835,8 @@ latest release, please see the [Clang Web Site](https://clang.llvm.org) or the
- Fixed a case where function effect analysis (`nonblocking` etc.) did not visit a destructor invoked from a `delete` expression. (#GH184460)
- Clang now defines the GCC-compatible predefined macros `__WCHAR_MIN__`, `__WINT_MIN__`, and `__SIG_ATOMIC_MIN__`. (#GH199678)
- Fix a crash in addUnsizedArray due assert not verifying we have a Base before doing checks on it. (#GH44212)
+- Fixed USR generation for declarations whose signature mentions a class-type
+ non-type template parameter. (#GH212351)
#### Bug Fixes to Compiler Builtins
diff --git a/clang/lib/UnifiedSymbolResolution/USRGeneration.cpp b/clang/lib/UnifiedSymbolResolution/USRGeneration.cpp
index 5f689ad32159b..f167302aca74b 100644
--- a/clang/lib/UnifiedSymbolResolution/USRGeneration.cpp
+++ b/clang/lib/UnifiedSymbolResolution/USRGeneration.cpp
@@ -193,6 +193,7 @@ class USRGenerator : public ConstDeclVisitor<USRGenerator> {
void VisitTemplateArgument(const TemplateArgument &Arg);
void VisitMSGuidDecl(const MSGuidDecl *D);
+ void VisitTemplateParamObjectDecl(const TemplateParamObjectDecl *D);
/// Emit a Decl's name using NamedDecl::printName() and return true if
/// the decl had no name.
@@ -1212,6 +1213,15 @@ void USRGenerator::VisitMSGuidDecl(const MSGuidDecl *D) {
D->NamedDecl::printName(Out);
}
+void USRGenerator::VisitTemplateParamObjectDecl(
+ const TemplateParamObjectDecl *D) {
+ Out << "@TPO@";
+ VisitType(D->getType());
+ ODRHash Hash{};
+ Hash.AddStructuralValue(D->getValue());
+ Out << Hash.CalculateHash();
+}
+
//===----------------------------------------------------------------------===//
// USR generation functions.
//===----------------------------------------------------------------------===//
diff --git a/clang/test/Index/USR/class-type-tpl-arg.cpp b/clang/test/Index/USR/class-type-tpl-arg.cpp
new file mode 100644
index 0000000000000..2ef0d02ece14b
--- /dev/null
+++ b/clang/test/Index/USR/class-type-tpl-arg.cpp
@@ -0,0 +1,27 @@
+// RUN: c-index-test core -print-source-symbols -- -std=c++20 %s | FileCheck %s
+
+// Check USRs of template specializations with class-type NTTP values.
+
+struct R {
+ int a;
+};
+
+template <R> struct L {};
+
+// Equal parameter object values must produce equal USRs, and distinct values
+// must produce distinct ones.
+
+// CHECK: | f | c:@F at f#$@S at L>#@TPO at 1$@S at R[[#HASH0:]]#
+void f(L<R{0}>);
+
+// CHECK: | g | c:@F at g#$@S at L>#@TPO at 1$@S at R[[#HASH0]]#
+void g(L<R{0}>);
+
+// CHECK: | h | c:@F at h#$@S at L>#@TPO at 1$@S at R[[#HASH1:]]#
+// CHECK-NOT: | h | c:@F at h#$@S at L>#@TPO at 1$@S at R[[#HASH0]]#
+void h(L<R{1}>);
+
+struct S {
+ // CHECK: | set | c:@S at S@F at set#&&$@S at L>#@TPO at 1$@S at R[[#HASH0]]#
+ void set(L<R{0}> &&);
+};
``````````
</details>
https://github.com/llvm/llvm-project/pull/212387
More information about the llvm-branch-commits
mailing list