From 591336a0f278bf963d01b6e9810cfc86a5b50620 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Sun, 15 Oct 2023 14:53:14 +0900 Subject: [PATCH] Avoid the pointer hack in RCLASS_EXT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... because GCC 13 warns it. ``` In file included from class.c:24: In function ‘RCLASS_SET_ALLOCATOR’, inlined from ‘class_alloc’ at class.c:251:5, inlined from ‘rb_module_s_alloc’ at class.c:1045:17: internal/class.h:159:43: warning: array subscript 0 is outside array bounds of ‘rb_classext_t[0]’ {aka ‘struct rb_classext_struct[]’} [-Warray-bounds=] 159 | RCLASS_EXT(klass)->as.class.allocator = allocator; | ^ ``` https://rubyci.s3.amazonaws.com/arch/ruby-master/log/20231015T030003Z.log.html.gz --- internal/class.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/class.h b/internal/class.h index 9bc1caf6a9..b055f07317 100644 --- a/internal/class.h +++ b/internal/class.h @@ -85,7 +85,12 @@ struct RClass { // Assert that classes can be embedded in size_pools[2] (which has 160B slot size) STATIC_ASSERT(sizeof_rb_classext_t, sizeof(struct RClass) + sizeof(rb_classext_t) <= 4 * RVALUE_SIZE); -#define RCLASS_EXT(c) ((rb_classext_t *)((char *)(c) + sizeof(struct RClass))) +struct RClass_and_rb_classext_t { + struct RClass rclass; + rb_classext_t classext; +}; + +#define RCLASS_EXT(c) (&((struct RClass_and_rb_classext_t*)(c))->classext) #define RCLASS_CONST_TBL(c) (RCLASS_EXT(c)->const_tbl) #define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl) #define RCLASS_IVPTR(c) (RCLASS_EXT(c)->iv_ptr)