From e77de9d575321ea3b45347be28ffd62106cdb788 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Mon, 14 Sep 2026 14:33:39 +0100 Subject: [PATCH 1/9] Add test for global initialization with non-const expression --- tests/unit/global_non_const_init.cpp | 79 +++++++ .../out/refcount/global_non_const_init.rs | 218 ++++++++++++++++++ .../unit/out/unsafe/global_non_const_init.rs | 115 +++++++++ 3 files changed, 412 insertions(+) create mode 100644 tests/unit/global_non_const_init.cpp create mode 100644 tests/unit/out/refcount/global_non_const_init.rs create mode 100644 tests/unit/out/unsafe/global_non_const_init.rs diff --git a/tests/unit/global_non_const_init.cpp b/tests/unit/global_non_const_init.cpp new file mode 100644 index 000000000..85a2a36a7 --- /dev/null +++ b/tests/unit/global_non_const_init.cpp @@ -0,0 +1,79 @@ +#include +#include +#include + +int next() { + static int counter = 0; + return ++counter; +} + +// constexpr function call +constexpr uint8_t marker(uint8_t tag) { return (tag << 3) | 2; } +const uint8_t signature[3] = {marker(1), 0x04, 'B'}; +static uint8_t single = marker(2); + +// non-constexpr function call +static int from_call = next(); +static int depends_on_call = from_call + 1; + +// constructors +struct Ctor { + int v; + Ctor() : v(next()) {} + explicit Ctor(int x) : v(x) {} +}; +static Ctor default_ctor; +static Ctor arg_ctor(7); + +// std::string +std::string str = "abc"; + +// static data members +struct Holder { + static int member; + static inline Ctor inline_member{5}; +}; +int Holder::member = next(); + +// static locals +int local_static() { + static int once = next(); + static Ctor local_ctor(3); + return once + local_ctor.v; +} + +// singleton via function local static +struct Singleton { + int hits; + Singleton() : hits(0) {} + static Singleton &instance() { + static Singleton s; + return s; + } +}; + +int main() { + assert(signature[0] == 10); + assert(signature[1] == 0x04); + assert(single == 18); + + assert(from_call == 1); + assert(depends_on_call == 2); + + assert(default_ctor.v == 2); + assert(arg_ctor.v == 7); + + assert(str == "abc"); + + assert(Holder::member == 3); + assert(Holder::inline_member.v == 5); + + assert(local_static() == 7); + assert(local_static() == 7); + + Singleton::instance().hits++; + Singleton::instance().hits++; + assert(Singleton::instance().hits == 2); + assert(&Singleton::instance() == &Singleton::instance()); + return 0; +} diff --git a/tests/unit/out/refcount/global_non_const_init.rs b/tests/unit/out/refcount/global_non_const_init.rs new file mode 100644 index 000000000..60f5f8566 --- /dev/null +++ b/tests/unit/out/refcount/global_non_const_init.rs @@ -0,0 +1,218 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +pub fn next_0() -> i32 { + thread_local!( + static counter_1: Value = Rc::new(RefCell::new(0)); + ); + return (*counter_1.with(Value::clone).borrow_mut()).prefix_inc(); +} +pub fn marker_2(tag: u8) -> u8 { + let tag: Value = Rc::new(RefCell::new(tag)); + return (((((*tag.borrow()) as i32) << 3) | 2) as u8); +} +thread_local!( + pub static signature_3: Value> = Rc::new(RefCell::new(Box::new([ + ({ marker_2(1_u8) }), + 4_u8, + ('B' as u8), + ]))); +); +thread_local!( + pub static single_4: Value = Rc::new(RefCell::new(({ marker_2(2_u8) }))); +); +thread_local!( + pub static from_call_5: Value = Rc::new(RefCell::new(({ next_0() }))); +); +thread_local!( + pub static depends_on_call_6: Value = Rc::new(RefCell::new( + ((*from_call_5.with(Value::clone).borrow()) + 1), + )); +); +#[derive()] +pub struct Ctor { + pub v: Value, +} +impl Ctor { + pub fn Ctor1() -> Self { + let __this: Value = Rc::new(RefCell::new(Self { + v: Rc::new(RefCell::new(({ next_0() }))), + })); + let this: Ptr = __this.as_pointer(); + Rc::try_unwrap(__this).ok().unwrap().into_inner() + } + pub fn Ctor2(x: i32) -> Self { + let x: Value = Rc::new(RefCell::new(x)); + let __this: Value = Rc::new(RefCell::new(Self { + v: Rc::new(RefCell::new((*x.borrow()))), + })); + let this: Ptr = __this.as_pointer(); + Rc::try_unwrap(__this).ok().unwrap().into_inner() + } +} +impl Clone for Ctor { + fn clone(&self) -> Self { + let __this: Value = Rc::new(RefCell::new(Self { + v: Rc::new(RefCell::new((*self.v.borrow()))), + })); + let this: Ptr = __this.as_pointer(); + Rc::try_unwrap(__this).ok().unwrap().into_inner() + } +} +impl Default for Ctor { + fn default() -> Self { + { Ctor::Ctor1() } + } +} +impl ByteRepr for Ctor { + fn byte_size() -> usize { + 4 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.v.borrow()).to_bytes(&mut buf[0..4]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + v: Rc::new(RefCell::new(::from_bytes(&buf[0..4]))), + } + } +} +thread_local!( + pub static default_ctor_7: Value = Rc::new(RefCell::new(Ctor::Ctor1())); +); +thread_local!( + pub static arg_ctor_8: Value = Rc::new(RefCell::new(Ctor::Ctor2({ 7 }))); +); +thread_local!( + pub static str_9: Value> = Rc::new(RefCell::new( + Ptr::from_string_literal(b"abc") + .to_c_string_iterator() + .chain(std::iter::once(0)) + .collect::>(), + )); +); +thread_local!(); +thread_local!( + pub static inline_member_11: Value = Rc::new(RefCell::new(Ctor::Ctor2({ 5 }))); +); +#[derive(Default)] +pub struct Holder {} +impl Clone for Holder { + fn clone(&self) -> Self { + let __this: Value = Rc::new(RefCell::new(Self {})); + let this: Ptr = __this.as_pointer(); + Rc::try_unwrap(__this).ok().unwrap().into_inner() + } +} +impl ByteRepr for Holder { + fn byte_size() -> usize { + 1 + } + fn to_bytes(&self, buf: &mut [u8]) {} + fn from_bytes(buf: &[u8]) -> Self { + Self {} + } +} +thread_local!( + pub static member_10: Value = Rc::new(RefCell::new(({ next_0() }))); +); +pub fn local_static_12() -> i32 { + thread_local!( + static once_13: Value = Rc::new(RefCell::new(({ next_0() }))); + ); + thread_local!( + static local_ctor_14: Value = Rc::new(RefCell::new(Ctor::Ctor2({ 3 }))); + ); + return ((*once_13.with(Value::clone).borrow()) + + (*(*local_ctor_14.with(Value::clone).borrow()).v.borrow())); +} +#[derive()] +pub struct Singleton { + pub hits: Value, +} +impl Singleton { + pub fn Singleton() -> Self { + let __this: Value = Rc::new(RefCell::new(Self { + hits: Rc::new(RefCell::new(0)), + })); + let this: Ptr = __this.as_pointer(); + Rc::try_unwrap(__this).ok().unwrap().into_inner() + } + pub fn instance() -> Ptr { + thread_local!( + static s_15: Value = Rc::new(RefCell::new(Singleton::Singleton())); + ); + return s_15.with(Value::clone).as_pointer(); + } +} +impl Clone for Singleton { + fn clone(&self) -> Self { + let __this: Value = Rc::new(RefCell::new(Self { + hits: Rc::new(RefCell::new((*self.hits.borrow()))), + })); + let this: Ptr = __this.as_pointer(); + Rc::try_unwrap(__this).ok().unwrap().into_inner() + } +} +impl Default for Singleton { + fn default() -> Self { + { Singleton::Singleton() } + } +} +impl ByteRepr for Singleton { + fn byte_size() -> usize { + 4 + } + fn to_bytes(&self, buf: &mut [u8]) { + (*self.hits.borrow()).to_bytes(&mut buf[0..4]); + } + fn from_bytes(buf: &[u8]) -> Self { + Self { + hits: Rc::new(RefCell::new(::from_bytes(&buf[0..4]))), + } + } +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!((((*signature_3.with(Value::clone).borrow())[(0) as usize] as i32) == 10)); + assert!((((*signature_3.with(Value::clone).borrow())[(1) as usize] as i32) == 4)); + assert!((((*single_4.with(Value::clone).borrow()) as i32) == 18)); + assert!(((*from_call_5.with(Value::clone).borrow()) == 1)); + assert!(((*depends_on_call_6.with(Value::clone).borrow()) == 2)); + assert!(((*(*default_ctor_7.with(Value::clone).borrow()).v.borrow()) == 2)); + assert!(((*(*arg_ctor_8.with(Value::clone).borrow()).v.borrow()) == 7)); + assert!( + (*str_9.with(Value::clone).borrow()) + .iter() + .copied() + .take((*str_9.with(Value::clone).borrow()).len().saturating_sub(1)) + .eq(Ptr::from_string_literal(b"abc").to_c_string_iterator()) + ); + assert!(((*member_10.with(Value::clone).borrow()) == 3)); + assert!(((*(*inline_member_11.with(Value::clone).borrow()).v.borrow()) == 5)); + assert!((({ local_static_12() }) == 7)); + assert!((({ local_static_12() }) == 7)); + (*(*({ Singleton::instance() }).upgrade().deref()) + .hits + .borrow_mut()) + .postfix_inc(); + (*(*({ Singleton::instance() }).upgrade().deref()) + .hits + .borrow_mut()) + .postfix_inc(); + assert!( + ((*(*({ Singleton::instance() }).upgrade().deref()) + .hits + .borrow()) + == 2) + ); + assert!((({ Singleton::instance() }) == ({ Singleton::instance() }))); + return 0; +} diff --git a/tests/unit/out/unsafe/global_non_const_init.rs b/tests/unit/out/unsafe/global_non_const_init.rs new file mode 100644 index 000000000..44b18d185 --- /dev/null +++ b/tests/unit/out/unsafe/global_non_const_init.rs @@ -0,0 +1,115 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub unsafe fn next_0() -> i32 { + static mut counter_1: i32 = unsafe { 0 };; + return counter_1.prefix_inc(); +} +pub unsafe fn marker_2(mut tag: u8) -> u8 { + return ((((tag as i32) << (3)) | (2)) as u8); +} +pub static mut signature_3: [u8; 3] = unsafe { + [ + (unsafe { marker_2(1_u8) }), + 4_u8, + (('B' as libc::c_char) as u8), + ] +}; +pub static mut single_4: u8 = unsafe { (unsafe { marker_2(2_u8) }) }; +pub static mut from_call_5: i32 = unsafe { (unsafe { next_0() }) }; +pub static mut depends_on_call_6: i32 = unsafe { ((from_call_5) + (1)) }; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Ctor { + pub v: i32, +} +impl Ctor { + pub unsafe fn Ctor1() -> Self { + let mut this = Self { + v: (unsafe { next_0() }), + }; + this + } + pub unsafe fn Ctor2(mut x: i32) -> Self { + let mut this = Self { v: x }; + this + } +} +impl Default for Ctor { + fn default() -> Self { + unsafe { Ctor::Ctor1() } + } +} +pub static mut default_ctor_7: Ctor = unsafe { Ctor::Ctor1() }; +pub static mut arg_ctor_8: Ctor = unsafe { Ctor::Ctor2({ 7 }) }; +pub static mut str_9: Vec = unsafe { + { + let s = c"abc".as_ptr(); + std::slice::from_raw_parts(s, (0..).take_while(|&i| *s.add(i) != 0).count() + 1).to_vec() + } +}; +pub static mut inline_member_11: Ctor = unsafe { Ctor::Ctor2({ 5 }) }; +#[repr(C)] +#[derive(Copy, Clone, Default)] +pub struct Holder {} +pub static mut member_10: i32 = unsafe { (unsafe { next_0() }) }; +pub unsafe fn local_static_12() -> i32 { + static mut once_13: i32 = unsafe { (unsafe { next_0() }) };; + static mut local_ctor_14: Ctor = unsafe { Ctor::Ctor2({ 3 }) };; + return ((once_13) + (local_ctor_14.v)); +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct Singleton { + pub hits: i32, +} +impl Singleton { + pub unsafe fn Singleton() -> Self { + let mut this = Self { hits: 0 }; + this + } + pub unsafe fn instance() -> *mut Singleton { + static mut s_15: Singleton = unsafe { Singleton::Singleton() };; + return &mut s_15 as *mut Singleton; + } +} +impl Default for Singleton { + fn default() -> Self { + unsafe { Singleton::Singleton() } + } +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!(((signature_3[(0) as usize] as i32) == (10))); + assert!(((signature_3[(1) as usize] as i32) == (4))); + assert!(((single_4 as i32) == (18))); + assert!(((from_call_5) == (1))); + assert!(((depends_on_call_6) == (2))); + assert!(((default_ctor_7.v) == (2))); + assert!(((arg_ctor_8.v) == (7))); + assert!( + str_9 == { + let s = c"abc".as_ptr(); + std::slice::from_raw_parts(s, (0..).take_while(|&i| *s.add(i) != 0).count() + 1) + .to_vec() + } + ); + assert!(((member_10) == (3))); + assert!(((inline_member_11.v) == (5))); + assert!(((unsafe { local_static_12() }) == (7))); + assert!(((unsafe { local_static_12() }) == (7))); + (*(unsafe { Singleton::instance() })).hits.postfix_inc(); + (*(unsafe { Singleton::instance() })).hits.postfix_inc(); + assert!((((*(unsafe { Singleton::instance() })).hits) == (2))); + assert!(((unsafe { Singleton::instance() }) == (unsafe { Singleton::instance() }))); + return 0; +} From ea704563e3273cb809f500934e87da7e1a170069 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Mon, 14 Sep 2026 14:51:46 +0100 Subject: [PATCH 2/9] Update tests --- .../out/unsafe/static_name_collision.rs | 20 +-- tests/unit/out/unsafe/addr_of_global.rs | 59 +++++--- tests/unit/out/unsafe/array_const_init.rs | 18 ++- .../unit/out/unsafe/bool_condition_logical.rs | 10 +- .../out/unsafe/bool_condition_logical_c.rs | 14 +- tests/unit/out/unsafe/constructor.rs | 12 +- tests/unit/out/unsafe/copy_assign.rs | 16 +-- tests/unit/out/unsafe/copy_ctor.rs | 18 +-- tests/unit/out/unsafe/default_in_statics.rs | 134 +++++++++++------- tests/unit/out/unsafe/destructor.rs | 50 ++++--- .../out/unsafe/enum_comparisson_in_globals.rs | 5 +- .../unit/out/unsafe/enum_default_in_static.rs | 14 +- tests/unit/out/unsafe/enum_int_interop.rs | 58 ++++++-- tests/unit/out/unsafe/enum_int_interop_c.rs | 67 ++++++--- tests/unit/out/unsafe/fn_ptr_global.rs | 17 +-- tests/unit/out/unsafe/fn_ptr_vtable.rs | 9 +- .../global-initialization-using-global.rs | 13 +- .../unit/out/unsafe/global_non_const_init.rs | 84 ++++++----- tests/unit/out/unsafe/global_pointers.rs | 34 +++-- .../out/unsafe/global_without_initializer.rs | 14 +- tests/unit/out/unsafe/null_in_statics.rs | 46 +++--- .../unsafe/operator_member_pointer_member.rs | 8 +- tests/unit/out/unsafe/rule_of_five.rs | 53 ++++--- tests/unit/out/unsafe/rule_of_three.rs | 35 +++-- tests/unit/out/unsafe/rvalue_ref_global.rs | 5 +- .../unsafe/static_function_vars_same_name.rs | 8 +- tests/unit/out/unsafe/static_local.rs | 18 ++- tests/unit/out/unsafe/static_shadow.rs | 4 +- tests/unit/out/unsafe/static_var_in_class.rs | 8 +- tests/unit/out/unsafe/string_escape.rs | 97 +++++++------ .../unsafe/string_literal_interior_null.rs | 24 ++-- .../out/unsafe/string_literal_ptr_init.rs | 51 +++++-- .../out/unsafe/union_tagged_struct_arms.rs | 17 +-- tests/unit/out/unsafe/void_cast.rs | 17 +-- 34 files changed, 656 insertions(+), 401 deletions(-) diff --git a/tests/multi-file/static_name_collision/out/unsafe/static_name_collision.rs b/tests/multi-file/static_name_collision/out/unsafe/static_name_collision.rs index f66ac5ea3..88cd3770a 100644 --- a/tests/multi-file/static_name_collision/out/unsafe/static_name_collision.rs +++ b/tests/multi-file/static_name_collision/out/unsafe/static_name_collision.rs @@ -6,13 +6,15 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub static mut same_name_different_type_0: i32 = unsafe { 1 }; -pub static mut same_name_same_type_1: i32 = unsafe { 5 }; +pub static mut same_name_different_type_0: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 1 }); +pub static mut same_name_same_type_1: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 5 }); pub unsafe fn a_foo_2() -> i32 { - return same_name_different_type_0; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut same_name_different_type_0)); } pub unsafe fn a_bar_3() -> i32 { - return same_name_same_type_1; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut same_name_same_type_1)); } pub fn main() { unsafe { @@ -26,11 +28,13 @@ unsafe fn main_0() -> i32 { assert!(((((unsafe { b_bar_5() }) == (6)) as i32) != 0)); return 0; } -pub static mut same_name_different_type_6: f32 = unsafe { 1.0E+0 }; -pub static mut same_name_same_type_7: i32 = unsafe { 6 }; +pub static mut same_name_different_type_6: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 1.0E+0 }); +pub static mut same_name_same_type_7: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 6 }); pub unsafe fn b_foo_4() -> f32 { - return same_name_different_type_6; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut same_name_different_type_6)); } pub unsafe fn b_bar_5() -> i32 { - return same_name_same_type_7; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut same_name_same_type_7)); } diff --git a/tests/unit/out/unsafe/addr_of_global.rs b/tests/unit/out/unsafe/addr_of_global.rs index 496ef09dd..8b56bca96 100644 --- a/tests/unit/out/unsafe/addr_of_global.rs +++ b/tests/unit/out/unsafe/addr_of_global.rs @@ -16,36 +16,49 @@ pub struct Inner { pub struct Outer { pub p: *mut Inner, } -pub static mut alpha_0: Inner = unsafe { Inner { value: 1 } }; -pub static mut beta_1: Inner = unsafe { Inner { value: 2 } }; -pub static mut shared_2: Inner = unsafe { Inner { value: 42 } }; -pub static mut items_3: [*mut Inner; 2] = unsafe { - [ - (&raw mut alpha_0 as *mut Inner), - (&raw mut beta_1 as *mut Inner), - ] -}; -pub static mut obj_4: Outer = unsafe { +pub static mut alpha_0: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { Inner { value: 1 } }); +pub static mut beta_1: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { Inner { value: 2 } }); +pub static mut shared_2: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { Inner { value: 42 } }); +pub static mut items_3: std::cell::LazyCell<[*mut Inner; 2]> = + std::cell::LazyCell::new(|| unsafe { + [ + (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut alpha_0)) as *mut Inner), + (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut beta_1)) as *mut Inner), + ] + }); +pub static mut obj_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { Outer { - p: (&raw mut shared_2 as *mut Inner), + p: (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_2)) as *mut Inner), } -}; +}); pub fn main() { unsafe { std::process::exit(main_0() as i32); } } unsafe fn main_0() -> i32 { - assert!((((*items_3[(0) as usize]).value) == (1))); - assert!((((*items_3[(1) as usize]).value) == (2))); - assert!((((*obj_4.p).value) == (42))); - static mut cache_5: [*mut Inner; 2] = unsafe { - [ - (&raw mut alpha_0 as *mut Inner), - (&raw mut beta_1 as *mut Inner), - ] - };; - assert!((((*cache_5[(0) as usize]).value) == (1))); - assert!((((*cache_5[(1) as usize]).value) == (2))); + assert!( + (((*(*std::cell::LazyCell::force_mut(&mut *&raw mut items_3))[(0) as usize]).value) == (1)) + ); + assert!( + (((*(*std::cell::LazyCell::force_mut(&mut *&raw mut items_3))[(1) as usize]).value) == (2)) + ); + assert!((((*(*std::cell::LazyCell::force_mut(&mut *&raw mut obj_4)).p).value) == (42))); + static mut cache_5: std::cell::LazyCell<[*mut Inner; 2]> = + std::cell::LazyCell::new(|| unsafe { + [ + (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut alpha_0)) as *mut Inner), + (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut beta_1)) as *mut Inner), + ] + });; + assert!( + (((*(*std::cell::LazyCell::force_mut(&mut *&raw mut cache_5))[(0) as usize]).value) == (1)) + ); + assert!( + (((*(*std::cell::LazyCell::force_mut(&mut *&raw mut cache_5))[(1) as usize]).value) == (2)) + ); return 0; } diff --git a/tests/unit/out/unsafe/array_const_init.rs b/tests/unit/out/unsafe/array_const_init.rs index 7601a660b..ed58820bd 100644 --- a/tests/unit/out/unsafe/array_const_init.rs +++ b/tests/unit/out/unsafe/array_const_init.rs @@ -22,28 +22,36 @@ impl Default for S { } } } -pub static mut s_0: S = unsafe { +pub static mut s_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { S { head: 5, tail: [0; 3], buf: [0; 4], } -}; +}); pub fn main() { unsafe { std::process::exit(main_0() as i32); } } unsafe fn main_0() -> i32 { - assert!(((((s_0.head) == (5)) as i32) != 0)); + assert!((((((*std::cell::LazyCell::force_mut(&mut *&raw mut s_0)).head) == (5)) as i32) != 0)); let mut i: i32 = 0; 'loop_: while ((((i) < (3)) as i32) != 0) { - assert!(((((s_0.tail[(i) as usize]) == (0)) as i32) != 0)); + assert!( + (((((*std::cell::LazyCell::force_mut(&mut *&raw mut s_0)).tail[(i) as usize]) == (0)) + as i32) + != 0) + ); i.postfix_inc(); } let mut i: i32 = 0; 'loop_: while ((((i) < (4)) as i32) != 0) { - assert!(((((s_0.buf[(i) as usize] as i32) == (0)) as i32) != 0)); + assert!( + (((((*std::cell::LazyCell::force_mut(&mut *&raw mut s_0)).buf[(i) as usize] as i32) + == (0)) as i32) + != 0) + ); i.postfix_inc(); } return 0; diff --git a/tests/unit/out/unsafe/bool_condition_logical.rs b/tests/unit/out/unsafe/bool_condition_logical.rs index 36ab7f233..a86aeab4f 100644 --- a/tests/unit/out/unsafe/bool_condition_logical.rs +++ b/tests/unit/out/unsafe/bool_condition_logical.rs @@ -10,9 +10,9 @@ pub type Code = u32; pub const Code_CODE_OK: Code = 0; pub const Code_CODE_ERR: Code = 1; pub const Code_CODE_FATAL: Code = 2; -pub static mut side_effect_0: i32 = unsafe { 0 }; +pub static mut side_effect_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub unsafe fn observe_1(mut v: i32) -> i32 { - side_effect_0.prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut side_effect_0)).prefix_inc(); return v; } pub unsafe fn returns_one_2() -> i32 { @@ -49,15 +49,15 @@ unsafe fn main_0() -> i32 { if (((n != 0) && (u != 0)) && (!(p).is_null())) && ((code as i32) == (Code_CODE_OK as i32)) { assert!(true); } - side_effect_0 = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut side_effect_0)) = 0; if (zero != 0) && ((unsafe { observe_1(1) }) != 0) { assert!(false); } - assert!(((side_effect_0) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut side_effect_0)) == (0))); if (n != 0) || ((unsafe { observe_1(1) }) != 0) { assert!(true); } - assert!(((side_effect_0) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut side_effect_0)) == (0))); let mut x: i32 = 5; let mut y: i32 = 3; let mut flags: u32 = 2_u32; diff --git a/tests/unit/out/unsafe/bool_condition_logical_c.rs b/tests/unit/out/unsafe/bool_condition_logical_c.rs index f79c7dd9c..b7c287f6d 100644 --- a/tests/unit/out/unsafe/bool_condition_logical_c.rs +++ b/tests/unit/out/unsafe/bool_condition_logical_c.rs @@ -10,9 +10,9 @@ pub type Code = u32; pub const Code_CODE_OK: Code = 0; pub const Code_CODE_ERR: Code = 1; pub const Code_CODE_FATAL: Code = 2; -pub static mut side_effect_0: i32 = unsafe { 0 }; +pub static mut side_effect_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub unsafe fn observe_1(mut v: i32) -> i32 { - side_effect_0.prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut side_effect_0)).prefix_inc(); return v; } pub unsafe fn returns_one_2() -> i32 { @@ -52,15 +52,19 @@ unsafe fn main_0() -> i32 { { assert!((1 != 0)); } - side_effect_0 = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut side_effect_0)) = 0; if ((((zero != 0) && ((unsafe { observe_1(1) }) != 0)) as i32) != 0) { assert!((0 != 0)); } - assert!(((((side_effect_0) == (0)) as i32) != 0)); + assert!( + ((((*std::cell::LazyCell::force_mut(&mut *&raw mut side_effect_0)) == (0)) as i32) != 0) + ); if ((((n != 0) || ((unsafe { observe_1(1) }) != 0)) as i32) != 0) { assert!((1 != 0)); } - assert!(((((side_effect_0) == (0)) as i32) != 0)); + assert!( + ((((*std::cell::LazyCell::force_mut(&mut *&raw mut side_effect_0)) == (0)) as i32) != 0) + ); let mut x: i32 = 5; let mut y: i32 = 3; let mut flags: u32 = 2_u32; diff --git a/tests/unit/out/unsafe/constructor.rs b/tests/unit/out/unsafe/constructor.rs index 558fd5eb6..630023ec6 100644 --- a/tests/unit/out/unsafe/constructor.rs +++ b/tests/unit/out/unsafe/constructor.rs @@ -6,7 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub static mut total_0: i32 = unsafe { 0 }; +pub static mut total_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive(Clone, Default)] pub struct S { @@ -22,12 +22,14 @@ impl S { pub unsafe fn S(mut init: i32) -> Self { let mut this = Self { v: init }; (unsafe { S::mut_method(&mut this) }); - total_0 += (unsafe { S::const_method(&mut this) }); + (*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) += + (unsafe { S::const_method(&mut this) }); this } pub unsafe fn destructor(&mut self) { (unsafe { S::mut_method(self) }); - total_0 += (unsafe { S::const_method(self) }); + (*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) += + (unsafe { S::const_method(self) }); } } pub fn main() { @@ -40,8 +42,8 @@ unsafe fn main_0() -> i32 { let mut s: S = S::S({ 3 }); let _dtor_s = ScopedDestructorUnsafe::new(&raw mut s, S::destructor); assert!(((s.v) == (4))); - assert!(((total_0) == (8))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) == (8))); } - assert!(((total_0) == (18))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) == (18))); return 0; } diff --git a/tests/unit/out/unsafe/copy_assign.rs b/tests/unit/out/unsafe/copy_assign.rs index c16d17a50..12b506b83 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -6,7 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub static mut assigns_0: i32 = unsafe { 0 }; +pub static mut assigns_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive(Default)] pub struct Partial { @@ -30,7 +30,7 @@ impl Partial { return &mut (*(self as *mut Partial)) as *mut Partial; } self.v = (*o).v; - assigns_0.prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)).prefix_inc(); return &mut (*(self as *mut Partial)) as *mut Partial; } } @@ -114,7 +114,7 @@ unsafe fn main_0() -> i32 { let mut c: Partial = Partial::Partial({ 3 }, { 300 }); (unsafe { Partial::operator_assign(&mut a, &b as *const Partial) }); assert!(((a.v) == (2)) && ((a.keep) == (100))); - assert!(((assigns_0) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (1))); (unsafe { Partial::operator_assign( &mut c, @@ -123,18 +123,18 @@ unsafe fn main_0() -> i32 { ) }); assert!(((c.v) == (2)) && ((c.keep) == (300))); - assert!(((assigns_0) == (3))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (3))); (unsafe { let _o: *const Partial = &a as *const Partial; Partial::operator_assign(&mut a, _o) }); - assert!(((assigns_0) == (3))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (3))); (unsafe { let mut _o: Partial = Partial::Partial({ 9 }, { 900 }); Partial::operator_assign(&mut a, &mut _o) }); assert!(((a.v) == (9)) && ((a.keep) == (100))); - assert!(((assigns_0) == (4))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (4))); let ra: *mut Partial = &mut a as *mut Partial; (unsafe { let _o: *const Partial = &c as *const Partial; @@ -147,7 +147,7 @@ unsafe fn main_0() -> i32 { Partial::operator_assign(&mut (*pa), _o) }); assert!(((a.v) == (2))); - assert!(((assigns_0) == (6))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (6))); let mut h: Holder = Holder { p: Partial::Partial({ 4 }, { 40 }), arr: [ @@ -159,7 +159,7 @@ unsafe fn main_0() -> i32 { (unsafe { Partial::operator_assign(&mut h.arr[(1) as usize], &c as *const Partial) }); assert!(((h.p.v) == (2)) && ((h.p.keep) == (40))); assert!(((h.arr[(1) as usize].v) == (2)) && ((h.arr[(1) as usize].keep) == (60))); - assert!(((assigns_0) == (8))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (8))); let mut n: NonConstAssign = NonConstAssign::NonConstAssign(); let mut n1: NonConstAssign = NonConstAssign::NonConstAssign(); let mut n2: NonConstAssign = NonConstAssign::NonConstAssign(); diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index 5bbe7906c..23da88110 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -6,7 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub static mut copies_0: i32 = unsafe { 0 }; +pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive(Default)] pub struct Counted { @@ -19,7 +19,7 @@ impl Counted { } pub unsafe fn Counted_pconstCounted(o: *const Counted) -> Self { let mut this = Self { v: (*o).v }; - copies_0.prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); this } } @@ -92,23 +92,23 @@ unsafe fn main_0() -> i32 { let mut b: Counted = Counted::Counted_pconstCounted({ &a as *const Counted }); let mut c: Counted = Counted::Counted_pconstCounted({ &a as *const Counted }); let mut d: Counted = Counted::Counted_pconstCounted({ &a as *const Counted }); - assert!(((copies_0) == (3))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (3))); assert!((((b.v) == (1)) && ((c.v) == (1))) && ((d.v) == (1))); assert!( ((unsafe { by_value_1(Counted::Counted_pconstCounted({ &a as *const Counted },),) }) == (1)) ); - assert!(((copies_0) == (4))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (4))); let mut e: Counted = (unsafe { make_2(5) }); assert!(((e.v) == (5))); - assert!(((copies_0) == (5))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (5))); let mut f: Counted = Counted::Counted({ 6 }); assert!(((f.v) == (6))); - assert!(((copies_0) == (5))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (5))); let g: Counted = Counted::Counted({ 7 }); let mut h: Counted = Counted::Counted_pconstCounted({ &g as *const Counted }); assert!(((h.v) == (7))); - assert!(((copies_0) == (6))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (6))); let mut hold: Holder = Holder { c: Counted::Counted({ 8 }), arr: [Counted::Counted({ 9 }), Counted::Counted({ 10 })], @@ -118,14 +118,14 @@ unsafe fn main_0() -> i32 { (((hold2.c.v) == (8)) && ((hold2.arr[(0) as usize].v) == (9))) && ((hold2.arr[(1) as usize].v) == (10)) ); - assert!(((copies_0) == (9))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (9))); let mut vec_: Vec = Vec::new(); { let a0_clone = a.clone(); vec_.push(a0_clone) }; assert!(((vec_[(0_usize)].v) == (1))); - assert!(((copies_0) == (10))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (10))); let mut n: NonConst = NonConst::NonConst(); let mut n1: NonConst = NonConst::NonConst_pmutNonConst({ &mut n as *mut NonConst }); let cn: NonConst = NonConst::NonConst(); diff --git a/tests/unit/out/unsafe/default_in_statics.rs b/tests/unit/out/unsafe/default_in_statics.rs index 3ef0e18b5..d522fa046 100644 --- a/tests/unit/out/unsafe/default_in_statics.rs +++ b/tests/unit/out/unsafe/default_in_statics.rs @@ -58,8 +58,9 @@ impl Default for Foo { } } } -pub static mut static_fn_0: Option i32> = unsafe { None }; -pub static mut static_outer_1: Outer = unsafe { +pub static mut static_fn_0: std::cell::LazyCell i32>> = + std::cell::LazyCell::new(|| unsafe { None }); +pub static mut static_outer_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { Outer { p1: std::ptr::null_mut(), p2: std::ptr::null(), @@ -73,14 +74,15 @@ pub static mut static_outer_1: Outer = unsafe { x: 0_i32, fn_: None, } -}; -pub static mut static_inner_array_2: [Inner; 2] = unsafe { - [Inner { - v: 0_i32, - name: std::ptr::null(), - }; 2] -}; -pub static mut static_foo_3: Foo = unsafe { +}); +pub static mut static_inner_array_2: std::cell::LazyCell<[Inner; 2]> = + std::cell::LazyCell::new(|| unsafe { + [Inner { + v: 0_i32, + name: std::ptr::null(), + }; 2] + }); +pub static mut static_foo_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { Foo { s1: c"hello".as_ptr(), s2: std::ptr::null(), @@ -88,27 +90,28 @@ pub static mut static_foo_3: Foo = unsafe { fn2: None, n: 42, } -}; -pub static mut static_foo_array_4: [Foo; 2] = unsafe { - [ - Foo { - s1: c"first".as_ptr(), - s2: std::ptr::null(), - fn1: None, - fn2: None, - n: 1, - }, - Foo { - s1: c"second".as_ptr(), - s2: std::ptr::null(), - fn1: None, - fn2: None, - n: 2, - }, - ] -}; +}); +pub static mut static_foo_array_4: std::cell::LazyCell<[Foo; 2]> = + std::cell::LazyCell::new(|| unsafe { + [ + Foo { + s1: c"first".as_ptr(), + s2: std::ptr::null(), + fn1: None, + fn2: None, + n: 1, + }, + Foo { + s1: c"second".as_ptr(), + s2: std::ptr::null(), + fn1: None, + fn2: None, + n: 2, + }, + ] + }); pub unsafe fn check_local_static_5() { - static mut local_outer_6: Outer = unsafe { + static mut local_outer_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { Outer { p1: std::ptr::null_mut(), p2: std::ptr::null(), @@ -122,13 +125,15 @@ pub unsafe fn check_local_static_5() { x: 0_i32, fn_: None, } - };; - static mut local_fn_7: Option i32> = unsafe { None };; - static mut local_p_8: *mut i32 = unsafe { std::ptr::null_mut() };; - assert!((local_outer_6.p1).is_null()); - assert!((local_outer_6.fn_).is_none()); - assert!((local_fn_7).is_none()); - assert!((local_p_8).is_null()); + });; + static mut local_fn_7: std::cell::LazyCell i32>> = + std::cell::LazyCell::new(|| unsafe { None });; + static mut local_p_8: std::cell::LazyCell<*mut i32> = + std::cell::LazyCell::new(|| unsafe { std::ptr::null_mut() });; + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut local_outer_6)).p1).is_null()); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut local_outer_6)).fn_).is_none()); + assert!((*std::cell::LazyCell::force_mut(&mut *&raw mut local_fn_7)).is_none()); + assert!((*std::cell::LazyCell::force_mut(&mut *&raw mut local_p_8)).is_null()); } pub fn main() { unsafe { @@ -136,32 +141,55 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - assert!((static_fn_0).is_none()); - assert!((static_outer_1.p1).is_null()); - assert!((static_outer_1.p2).is_null()); - assert!((static_outer_1.cp).is_null()); - assert!((static_outer_1.pp).is_null()); - assert!((static_outer_1.fn_).is_none()); + assert!((*std::cell::LazyCell::force_mut(&mut *&raw mut static_fn_0)).is_none()); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut static_outer_1)).p1).is_null()); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut static_outer_1)).p2).is_null()); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut static_outer_1)).cp).is_null()); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut static_outer_1)).pp).is_null()); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut static_outer_1)).fn_).is_none()); let mut i: i32 = 0; 'loop_: while ((i) < (3)) { - assert!((static_outer_1.arr[(i) as usize]).is_null()); + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_outer_1)).arr[(i) as usize]) + .is_null() + ); i.prefix_inc(); } - assert!((static_outer_1.inner.name).is_null()); + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_outer_1)) + .inner + .name) + .is_null() + ); let mut i: i32 = 0; 'loop_: while ((i) < (2)) { - assert!((static_inner_array_2[(i) as usize].name).is_null()); + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_inner_array_2))[(i) as usize] + .name) + .is_null() + ); i.prefix_inc(); } - assert!((static_foo_3.s2).is_null()); - assert!((static_foo_3.fn1).is_none()); - assert!((static_foo_3.fn2).is_none()); - assert!(((static_foo_3.n) == (42))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut static_foo_3)).s2).is_null()); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut static_foo_3)).fn1).is_none()); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut static_foo_3)).fn2).is_none()); + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut static_foo_3)).n) == (42))); let mut i: i32 = 0; 'loop_: while ((i) < (2)) { - assert!((static_foo_array_4[(i) as usize].s2).is_null()); - assert!((static_foo_array_4[(i) as usize].fn1).is_none()); - assert!((static_foo_array_4[(i) as usize].fn2).is_none()); + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_foo_array_4))[(i) as usize].s2) + .is_null() + ); + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_foo_array_4))[(i) as usize] + .fn1) + .is_none() + ); + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_foo_array_4))[(i) as usize] + .fn2) + .is_none() + ); i.prefix_inc(); } (unsafe { check_local_static_5() }); diff --git a/tests/unit/out/unsafe/destructor.rs b/tests/unit/out/unsafe/destructor.rs index 4f8e74d18..af70431d2 100644 --- a/tests/unit/out/unsafe/destructor.rs +++ b/tests/unit/out/unsafe/destructor.rs @@ -6,13 +6,13 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub static mut global_0: i32 = unsafe { 0 }; +pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive(Clone, Default)] pub struct S {} impl S { pub unsafe fn destructor(&mut self) { - global_0.postfix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)).postfix_inc(); } } #[repr(C)] @@ -81,9 +81,9 @@ pub struct Templated_char_ { } impl Templated_char_ { pub unsafe fn destructor(&mut self) { - global_0 = ((global_0 as usize) - .wrapping_add((::std::mem::size_of::() as usize))) - as i32; + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) = + (((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) as usize) + .wrapping_add((::std::mem::size_of::() as usize))) as i32; } } #[repr(C)] @@ -93,8 +93,9 @@ pub struct Templated_int_ { } impl Templated_int_ { pub unsafe fn destructor(&mut self) { - global_0 = - ((global_0 as usize).wrapping_add((::std::mem::size_of::() as usize))) as i32; + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) = + (((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) as usize) + .wrapping_add((::std::mem::size_of::() as usize))) as i32; } } #[repr(C)] @@ -104,11 +105,12 @@ pub struct Copied { } impl Copied { pub unsafe fn destructor(&mut self) { - global_0.postfix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)).postfix_inc(); } } -pub static mut order_1: [i32; 3] = unsafe { [0_i32; 3] }; -pub static mut order_count_2: i32 = unsafe { 0 }; +pub static mut order_1: std::cell::LazyCell<[i32; 3]> = + std::cell::LazyCell::new(|| unsafe { [0_i32; 3] }); +pub static mut order_count_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive(Clone, Default)] pub struct Tagged { @@ -116,7 +118,9 @@ pub struct Tagged { } impl Tagged { pub unsafe fn destructor(&mut self) { - order_1[(order_count_2.postfix_inc()) as usize] = self.tag; + (*std::cell::LazyCell::force_mut(&mut *&raw mut order_1)) + [((*std::cell::LazyCell::force_mut(&mut *&raw mut order_count_2)).postfix_inc()) + as usize] = self.tag; } } #[repr(C)] @@ -145,36 +149,36 @@ unsafe fn main_0() -> i32 { let mut s: S = S {}; let _dtor_s = ScopedDestructorUnsafe::new(&raw mut s, S::destructor); } - assert!(((global_0) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (1))); { let mut s: S = S {}; let _dtor_s = ScopedDestructorUnsafe::new(&raw mut s, S::destructor); } - assert!(((global_0) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (2))); { let mut d: Defaulted = Defaulted { s: S {} }; let _dtor_d = ScopedDestructorUnsafe::new(&raw mut d, Defaulted::destructor); } - assert!(((global_0) == (3))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (3))); { let mut o: Outer = Outer { m: Middle { s: S {} }, }; let _dtor_o = ScopedDestructorUnsafe::new(&raw mut o, Outer::destructor); } - assert!(((global_0) == (4))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (4))); { let mut am: ArrayMember = ArrayMember { items: [S {}, S {}, S {}], }; let _dtor_am = ScopedDestructorUnsafe::new(&raw mut am, ArrayMember::destructor); } - assert!(((global_0) == (7))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (7))); { let mut e: EmptyBody = EmptyBody { s: S {} }; let _dtor_e = ScopedDestructorUnsafe::new(&raw mut e, EmptyBody::destructor); } - assert!(((global_0) == (8))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (8))); { let mut tc: Templated_char_ = Templated_char_ { v: (0 as libc::c_char), @@ -183,7 +187,7 @@ unsafe fn main_0() -> i32 { let mut ti: Templated_int_ = Templated_int_ { v: 0_i32 }; let _dtor_ti = ScopedDestructorUnsafe::new(&raw mut ti, Templated_int_::destructor); } - assert!(((global_0) == (13))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (13))); { let mut a: Copied = Copied { v: 5 }; let _dtor_a = ScopedDestructorUnsafe::new(&raw mut a, Copied::destructor); @@ -191,7 +195,7 @@ unsafe fn main_0() -> i32 { let _dtor_b = ScopedDestructorUnsafe::new(&raw mut b, Copied::destructor); assert!(((b.v) == (5))); } - assert!(((global_0) == (15))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (15))); { let mut o: Ordered = Ordered { first: Tagged { tag: 1 }, @@ -202,9 +206,9 @@ unsafe fn main_0() -> i32 { }; let _dtor_o = ScopedDestructorUnsafe::new(&raw mut o, Ordered::destructor); } - assert!(((order_count_2) == (3))); - assert!(((order_1[(0) as usize]) == (3))); - assert!(((order_1[(1) as usize]) == (2))); - assert!(((order_1[(2) as usize]) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut order_count_2)) == (3))); + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut order_1))[(0) as usize]) == (3))); + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut order_1))[(1) as usize]) == (2))); + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut order_1))[(2) as usize]) == (1))); return 0; } diff --git a/tests/unit/out/unsafe/enum_comparisson_in_globals.rs b/tests/unit/out/unsafe/enum_comparisson_in_globals.rs index aca69a0e2..50a548dc5 100644 --- a/tests/unit/out/unsafe/enum_comparisson_in_globals.rs +++ b/tests/unit/out/unsafe/enum_comparisson_in_globals.rs @@ -9,13 +9,14 @@ use std::rc::Rc; pub type E = u32; pub const E_A: E = 0; pub const E_B: E = 1; -pub static mut global_0: i32 = unsafe { (((E_A as i32) != (E_B as i32)) as i32) }; +pub static mut global_0: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { (((E_A as i32) != (E_B as i32)) as i32) }); pub fn main() { unsafe { std::process::exit(main_0() as i32); } } unsafe fn main_0() -> i32 { - assert!(((global_0) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (1))); return 0; } diff --git a/tests/unit/out/unsafe/enum_default_in_static.rs b/tests/unit/out/unsafe/enum_default_in_static.rs index a4818b42a..a6ac3fd39 100644 --- a/tests/unit/out/unsafe/enum_default_in_static.rs +++ b/tests/unit/out/unsafe/enum_default_in_static.rs @@ -16,19 +16,25 @@ pub struct Config { pub count: i32, pub mode: Mode, } -pub static mut config_0: Config = unsafe { +pub static mut config_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { Config { count: 0_i32, mode: Mode_MODE_NONE, } -}; +}); pub fn main() { unsafe { std::process::exit(main_0() as i32); } } unsafe fn main_0() -> i32 { - assert!(((((config_0.count) == (0)) as i32) != 0)); - assert!(((((config_0.mode as u32) == ((Mode_MODE_NONE as i32) as u32)) as i32) != 0)); + assert!( + (((((*std::cell::LazyCell::force_mut(&mut *&raw mut config_0)).count) == (0)) as i32) != 0) + ); + assert!( + (((((*std::cell::LazyCell::force_mut(&mut *&raw mut config_0)).mode as u32) + == ((Mode_MODE_NONE as i32) as u32)) as i32) + != 0) + ); return 0; } diff --git a/tests/unit/out/unsafe/enum_int_interop.rs b/tests/unit/out/unsafe/enum_int_interop.rs index 8c64334d8..609e17ac4 100644 --- a/tests/unit/out/unsafe/enum_int_interop.rs +++ b/tests/unit/out/unsafe/enum_int_interop.rs @@ -26,10 +26,13 @@ pub struct Entry { pub color: Color, pub opt: Option, } -pub static mut global_color_0: Color = unsafe { Color_GREEN }; -pub static mut global_opt_1: Option = unsafe { Option_OPT_B }; -pub static mut global_tag_2: Tag = unsafe { Tag_TAG_TWO }; -pub static mut entries_3: [Entry; 3] = unsafe { +pub static mut global_color_0: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { Color_GREEN }); +pub static mut global_opt_1: std::cell::LazyCell