Skip to content

[clang-doc] Fix assertions error in Serialize.cpp #141990

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 1 commit into from
May 29, 2025

Conversation

ilovepi
Copy link
Contributor

@ilovepi ilovepi commented May 29, 2025

We can only print and use a default arg, if it is instantiated.
I was unable to reduce the test case for this to something of reasonable
size, but this is easily hit by running clang-doc to generate clang's
documentation. For now, we can fix the assertion quickly to unbreak
users, and add the proper test once it is small enough.

Copy link
Contributor Author

ilovepi commented May 29, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

github-actions bot commented May 29, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

We can only print and use a default arg, if it is instantiated.
I was unable to reduce the test case for this to something of reasonable
size, but this is easily hit by running clang-doc to generate clang's
documentation. For now, we can fix the assertion quickly to unbreak
users, and add the proper test once it is small enough.
@ilovepi ilovepi force-pushed the users/ilovepi/clang-doc-assertion branch from ac37e01 to d4e62ee Compare May 29, 2025 19:38
@ilovepi ilovepi marked this pull request as ready for review May 29, 2025 19:38
@llvmbot
Copy link
Member

llvmbot commented May 29, 2025

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

Author: Paul Kirth (ilovepi)

Changes

We can only print and use a default arg, if it is instantiated.
I was unable to reduce the test case for this to something of reasonable
size, but this is easily hit by running clang-doc to generate clang's
documentation. For now, we can fix the assertion quickly to unbreak
users, and add the proper test once it is small enough.


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

1 Files Affected:

  • (modified) clang-tools-extra/clang-doc/Serialize.cpp (+3-3)
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp
index 97ea1f02a6178..3932a939de973 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -113,9 +113,9 @@ getFunctionPrototype(const FunctionDecl *FuncDecl) {
       Stream << " " << ParamDecl->getNameAsString();
 
     // Print default argument if it exists
-    if (ParamDecl->hasDefaultArg()) {
-      const Expr *DefaultArg = ParamDecl->getDefaultArg();
-      if (DefaultArg) {
+    if (ParamDecl->hasDefaultArg() &&
+        !ParamDecl->hasUninstantiatedDefaultArg()) {
+      if (const Expr *DefaultArg = ParamDecl->getDefaultArg()) {
         Stream << " = ";
         DefaultArg->printPretty(Stream, nullptr, Ctx.getPrintingPolicy());
       }

Copy link
Member

@evelez7 evelez7 left a comment

Choose a reason for hiding this comment

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

LGTM.

@ilovepi ilovepi merged commit ddc8db7 into main May 29, 2025
11 of 12 checks passed
@ilovepi ilovepi deleted the users/ilovepi/clang-doc-assertion branch May 29, 2025 20:32
svkeerthy pushed a commit that referenced this pull request May 29, 2025
We can only print and use a default arg, if it is instantiated.
I was unable to reduce the test case for this to something of reasonable
size, but this is easily hit by running clang-doc to generate clang's
documentation. For now, we can fix the assertion quickly to unbreak
users, and add the proper test once it is small enough.
google-yfyang pushed a commit to google-yfyang/llvm-project that referenced this pull request May 29, 2025
We can only print and use a default arg, if it is instantiated.
I was unable to reduce the test case for this to something of reasonable
size, but this is easily hit by running clang-doc to generate clang's
documentation. For now, we can fix the assertion quickly to unbreak
users, and add the proper test once it is small enough.
ilovepi added a commit that referenced this pull request May 30, 2025
When we landed the fix for the assertion in #141990, we hadn't yet
reduced the test case sufficiently for a regression test.
ilovepi added a commit that referenced this pull request Jun 3, 2025
When we landed the fix for the assertion in #141990, we hadn't yet
reduced the test case sufficiently for a regression test.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
We can only print and use a default arg, if it is instantiated.
I was unable to reduce the test case for this to something of reasonable
size, but this is easily hit by running clang-doc to generate clang's
documentation. For now, we can fix the assertion quickly to unbreak
users, and add the proper test once it is small enough.
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.

5 participants