[Clang][Index] Add support for dependent class scope explicit specializations of function templates to USRGenerator#98027
Merged
sdkrystian merged 1 commit intollvm:mainfrom Jul 8, 2024
Conversation
…izations of function templates to USRGenerator
Member
|
@llvm/pr-subscribers-clang Author: Krystian Stasiowski (sdkrystian) ChangesGiven the following: template<typename T>
struct A
{
void f(int); // #<!-- -->1
template<typename U>
void f(U); // #<!-- -->2
template<>
void f<int>(int); // #<!-- -->3
};Clang will generate the same USR for Full diff: https://github.com/llvm/llvm-project/pull/98027.diff 2 Files Affected:
diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp
index 5036ddee35fd12..ad7870309c5df1 100644
--- a/clang/lib/Index/USRGeneration.cpp
+++ b/clang/lib/Index/USRGeneration.cpp
@@ -257,12 +257,20 @@ void USRGenerator::VisitFunctionDecl(const FunctionDecl *D) {
!D->hasAttr<OverloadableAttr>())
return;
- if (const TemplateArgumentList *
- SpecArgs = D->getTemplateSpecializationArgs()) {
+ if (D->isFunctionTemplateSpecialization()) {
Out << '<';
- for (unsigned I = 0, N = SpecArgs->size(); I != N; ++I) {
- Out << '#';
- VisitTemplateArgument(SpecArgs->get(I));
+ if (const TemplateArgumentList *SpecArgs =
+ D->getTemplateSpecializationArgs()) {
+ for (const auto &Arg : SpecArgs->asArray()) {
+ Out << '#';
+ VisitTemplateArgument(Arg);
+ }
+ } else if (const ASTTemplateArgumentListInfo *SpecArgsWritten =
+ D->getTemplateSpecializationArgsAsWritten()) {
+ for (const auto &ArgLoc : SpecArgsWritten->arguments()) {
+ Out << '#';
+ VisitTemplateArgument(ArgLoc.getArgument());
+ }
}
Out << '>';
}
diff --git a/clang/test/Index/USR/func-template.cpp b/clang/test/Index/USR/func-template.cpp
new file mode 100644
index 00000000000000..c9c82f5e30a751
--- /dev/null
+++ b/clang/test/Index/USR/func-template.cpp
@@ -0,0 +1,15 @@
+// RUN: c-index-test core -print-source-symbols -- %s | FileCheck %s
+
+template<typename T>
+struct A {
+ void f(int);
+ // CHECK: {{[0-9]+}}:8 | instance-method/C++ | f | c:@ST>1#T@A@F@f#I# |
+
+ template<typename U>
+ void f(U);
+ // CHECK: {{[0-9]+}}:8 | instance-method/C++ | f | c:@ST>1#T@A@FT@>1#Tf#t1.0#v# |
+
+ template<>
+ void f<int>(int);
+ // CHECK: {{[0-9]+}}:8 | instance-method/C++ | f | c:@ST>1#T@A@F@f<#I>#I# |
+};
|
mizvekov
approved these changes
Jul 8, 2024
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.
Given the following:
Clang will generate the same USR for
#1and#2. This patch fixes the issue by including the template arguments of dependent class scope explicit specializations in their USRs.