-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
bug: Behavior of denormalized Bool depends on inlining decisions #34909
Comments
What is |
|
Oops, So the general idea is that we assume that every
and make it hard UB? |
I don't think we can realistically defend the invariant that every Bool is normalized. E.g.
This example shows (1) a mismatch between interpreted and compiled code (egal vs equal, which just calls egal but in a compiled situation) and (2) that behavior depends on inlining decisions. More realistic is to treat the other 7 bits of Bool as structure padding:
That is, |
This seems like it's pretty clearly going outside of the system. You can make lots of things break by using |
Absolutely correct. However, one would naively expect that So, if we decide to docfix this, we should write:
...if I was reading this docfix, I'd say think that julia is bananas. My preferred behavior would be
|
Why? See e.g. https://doc.rust-lang.org/reference/behavior-considered-undefined.html
In your text, the part that starts with
and the rest after it can be removed since it is already established that you mustn't do this and it seems you are just adding some passive-aggressive extra stuff because you don't like it :P. For your second suggestion, that seems much more complicated and just worse. |
|
Also, @chethega fixing this isn't that difficult. |
If there are low-cost (zero, actually) ways to make this behavior less bad in the presence of unnormalized bools, that would be great to have. Some doc addition might also be good, but the two notes above are both a bit overly alarming. The first one essentially says "if you use unsafe tools incorrectly, you might hurt yourself" which is pretty reasonable, it's just written in an alarming way. The second one is better, but I'm not sure that the padding stuff will be clear to people (or that most Julia programmers need to know or care about it). |
Looking back at this, |
Booleans are represented by
i8
, but logically representi1
. Now, if we ever come into the situation of having a denormalized Bool, likereinterpret(Bool, 0x03)
, we get very confusing behavior. I am not sure whether this isEspecially the last test suggests that this is pretty UB in practice
The text was updated successfully, but these errors were encountered: