summaryrefslogtreecommitdiff
path: root/internal/gc.h
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-01-20 23:04:27 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-01-21 00:30:34 +0900
commit15328302dc7154927ebbcec880c9ec200862a1cd (patch)
tree68739c648cc4a9a061d08ec02150bbea2242deeb /internal/gc.h
parentf0f2535c4daad91872c9f133f8812c421edf0dbb (diff)
downloadruby-15328302dc7154927ebbcec880c9ec200862a1cd.tar.gz
In `UNALIGNED_MEMBER_PTR` cast through `void` pointer
Suppress warnings shown even with `-Waddress-of-packed-member` disabled in gcc 11.
Diffstat (limited to 'internal/gc.h')
-rw-r--r--internal/gc.h12
1 files changed, 11 insertions, 1 deletions
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