Skip to content

[clang-doc] fix names of conversions for template parameters #140856

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2025

Conversation

evelez7
Copy link
Member

@evelez7 evelez7 commented May 21, 2025

Fixes #59812

The names of conversion functions of template type parameters were being emitted as "type-parameter-N-M". Now we check if the conversion type is a TemplateTypeParmType and reconstruct the source name.

@llvmbot
Copy link
Member

llvmbot commented May 21, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: Erick Velez (evelez7)

Changes

Fixes #59812

The names of conversion functions of template type parameters were being emitted as "type-parameter-N-M". Now we check if the conversion type is a TemplateTypeParmType and reconstruct the source name.


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

1 Files Affected:

  • (modified) clang-tools-extra/clang-doc/Serialize.cpp (+7-1)
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp
index 18db427b5239e..585a46112d43d 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -525,7 +525,13 @@ template <typename T>
 static void populateInfo(Info &I, const T *D, const FullComment *C,
                          bool &IsInAnonymousNamespace) {
   I.USR = getUSRForDecl(D);
-  I.Name = D->getNameAsString();
+  auto ConversionDecl = dyn_cast_or_null<CXXConversionDecl>(D);
+  if (ConversionDecl && ConversionDecl->getConversionType()
+                            .getTypePtr()
+                            ->isTemplateTypeParmType())
+    I.Name = "operator " + ConversionDecl->getConversionType().getAsString();
+  else
+    I.Name = D->getNameAsString();
   populateParentNamespaces(I.Namespace, D, IsInAnonymousNamespace);
   if (C) {
     I.Description.emplace_back();

@evelez7
Copy link
Member Author

evelez7 commented May 21, 2025

Should note that #59812 also mentions the requires clause being omitted but that should be addressed by a different issue/patch because that will be applicable to all function types.

@evelez7 evelez7 requested a review from ilovepi May 21, 2025 07:01
Copy link
Contributor

@ilovepi ilovepi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs a test before it can land.

@evelez7 evelez7 requested a review from ilovepi May 22, 2025 21:23
Copy link
Contributor

@ilovepi ilovepi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but would you mind pre-committing the test so its easy to see what's changing in the output with this patch? I've been trying to get more of that done when we're changing clang-doc output. Otherwise it's hard to know exactly what we're achieving with a particular patch. I can rubber stamp the pre-commit patch.

@evelez7
Copy link
Member Author

evelez7 commented May 22, 2025

would you mind pre-committing the test so its easy to see what's changing in the output with this patch?

Could you explain what this means please? Do you mean reorganizing the PR so that the first commit is the test and then the second is the code change?

@ilovepi
Copy link
Contributor

ilovepi commented May 22, 2025

Sorry, I mean committing a test w/ the current in-tree behavior, and then this patch would have your fix and a small delta to the test showing the new behavior. Some information on that can be found here: https://llvm.org/docs/TestingGuide.html#precommit-workflow-for-tests

@ilovepi
Copy link
Contributor

ilovepi commented May 22, 2025

You can find a stack where I did that here: https://app.graphite.dev/github/pr/llvm/llvm-project/135705/%5Bllvm%5D%5Blto%5D-Precommit-test-for-libcall-internalization

Those aren't landed, since we're hashing out the proper way to fix things, but I added a test w/ the behavior today, and then in the next patch its very easy to see what changed.

@evelez7 evelez7 force-pushed the clang-doc-operator-names branch from 985ca4b to b1a07c3 Compare May 23, 2025 00:34
@evelez7
Copy link
Member Author

evelez7 commented May 23, 2025

Opened #141168. I'll make the test changes once that's in.

I can see why Graphite would be useful to learn. Makes me miss Phabricator a bit. 🥲

@ilovepi
Copy link
Contributor

ilovepi commented May 23, 2025

stacked PRs are still not as nice as phabricator or gerrit, but Graphite is a lot more firendly than I found spr, or winging it w/ github PRs. For a precommit test, it isn't too hard to upload a patch for before and then rebase the "after" patch after it lands.

@evelez7 evelez7 force-pushed the clang-doc-operator-names branch from b1a07c3 to f2f7e1e Compare May 23, 2025 02:21
@evelez7 evelez7 merged commit 441b967 into llvm:main May 23, 2025
11 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented May 23, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-gcc-ubuntu running on sie-linux-worker3 while building clang-tools-extra at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/18265

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'AddressSanitizer-x86_64-linux :: TestCases/asan_lsan_deadlock.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/./bin/clang  --driver-mode=g++ -fsanitize=address -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -gline-tables-only  -m64  -O0 /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/compiler-rt/test/asan/TestCases/asan_lsan_deadlock.cpp -o /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/runtimes/runtimes-bins/compiler-rt/test/asan/X86_64LinuxConfig/TestCases/Output/asan_lsan_deadlock.cpp.tmp # RUN: at line 4
+ /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/./bin/clang --driver-mode=g++ -fsanitize=address -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -gline-tables-only -m64 -O0 /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/compiler-rt/test/asan/TestCases/asan_lsan_deadlock.cpp -o /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/runtimes/runtimes-bins/compiler-rt/test/asan/X86_64LinuxConfig/TestCases/Output/asan_lsan_deadlock.cpp.tmp
env ASAN_OPTIONS=detect_leaks=1 not  /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/runtimes/runtimes-bins/compiler-rt/test/asan/X86_64LinuxConfig/TestCases/Output/asan_lsan_deadlock.cpp.tmp 2>&1 | FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/compiler-rt/test/asan/TestCases/asan_lsan_deadlock.cpp # RUN: at line 5
+ env ASAN_OPTIONS=detect_leaks=1 not /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/runtimes/runtimes-bins/compiler-rt/test/asan/X86_64LinuxConfig/TestCases/Output/asan_lsan_deadlock.cpp.tmp
+ FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/compiler-rt/test/asan/TestCases/asan_lsan_deadlock.cpp
�[1m/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/compiler-rt/test/asan/TestCases/asan_lsan_deadlock.cpp:58:12: �[0m�[0;1;31merror: �[0m�[1mCHECK: expected string not found in input
�[0m // CHECK: SUMMARY: AddressSanitizer: stack-buffer-overflow
�[0;1;32m           ^
�[0m�[1m<stdin>:1:1: �[0m�[0;1;30mnote: �[0m�[1mscanning from here
�[0m=================================================================
�[0;1;32m^
�[0m�[1m<stdin>:2:10: �[0m�[0;1;30mnote: �[0m�[1mpossible intended match here
�[0m==2934904==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7b7d145de034 at pc 0x56352b2b6060 bp 0x7b7d127fdce0 sp 0x7b7d127fdcd8
�[0;1;32m         ^
�[0m
Input file: <stdin>
Check file: /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/compiler-rt/test/asan/TestCases/asan_lsan_deadlock.cpp

-dump-input=help explains the following input dump.

Input was:
<<<<<<
�[1m�[0m�[0;1;30m            1: �[0m�[1m�[0;1;46m================================================================= �[0m
�[0;1;31mcheck:58'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
�[0m�[0;1;30m            2: �[0m�[1m�[0;1;46m==2934904==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7b7d145de034 at pc 0x56352b2b6060 bp 0x7b7d127fdce0 sp 0x7b7d127fdcd8 �[0m
�[0;1;31mcheck:58'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;35mcheck:58'1              ?                                                                                                                                    possible intended match
�[0m�[0;1;30m            3: �[0m�[1m�[0;1;46mWRITE of size 4 at 0x7b7d145de034 thread T2 �[0m
�[0;1;31mcheck:58'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m>>>>>>

--

********************


@evelez7 evelez7 deleted the clang-doc-operator-names branch May 24, 2025 02:39
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
…0856)

Fixes llvm#59812

The names of conversion functions of template type parameters were being
emitted as "type-parameter-N-M". Now we check if the conversion type is
a TemplateTypeParmType and reconstruct the source name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[clang-doc] template operator T() produces a bad name
4 participants