itanium-cxx-abi / cxx-abi

C++ ABI Summary
508 stars 96 forks source link

ABI and mangling for _BitInt #128

Closed AaronBallman closed 3 years ago

AaronBallman commented 3 years ago

Hello! WG14 has recently adopted a new fundamental bit-precise integer datatype called _BitInt. The proposal with the final wording is: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2763.pdf. This type started out as a language extension in Clang named _ExtInt that can be used in both C and C++, but WG14 renamed it to _BitInt. The name mangling used in that implementation currently uses _ExtInt. e.g., void func(_ExtInt(64) i) {} corresponds to a mangled identifier @_Z4funcU7_ExtIntILi64EEi in Clang, and it would be useful to have an idea of what name mangling should be used by _BitInt before renaming the type in Clang. This type is expected to be proposed to WG21, but name mangling questions still arise in the C implementation because of attributes that allow for function overloading or other similar extensions.

Can you define the name mangling for this type (and any other ABI-related considerations that need to be addressed)?

It is worth pointing out some details here:

  1. This is a signed or unsigned fundamental integer type that lets the user specify how many bits of precision the type has. Distinct bit widths are distinct types.
  2. The type does not undergo default argument promotions but does undergo integer conversions when needed. If both types are bit-precise, the larger one is picked. If the width of a bit-precise integer type is the same as the width of a basic integer type, the common type is the basic integer type, otherwise the one with larger width is chosen. So _BitInt(32) + int on a system where int is 32 bits will pick int as the common type and same for _BitInt(31) + int, but _BitInt(33) + int would select _BitInt(33) as the common type. If the width of a bit-precise integer type is the same as the width of an extended integer type, it is implementation-defined which is the common type.
  3. The size and alignment of the type is based on the smallest basic integer type that can contain the bit-precise integer type. Bit widths larger than long long int are rounded to the nearest long long-sized boundary. So sizeof(_BitInt(7)) == 1, sizeof(_BitInt(8)) == 1, sizeof(_BitInt(9)) == 2, sizeof(_BitInt(64)) == 8, sizeof(_BitInt(65)) == 16 and alignof(_BitInt(7)) == 1, alignof(_BitInt(8)) == 1, alignof(_BitInt(9)) == 2, alignof(_BitInt(64)) == 8, alignof(_BitInt(65)) == 8.
rjmccall commented 3 years ago

129 seems to be in good shape to me, so I'd like to invite comment from the community on this issue.

AaronBallman commented 3 years ago

Merged in https://github.com/itanium-cxx-abi/cxx-abi/commit/967667b3d7b256ad50a94e1e5d0d3c7661a8ea1b, closing. Thanks!