From f089a52865bd82a327fe9ef460cecdb812dcb56c Mon Sep 17 00:00:00 2001 From: shyouhei Date: Mon, 15 Jan 2018 02:35:16 +0000 Subject: __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 --- compile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index f4ae64bacc..98004b65a0 100644 --- a/compile.c +++ b/compile.c @@ -8077,7 +8077,7 @@ struct ibf_dump { rb_iseq_t * iseq_alloc(void); struct ibf_load { - const char *buff; + const RUBY_ALIGNAS(sizeof(VALUE)) char *buff; const struct ibf_header *header; ID *id_list; /* [id0, ...] */ VALUE iseq_list; /* [iseq0, ...] */ -- cgit v1.2.3