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
clang: Assertion `NumPositiveBits <= BestWidth && "How could an initializer get larger than ULL?"' failed. #69352
Comments
@llvm/issue-subscribers-clang-frontend Author: wt.cc (wierton)
This bug is related to a C23 feature (_BigInt):
```
enum { B = 66666666666666666666wb };
```
When compile the above program with clang, clang triggers an assertion failure (Compiler Explorer: https://godbolt.org/z/M6a94abG6):
|
Confirmed CC @AaronBallman |
C23 6.7.2.2p4: For an enumeration without a fixed underlying type, the expression that defines the value of an enumeration constant shall be an integer constant expression. For all the integer constant expressions which make up the values of the enumeration constants, there shall be a type capable of representing all the values that is a standard or extended signed or unsigned integer type, or char.
Note, we should still accept:
because 6.7.2.2p12: "... int, if given explicitly with = and the value of the integer constant expression is representable by an int; or," |
C23 added the wb and uwb suffixes to generate a bit-precise integer value. These values can be larger than what is representable in intmax_t or uintmax_t. We were asserting that an enumerator constant could not have a value larger than unsigned long long but that's now a possibility. This patch turns the assertion into a "value too large" diagnostic. Note, we do not yet implement WG14 N3029 and so the behavior of this patch will cause the enumerator to be cast to unsigned long long, but this behavior may change in the future. GCC selects __uint128_t as the underlying type for such an enumeration and we may want to match that behavior in the future. This patch has several FIXME comments related to this and the release notes call out the possibility of a change in behavior in the future. Fixes llvm#69352
C23 added the wb and uwb suffixes to generate a bit-precise integer value. These values can be larger than what is representable in intmax_t or uintmax_t. We were asserting that an enumerator constant could not have a value larger than unsigned long long but that's now a possibility. This patch turns the assertion into a "value too large" diagnostic. Note, we do not yet implement WG14 N3029 and so the behavior of this patch will cause the enumerator to be cast to unsigned long long, but this behavior may change in the future. GCC selects __uint128_t as the underlying type for such an enumeration and we may want to match that behavior in the future. This patch has several FIXME comments related to this and the release notes call out the possibility of a change in behavior in the future. Fixes #69352
This bug is related to a C23 feature (_BigInt):
When compile the above program with clang, clang triggers an assertion failure (Compiler Explorer: https://godbolt.org/z/M6a94abG6):
Diagnostic:
Assertion:
Backtrace:
The text was updated successfully, but these errors were encountered: