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
Ensure RUBY_ALIGNOF == the "alignment requirement" defined in C11 #3570
Conversation
Availability of `alignas` is checked in include/ruby/internal/stdalign.h now. That does not need this configure check. Also as commented in the header, we see `_Alignas` being inadequate for our purpose.
It is reported that on a system of i386 System V ABI, GCC returns 8 for __alignof__(double). OTOH the ABI defines alignments of double to be 4, and ISO/IEC 9899:2011 reads that _Alignof(double) shall return 4 on such machine. What we want in ruby is 4 instead of 8 there. We cannot use __alignof__. Additionally, both old GCC / old clang return 8 for _Alignof(double) on such platforms. They are their bugs, and already fixed in recent versions. But we have to support older compilers for a while. Shall check sanity of _Alignof.
Now that RUBY_ALIGNOF behaves like C11's _Alignof. This is not necessarily the best stack arrangement. We can just give up using __builtin_alloca_with_align(), and let alloca choose what is optimal.
Check if RUBY_ALIGNOF(double) is the alignment to store a double inside of a struct.
Am checking icc / sunc... |
Was definitely a bad idea to use constexpr. It is not ubiquitous.
1f9f728
to
c00bfb2
Compare
C++ compilers are optional. Skip C++ tests when they are absent.
c00bfb2
to
dae0b90
Compare
Both icc/sunc seems working _Alignof, no problem observed for me. |
It seems fine. I recommend some comment about a struct with flexible array member, though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it enough to check only double
?
@mrkn I think so. There are other types that exhibit similar behaviour (e.g. |
Added description and URL about nested flexible array member.
# * querying the alignment of a type, you definitely should use that instead. | ||
# * There are 2 known pitfalls for this fallback implementation: | ||
# * | ||
# * Fitst, it is either an undefined behaviour (C) or an explicit error (C++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fitst => First
Reported by Mau Magnaguagno See: #3570 (comment)
This was a workaround for RUBY_ALIGNOF's glitch, which has already been fixed. See also ruby#3570
This was a workaround for RUBY_ALIGNOF's glitch, which has already been fixed. See also #3570
Context: #3261 (comment)
GCC/clang have
__alignof__
operator. This is very much like C11_Alignof
, but can be different on a i386 System V ABI situation. The difference is troublesome. We would like to stick to what C11 says.This is how we achieve that.