Search code examples
c++clangextint

_ExtInt(256) doesn't work in CLang 14, but works in CLang 13


When CLang 14 was released I noticed that following code doesn't compile anymore (but works in CLang 13):

Try it online!

int main() { using T = _ExtInt(256); }

This code was used to create fixed size integers of arbitrary bit length, even of unusual bit sizes like _ExtInt(12345). And everything worked for any bit size.

In CLang 14 you can use only 128 bits:

Try it online!

int main() { using T = _ExtInt(128); }

Above code works in both CLang 13 and 14, but says _ExtInt() is deprecated and suggest to use _BitInt(128) instead.

Of course there exists unsigned __int128, but _ExtInt()/_BitInt() can be used to create any bit size including prime numbers like _ExtInt(97)/_BitInt(97) (online).

I have two questions:

  1. Is there any chance in CLang 14 to have (natively) integers bigger than 128 bits? Of course external libraries like Boost can provide them. But what about native support? As CLang 13 natively supported any weird bit size like _ExtInt(12345).

  2. Is _BitInt(x) exactly same as _ExtInt(x) in CLang 14 for any x?


Solution

  • From https://releases.llvm.org/14.0.0/tools/clang/docs/ReleaseNotes.html#c-language-changes-in-clang:

    Currently, Clang supports bit widths <= 128 because backends are not yet able to cope with some math operations (like division) on wider integer types. See PR44994 for more information.

    And

    _BitInt(N) and _ExtInt(N) are the same types in all respects beyond spelling and the deprecation warning.

    Note that while Clang 13 allows _ExtInt(256), it crashes as soon as a _ExtInt(256) value is divided by 3 (or basically any other value that's not statically a power of 2). (live)