From 655d5e3a9bd084f964ae04cb3275d0c7767b21f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Thu, 2 Sep 2021 15:19:42 +0300 Subject: [PATCH] More syntactic noise to work around unaligned ref warnings --- rts/motoko-rts/src/debug.rs | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/rts/motoko-rts/src/debug.rs b/rts/motoko-rts/src/debug.rs index 8a113bdc68d..9f260e9b10e 100644 --- a/rts/motoko-rts/src/debug.rs +++ b/rts/motoko-rts/src/debug.rs @@ -4,6 +4,7 @@ use crate::print::*; use crate::types::*; use core::fmt::Write; +use core::ptr::addr_of; /// Print an object. The argument can be a skewed pointer to a boxed object, or a tagged scalar. #[cfg(feature = "ic")] @@ -157,7 +158,11 @@ pub(crate) unsafe fn print_boxed_object(buf: &mut WriteBuf, p: usize) { } TAG_OBJ_IND => { let obj_ind = obj as *const ObjInd; - let _ = write!(buf, "", (*obj_ind).field.get_raw()); + let _ = write!( + buf, + "", + (&*addr_of!((*obj_ind).field)).get_raw() + ); } TAG_ARRAY => { let array = obj as *mut Array; @@ -179,7 +184,11 @@ pub(crate) unsafe fn print_boxed_object(buf: &mut WriteBuf, p: usize) { } TAG_MUTBOX => { let mutbox = obj as *const MutBox; - let _ = write!(buf, "", (*mutbox).field.get_raw()); + let _ = write!( + buf, + "", + (&*addr_of!((*mutbox).field)).get_raw() + ); } TAG_CLOSURE => { let closure = obj as *const Closure; @@ -187,7 +196,11 @@ pub(crate) unsafe fn print_boxed_object(buf: &mut WriteBuf, p: usize) { } TAG_SOME => { let some = obj as *const Some; - let _ = write!(buf, "", (*some).field.get_raw()); + let _ = write!( + buf, + "", + (&*addr_of!((*some).field)).get_raw() + ); } TAG_VARIANT => { let variant = obj as *const Variant; @@ -195,7 +208,7 @@ pub(crate) unsafe fn print_boxed_object(buf: &mut WriteBuf, p: usize) { buf, "", { (*variant).tag }, - (*variant).field.get_raw() + (&*addr_of!((*variant).field)).get_raw() ); } TAG_BLOB => { @@ -204,7 +217,11 @@ pub(crate) unsafe fn print_boxed_object(buf: &mut WriteBuf, p: usize) { } TAG_FWD_PTR => { let ind = obj as *const FwdPtr; - let _ = write!(buf, "", (*ind).fwd.get_raw()); + let _ = write!( + buf, + "", + (&*addr_of!((*ind).fwd)).get_raw() + ); } TAG_BITS32 => { let bits32 = obj as *const Bits32; @@ -220,8 +237,8 @@ pub(crate) unsafe fn print_boxed_object(buf: &mut WriteBuf, p: usize) { buf, "", (*concat).n_bytes.0, - (*concat).text1.get_raw(), - (*concat).text2.get_raw(), + (&*addr_of!((*concat).text1)).get_raw(), + (&*addr_of!((*concat).text2)).get_raw(), ); } TAG_ONE_WORD_FILLER => {