From 15328302dc7154927ebbcec880c9ec200862a1cd Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 20 Jan 2023 23:04:27 +0900 Subject: [PATCH] In `UNALIGNED_MEMBER_PTR` cast through `void` pointer Suppress warnings shown even with `-Waddress-of-packed-member` disabled in gcc 11. --- internal/gc.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/gc.h b/internal/gc.h index 0c6fb2bcaf..0e17a0f001 100644 --- a/internal/gc.h +++ b/internal/gc.h @@ -59,9 +59,19 @@ struct rb_objspace; /* in vm_core.h */ COMPILER_WARNING_POP; \ unaligned_member_access_result; \ }) + +# define UNALIGNED_MEMBER_PTR(ptr, mem) __extension__({ \ + COMPILER_WARNING_PUSH; \ + COMPILER_WARNING_IGNORED(-Waddress-of-packed-member); \ + const volatile void *unaligned_member_ptr_result = &(ptr)->mem; \ + COMPILER_WARNING_POP; \ + (__typeof__((ptr)->mem) *)unaligned_member_ptr_result; \ +}) #endif -#define UNALIGNED_MEMBER_PTR(ptr, mem) UNALIGNED_MEMBER_ACCESS(&(ptr)->mem) +#ifndef UNALIGNED_MEMBER_PTR +# define UNALIGNED_MEMBER_PTR(ptr, mem) UNALIGNED_MEMBER_ACCESS(&(ptr)->mem) +#endif // We use SIZE_POOL_COUNT number of shape IDs for transitions out of different size pools // The next available shapd ID will be the SPECIAL_CONST_SHAPE_ID