-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
wrong value for BOOL_WIDTH #117348
Comments
Hi! This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below. |
@llvm/issue-subscribers-good-first-issue Author: Jens Gustedt (gustedt)
C23 has a new feature test macro BOOL_WIDTH which is fixed by the standard to the value 1.
Clang has it as 8 in v. 14 to 20, gcc has the correct value.
Test this by compiling with
Thanks |
@llvm/issue-subscribers-clang-frontend Author: Jens Gustedt (gustedt)
C23 has a new feature test macro BOOL_WIDTH which is fixed by the standard to the value 1.
Clang has it as 8 in v. 14 to 20, gcc has the correct value.
Test this by compiling with
Thanks |
https://github.com/llvm/llvm-project/blob/main/clang/lib/Frontend/InitPreprocessor.cpp#L1106 is where we define the macro, and it's based on what each target reports. However, changing that value also impacts Note, Clang's current behavior is conforming. C23 5.2.5.3.2p1 specifies the minimum values but they can be replaced by implementation-defined values. I confirmed the issue because I don't know of a good reason why we should diverge from GCC's behavior. |
No, note the little footnote to the item in the C standard for <limits.h> says that it is an exact value. The normative text is in 6.2.6.2 p1
So the problem may even run deeper than just defining the correct value for the macro. |
Footnotes are not normative, so that's a bug in the standard we should fix. The intro text is very explicitly contradicting that footnote:
(Oh, I think I see what you mean, we do say "width for an object of type bool" which could be seen as a descriptor or as a requirement. I read it as a descriptor and you read it as a requirement. Neat!)
I think we may be okay here, because we lower |
Based on comments I spotted at
__BOOL_WIDTH__ to 1 in InitPreprocesor.cpp and not touch TargetInfo . The getBoolWidth() function is returning the number of bits in the object representation, not the value representation. But I'm double-checking this reasoning.
|
No Aaron (to the previous comment). The value could in theory be different for types that have a different width than the minimum width as defined here. For types that have a width that is fixed by the standard there is no wiggle room. So note that the leeway for the implementation is not the value of the macro, the macro is there to represent the effective width of the type. And it was a conscious decision by WG14 to present it as it is presented. What is normative is the text that I cited and which fixes the number of value bits to one. (The number of value bits is the definition of the width.) With which integer type you represent the type internally is llvm's business, obviously, you'd only have to ensure that all other bits than the lowest are considered as padding bits. |
The name of (And also I do not know what you mean by a descriptor. This macro is meant to expand to the number of value bits of the types, which since C23 is |
I would like the standard to say that more clearly as it is a point of needless confusion. We should not explicitly say something can be implementation-defined to be greater than the values shown when we mean something more specific.
Great, and we can make a decision whether we want to change it now that it's caused problems in practice. :-)
Correct, that's the definition of
"width for an object of type bool" etc can be read as introductory text; there's no cross-reference or other indication that "width" here means to be connected with the later-defined term of art. Basically, I think the standards wording would be more clear if 5.2.5.3.2 said something along the lines of "Each standard unsigned integer type (6.2.5) has a corresponding width macro. The implementation-defined values of these macros shall be the number of bits in the value representation of the type (6.2.6.2)." This makes it very explicit that the macros expand to the width (term of art for the number of bits in the value representation) and not the width (ambiguous English term that means different things in different contexts, such as the standard format specifiers talking about field widths, compilers that have poorly named interfaces, etc). Regardless, this is a Clang bug for more than just GCC compatibility reasons; in that I think we're strongly agreed. |
C23 has a new feature test macro BOOL_WIDTH which is fixed by the standard to the value 1.
Clang has it as 8 in v. 14 to 20, gcc has the correct value.
Test this by compiling with
-std=c2x
Thanks
Jens
The text was updated successfully, but these errors were encountered: