-
Notifications
You must be signed in to change notification settings - Fork 738
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
Your byte implementation is unsafe under optimisation on GCC and clang #663
Comments
…ter (thanks to Niall Douglas @ned14)
Sounds pretty reasonable to me. I'm guessing that's only necessary if someone is running without the |
What was the point of calling that out? |
Just to be clear, we're not suggesting anyone prefer to flags to enable extensions to use non-standard c++, right? |
It's C++17 behaviour, see |
-fno-strict-aliasing is not c++17 behavior as far as I can tell. no-strict-aliasing treats everything as if it were a char* from what I can see. |
Ah, had the impression you were referring to |
Strict aliasing has been on by default in GCC for a very long time at -O2 and above. clang gained the same maybe four or five years ago. MSVC once had opt-in strict aliasing a long time ago, but they removed it and its magic compiler options. In any case, on GCC and clang, |
@neilmacintosh I think there is some issue regarding your Facebook link on your profile. |
@xaxxon I was simply asking a question, not "calling anything out". I wanted to understand the situations that would/wouldn't expose people to the problem that was being reported. Both @jack17529 If you would like to contact me directly, I can be reached at neilmac@fb.com. |
Have ported @martinmoene's patch and opened a PR. |
C++17 defines `std::byte*` to have the same aliasing properties as `char*`. Hence, we mark it with the `__may_alias__` attribute under gcc and clang. Based on the fix by Martin Moene in byte-lite. Fixes #663
The C++ 20 standard defines
std::byte*
to have the same may-alias properties aschar*
.Your byte implementation therefore needs to be marked up with
__attribute__((__may_alias__))
on GCC and clang compilers to tell the compiler that it must not assume thatbyte*
cannot alias a pointer to a different type.The text was updated successfully, but these errors were encountered: