Skip to content

Fix C++ demangling for _BitInt type #143466

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 4 commits into from
Jun 25, 2025
Merged

Conversation

lfmeadow
Copy link
Contributor

@lfmeadow lfmeadow commented Jun 10, 2025

  • FE expects _BitInt to be available for substitution; ensure DB is added to Subs in ItaniumDemangle.h
  • Add a test case to libc++abi
  • Copy changed files to llvm/include/llvm/

    * FE expects _BitInt to be available for substitution;
      ensure DB<n> is added to Subs in ItaniumDemangle.h
    * Add a test case to libcxxabi
    * Copy changed files to llvm/include/llvm/
@lfmeadow lfmeadow requested a review from a team as a code owner June 10, 2025 02:07
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the libc++abi libc++abi C++ Runtime Library. Not libc++. label Jun 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 10, 2025

@llvm/pr-subscribers-libcxxabi

Author: Larry Meadows (lfmeadow)

Changes
* FE expects _BitInt to be available for substitution; ensure DB&lt;n&gt; is added to Subs in ItaniumDemangle.h
* Add a test case to libcxxabi
* Copy changed files to llvm/include/llvm/

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

4 Files Affected:

  • (modified) libcxxabi/src/demangle/ItaniumDemangle.h (+3-1)
  • (modified) libcxxabi/test/DemangleTestCases.inc (+1)
  • (modified) llvm/include/llvm/Demangle/ItaniumDemangle.h (+3-1)
  • (modified) llvm/include/llvm/Testing/Demangle/DemangleTestCases.inc (+1)
diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h
index 4e7f92dd1991a..b15cf03aa1f9c 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -4468,7 +4468,9 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
         return nullptr;
       if (!consumeIf('_'))
         return nullptr;
-      return make<BitIntType>(Size, Signed);
+      // The FE expects this to be available for Substitution
+      Result = make<BitIntType>(Size, Signed);
+      break;
     }
     //                ::= Di   # char32_t
     case 'i':
diff --git a/libcxxabi/test/DemangleTestCases.inc b/libcxxabi/test/DemangleTestCases.inc
index 1e3f7459deaa2..2721d2aa5504e 100644
--- a/libcxxabi/test/DemangleTestCases.inc
+++ b/libcxxabi/test/DemangleTestCases.inc
@@ -6,6 +6,7 @@
 {"_Z1fDU10_", "f(unsigned _BitInt(10))"},
 {"_Z1fIfEvDUstPT__", "void f<float>(unsigned _BitInt(sizeof (float*)))"},
 {"_Z1fIiEvDBstPT__", "void f<int>(_BitInt(sizeof (int*)))"},
+{"_Z6myfuncRDB8_S0_", "myfunc(_BitInt(8)&, _BitInt(8)&)"},
 {"_Z4testI1A1BE1Cv", "C test<A, B>()"},
 {"_Z4testI1A1BET0_T_S3_", "B test<A, B>(A, A)"},
 {"_ZN1SgtEi", "S::operator>(int)"},
diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h
index f4569850b093c..38ac8473e3e97 100644
--- a/llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -4468,7 +4468,9 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
         return nullptr;
       if (!consumeIf('_'))
         return nullptr;
-      return make<BitIntType>(Size, Signed);
+      // The FE expects this to be available for Substitution
+      Result = make<BitIntType>(Size, Signed);
+      break;
     }
     //                ::= Di   # char32_t
     case 'i':
diff --git a/llvm/include/llvm/Testing/Demangle/DemangleTestCases.inc b/llvm/include/llvm/Testing/Demangle/DemangleTestCases.inc
index 1e3f7459deaa2..2721d2aa5504e 100644
--- a/llvm/include/llvm/Testing/Demangle/DemangleTestCases.inc
+++ b/llvm/include/llvm/Testing/Demangle/DemangleTestCases.inc
@@ -6,6 +6,7 @@
 {"_Z1fDU10_", "f(unsigned _BitInt(10))"},
 {"_Z1fIfEvDUstPT__", "void f<float>(unsigned _BitInt(sizeof (float*)))"},
 {"_Z1fIiEvDBstPT__", "void f<int>(_BitInt(sizeof (int*)))"},
+{"_Z6myfuncRDB8_S0_", "myfunc(_BitInt(8)&, _BitInt(8)&)"},
 {"_Z4testI1A1BE1Cv", "C test<A, B>()"},
 {"_Z4testI1A1BET0_T_S3_", "B test<A, B>(A, A)"},
 {"_ZN1SgtEi", "S::operator>(int)"},

@lfmeadow
Copy link
Contributor Author

This tiny fix resolved a number of problems with demangling names that use _BitInt; in particular that is how some of the 8-bit (and smaller) types are represented in various MI operations.
I would like to request @VitaNuo to review this; I made good use of your #111345 PR.

@frederick-vs-ja frederick-vs-ja requested a review from VitaNuo June 10, 2025 03:51
Copy link
Contributor

@VitaNuo VitaNuo left a comment

Choose a reason for hiding this comment

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

Looks reasonable, thank you. But I am not a maintainer for the demangler, so I would recommend to also request a review from someone in the owners list.

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

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

This makes sense to me with a rewording of the comment, potentially.

For history, @zsrkmyn originally added this support in a23652f.

@zsrkmyn
Copy link
Member

zsrkmyn commented Jun 13, 2025

Thanks for mentioning me here.

But AFAIK, _BitInt and _FloatN were not candidates for substitution by c++abi. Are there any updates now? I once made a proposal to fix the ABI but wasn't merged.

See also: https://reviews.llvm.org/D140359

@zsrkmyn zsrkmyn requested a review from rjmccall June 13, 2025 05:09
@rjmccall
Copy link
Contributor

Is Clang treating these as substitution candidates, and for how long?

@rjmccall
Copy link
Contributor

@zsrkmyn, I got a notification about a response you made, but I don't see it here anymore. I think you're saying that this is not so much a fix as a change intended to unblock a future clang change. But in either case, we seem to have a serious problem if we're retroactively changing the mangling rules for _BitInt. It may have made sense to do this several years, but if we didn't, we may just have to live with the rules as they are.

@zsrkmyn
Copy link
Member

zsrkmyn commented Jun 18, 2025

@rjmccall Sorry, I posted a comment but just found that I was wrong, so I deleted it. I believe you were questioning about how long clang mangler treated these as substitute candidates, but I was answering about demangler.

I haven't worked with _BitInt for years, so I'm not sure what's the current status of it -- neither mangler nor demangler. I posted comments just for historical reference. @lfmeadow may know these things much better than me now :-D

@lfmeadow
Copy link
Contributor Author

I did not look into how long the FE has been making _BitInt substitutable. I will look into it.

@lfmeadow
Copy link
Contributor Author

@zsrkmyn @rjmccall @ldionne It seems one of you needs to approve the workflows before this change can be merged...

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

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

I assumed that Clang already produced these manglings. I'd like to have clarity on whether we already do produce these manglings, otherwise this change may indeed never be required. @lfmeadow Can you chime in?

@lfmeadow
Copy link
Contributor Author

lfmeadow commented Jun 25, 2025

I assumed that Clang already produced these manglings. I'd like to have clarity on whether we already do produce these manglings, otherwise this change may indeed never be required. @lfmeadow Can you chime in?

Yes, clang does produce the mangling for _BitInt, and it does not demangle properly without this change. It's been there for quite some time, with a broken demangler.

@lfmeadow
Copy link
Contributor Author

@ldionne Are you satisfied with my response, or do you need me to try to figure out when/where clang started producing these manglings?

Copy link
Member

@ldionne ldionne 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 is fine, then.

@ldionne ldionne merged commit 20f56d1 into llvm:main Jun 25, 2025
110 of 116 checks passed
Copy link

@lfmeadow Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@lfmeadow lfmeadow deleted the bitint-demangle-fix branch June 25, 2025 19:36
@rjmccall
Copy link
Contributor

Thanks, yeah, that was what I was asking. If clang is producing manglings that assume that this is substitutable, seems like this should be accepted.

@zsrkmyn
Copy link
Member

zsrkmyn commented Jun 26, 2025

@rjmccall I would suggest updating itanium abi as well :-D

anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
The front-end expects _BitInt to be available for substitution; ensure DB<n> is
added to Subs in ItaniumDemangle.h. Also add a test case to libc++abi and
sync the files to llvm/include/llvm.
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
The front-end expects _BitInt to be available for substitution; ensure DB<n> is
added to Subs in ItaniumDemangle.h. Also add a test case to libc++abi and
sync the files to llvm/include/llvm.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++abi libc++abi C++ Runtime Library. Not libc++.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants