[前][次][番号順一覧][スレッド一覧]

ruby-changes:65373

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Tue, 2 Mar 2021 17:47:48 +0900 (JST)
Subject: [ruby-changes:65373] 33dc0a070a (master): RBASIC_SET_CLASS_RAW: follow strict aliasing rule

https://git.ruby-lang.org/ruby.git/commit/?id=33dc0a070a

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?=
 <shyouhei@r...>
Date: Tue, 2 Mar 2021 15:22:22 +0900
Subject: 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 aa82012..2af90c1 100644
--- a/internal/object.h
+++ b/internal/object.h
@@ -47,8 +47,8 @@ MJIT_SYMBOL_EXPORT_END https://github.com/ruby/ruby/blob/trunk/internal/object.h#L47
 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
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]