Skip to content

Add _BitInt to substitution table for compatibility with clang - #306

Merged
khuey merged 1 commit into
gimli-rs:masterfrom
al13n321:bit-int-subs
Jan 2, 2026
Merged

khuey merged 1 commit into
gimli-rs:masterfrom
al13n321:bit-int-subs

Conversation

@al13n321

@al13n321 al13n321 commented Nov 13, 2025 •

Copy link
Copy Markdown
Contributor

Followup for #295

  1. Turns out clang considers _BitInt (e.g. <builtin-type> ::= DB <number> _) substitutable.
    • AFAICT, this contradicts https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-compression . But it would be useful in practice to be able to demangle such symbols, so this PR adds this ability.
    • Clang is probably currently the only compiler emitting these DB <number> _ substrings in the wild (gcc doesn't allow _BitInt in C++). And this behavior is consistent between clang mangler and demangler. So I'm guessing the ABI doc will eventually change to match clang, not the other way around. So it seems to make sense to make this behavior default. If you disagree, I can just add an option instead.
    • I checked all other <builtin-type> productions with llvm-cxxfilt, _BitInt and vendor extended type are the only ones that are substitutable.
  2. There was a simple bug where I didn't consume the _ after expression in DB <expression> _. Oops. Added a test.
  3. Also changed "signed _BitInt(<n>)" to "_BitInt(<n>)" to match llvm-cxxfilt output.
  4. Along the way also made "vendor extended type" builtin types substitutable, per https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-compression

(The code ended up a little weird: BuiltinType can be either in Type or in TypeHandle; some variants are always in Type, others are always in TypeHandle. Maybe there should instead be two different enums: substitutable builtin type (in Type) and non-substitutable builtin type (in TypeHandle). Lmk if you would prefer that, and how to name those enums. On the other hand, the current implementation allows easily adding an option to control whether to add _BitInt to substitution table.)

@khuey
khuey merged commit 8411ca0 into gimli-rs:master Jan 2, 2026
6 checks passed
@khuey

khuey commented Jan 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants