aboutsummaryrefslogtreecommitdiffstats
path: root/configure.ac
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-15 02:35:16 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-15 02:35:16 +0000
commitf96c96aae6a5361f9c4e01015e66d95854aba166 (patch)
treefd2ebe09327942662defac756ae752d0a9134e00 /configure.ac
parentc439e033dfdad6edf999772a88699138e58e8c48 (diff)
downloadruby-f96c96aae6a5361f9c4e01015e66d95854aba166.tar.gz
__attibute__((__aligned__)) for RSTRING_PTR()
For instance array.c:rb_ary_product() uses RSTRING_PTR() as an array of int. So to avoid misaligned memory access RSTRING_PTR() must at least be sizeof(int)-aligned. However the type of RSTRING_PTR() is char*, which of course can expect alignment as much as 1. This is a problem. The reality is, there is no misaligned memory access because the memory region behind RSTRING_PTR() is allocated using malloc(). Memory regions returned from malloc() are always aligned appropriately. So let's tell the compiler about this information. It seems GCC, clang, and MSVC have such feature. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'configure.ac')
-rw-r--r--configure.ac26
1 files changed, 25 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 81efb0bbc1..f7707b761d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1743,6 +1743,30 @@ EOH
])dnl
])dnl
+AC_CACHE_CHECK([for alignas() syntax], rb_cv_have_alignas, [
+rb_cv_have_alignas=no
+RUBY_WERROR_FLAG([
+for attr in \
+ "_Alignas(x)" \
+ "alignas(x)" \
+ "@<:@@<:@alignas(x)@:>@@:>@" \
+ "__declspec(aligned(x))" \
+ "__attribute__((__aligned__(x)))" \
+;
+do
+ # C11 _Alignas and GCC __attribute__((__aligned__)) behave
+ # slightly differently. What we want is GCC's. Check that
+ # here by something C11 does not allow (`struct ALIGNAS ...`)
+ AC_TRY_COMPILE(
+ [@%:@define ALIGNAS(x) $attr
+ struct ALIGNAS(128) conftest_tag { int foo; } foo; ], [],
+ [rb_cv_have_alignas="$attr"; break], [])
+done
+])])
+AS_IF([test "$rb_cv_have_alignas" != no], [
+ AC_DEFINE_UNQUOTED([RUBY_ALIGNAS(x)], $rb_cv_have_alignas)
+])
+
dnl RUBY_DECL_ATTRIBUTE(attrib, macroname, cachevar, condition, type, code)
AC_DEFUN([RUBY_DECL_ATTRIBUTE], [dnl
m4_ifval([$2], dnl
@@ -1773,6 +1797,7 @@ ${rbcv_cond+[@%:@define ]attrib[](attrib_params)[ x]}
${rbcv_cond+[@%:@endif]})
$6
@%:@define mesg ("")
+@%:@define n (32768)
attrib[](attrib_params)[;], [],
[rbcv="$mac"; break])
done
@@ -1801,7 +1826,6 @@ AC_DEFUN([RUBY_TYPE_ATTRIBUTE], [dnl
@%:@define x struct conftest_attribute_check {int i;}
])
])
-
RUBY_FUNC_ATTRIBUTE(__const__, CONSTFUNC)
RUBY_FUNC_ATTRIBUTE(__pure__, PUREFUNC)
RUBY_FUNC_ATTRIBUTE(__noreturn__, NORETURN)