From 33dc0a070a515811e71fccbdc8cf0cd5a5dd784c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Tue, 2 Mar 2021 15:22:22 +0900 Subject: [PATCH] RBASIC_SET_CLASS_RAW: follow strict aliasing rule Instead of rather euphemistic struct cast, just reomve the const qualifier and assign directly. According to ISO/IEC 9899:2018 section 6.5 paragraph 7, `VALUE` and `const VALUE` are allowed to alias (but two distinct structs are not, even when their structures are the same). [Bug #17540] --- internal/object.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/object.h b/internal/object.h index aa820128c7..2af90c1fdc 100644 --- a/internal/object.h +++ b/internal/object.h @@ -47,8 +47,8 @@ MJIT_SYMBOL_EXPORT_END static inline void RBASIC_SET_CLASS_RAW(VALUE obj, VALUE klass) { - struct { VALUE flags; VALUE klass; } *ptr = (void *)obj; - ptr->klass = klass; + const VALUE *ptr = &RBASIC(obj)->klass; + *(VALUE *)ptr = klass; } static inline void