diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-09-23 10:57:35 +0900 |
---|---|---|
committer | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-09-25 11:38:33 +0900 |
commit | e9fb2bc873a55181ac7d581e7252db3754a3209d (patch) | |
tree | 7ea6012f6ed825b0f35d0ffbca3ea275266f2b8d /configure.ac | |
parent | fe875be01a501a47a4bf75df9c6b42bb33d9842b (diff) | |
download | ruby-e9fb2bc873a55181ac7d581e7252db3754a3209d.tar.gz |
RBIMPL_ALIGNOF: do not use __alignof__
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.
Diffstat (limited to 'configure.ac')
-rw-r--r-- | configure.ac | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/configure.ac b/configure.ac index 46fdecda23..f7bbc36366 100644 --- a/configure.ac +++ b/configure.ac @@ -1460,26 +1460,44 @@ AS_IF([test "$rb_cv_va_args_macro" = yes], [ AC_DEFINE(HAVE_VA_ARGS_MACRO) ]) -AC_CACHE_CHECK([for alignof() syntax], rb_cv_have_alignof,[ -rb_cv_have_alignof=no -# Prefer alignof over _Alignof to allow C++ compiler to read ruby.h -RUBY_WERROR_FLAG([ -for expr in \ - "alignof" \ - "_Alignof" \ - "__alignof" \ - "__alignof__" \ -; -do - AC_TRY_COMPILE([ - @%:@ifdef HAVE_STDALIGN_H - @%:@include <stdalign.h> - @%:@endif],[return (int)$expr(int);], - [rb_cv_have_alignof="$expr"; break], []) -done -])]) -AS_IF([test "$rb_cv_have_alignof" != no], [ - AC_DEFINE_UNQUOTED(RUBY_ALIGNOF, $rb_cv_have_alignof) +# We want C11's `_Alignof`. GCC (and alike) have `__alignof__`, which behave +# slightly differently than the C11's. We cannot use `__alignof__` for our +# purpose. The problem is, however, that old gcc and old clang had both +# implemented `_Alignof` as a synonym of `__alignof__`. They are not what we +# want. We have to check sanity. +# +# See also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023 +# See also: https://bugs.llvm.org/show_bug.cgi?id=26547 +AC_CACHE_CHECK([if _Alignof() works], rb_cv_have__alignof,[ + rb_cv_have__alignof=no + RUBY_WERROR_FLAG([ + AC_TRY_COMPILE([ + @%:@ifdef HAVE_STDALIGN_H + @%:@include <stdalign.h> + @%:@endif + @%:@ifdef STDC_HEADERS + @%:@include <stddef.h> + @%:@endif + @%:@ifndef __GNUC__ + @%:@define __extension__ + @%:@endif + ], [ + typedef struct conftest_tag { + char _; + double d; + } T; + static int conftest_ary@<:@ + offsetof(T, d) == __extension__ _Alignof(double) + ? 1 : -1 + @:>@; + return conftest_ary@<:@0@:>@; + ], [ + rb_cv_have__alignof=yes + ]) + ]) +]) +AS_IF([test "$rb_cv_have__alignof" != no], [ + AC_DEFINE(HAVE__ALIGNOF) ]) RUBY_FUNC_ATTRIBUTE(__const__, CONSTFUNC) |