From 09ed8a19e32fe72ebdad445160132ac45fb4cb33 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Mon, 16 Nov 2026 21:24:50 +0000 Subject: [PATCH 1/4] Add basic.link test --- tests/std/basic/basic.link/CMakeLists.txt | 5 + tests/std/basic/basic.link/a.cpp | 304 ++++++++++++ tests/std/basic/basic.link/b.cpp | 146 ++++++ .../basic.link/out/refcount/basic.link.rs | 436 ++++++++++++++++++ .../basic/basic.link/out/unsafe/basic.link.rs | 364 +++++++++++++++ 5 files changed, 1255 insertions(+) create mode 100644 tests/std/basic/basic.link/CMakeLists.txt create mode 100644 tests/std/basic/basic.link/a.cpp create mode 100644 tests/std/basic/basic.link/b.cpp create mode 100644 tests/std/basic/basic.link/out/refcount/basic.link.rs create mode 100644 tests/std/basic/basic.link/out/unsafe/basic.link.rs diff --git a/tests/std/basic/basic.link/CMakeLists.txt b/tests/std/basic/basic.link/CMakeLists.txt new file mode 100644 index 0000000000..f1512e2e0a --- /dev/null +++ b/tests/std/basic/basic.link/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.20) +project(basic_link LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +add_executable(app a.cpp b.cpp) diff --git a/tests/std/basic/basic.link/a.cpp b/tests/std/basic/basic.link/a.cpp new file mode 100644 index 0000000000..f2b2f22542 --- /dev/null +++ b/tests/std/basic/basic.link/a.cpp @@ -0,0 +1,304 @@ +#include + +// N4950 [basic.link]/3.1: the name of a function that is explicitly declared +// static has internal linkage. +namespace p3_1_static_functions_in_two_files { +static int pick() { return 1; } + +int pick_in_b(); + +void test() { + assert(pick() == 1); + assert(pick_in_b() == 2); +} +} // namespace p3_1_static_functions_in_two_files + +// N4950 [basic.link]/3.2: the name of a non-template variable of non-volatile +// const-qualified type has internal linkage. +namespace p3_2_const_variables_in_two_files { +const int limit = 10; + +int limit_in_b(); +const int *limit_address_in_b(); + +void test() { + assert(limit == 10); + assert(limit_in_b() == 20); + assert(&limit != limit_address_in_b()); +} +} // namespace p3_2_const_variables_in_two_files + +// N4950 [basic.link]/3.2.2: unless it is explicitly declared extern. +namespace p3_2_2_extern_const_variable { +extern const int threshold; + +const int *threshold_address_in_b(); + +void test() { + assert(threshold == 30); + assert(&threshold == threshold_address_in_b()); +} +} // namespace p3_2_2_extern_const_variable + +// N4950 [basic.link]/3.2.4: or it was previously declared and the prior +// declaration did not have internal linkage. +namespace p3_2_4_const_variable_previously_declared_extern { +extern const int ceiling; + +const int *ceiling_address_in_b(); + +void test() { + assert(ceiling == 40); + assert(&ceiling == ceiling_address_in_b()); +} +} // namespace p3_2_4_const_variable_previously_declared_extern + +// N4950 [basic.link]/3.3: the name of a data member of an anonymous union has +// internal linkage. +namespace p3_3_anonymous_union_members_in_two_files { +static union { + int whole; + float fraction; +}; + +void set_whole_in_b(int value); +int whole_in_b(); + +void test() { + whole = 5; + set_whole_in_b(6); + assert(whole == 5); + assert(whole_in_b() == 6); +} +} // namespace p3_3_anonymous_union_members_in_two_files + +// N4950 [basic.link]/4: an unnamed namespace or a namespace declared directly +// or indirectly within an unnamed namespace has internal linkage, and so do +// the names of the entities that belong to it. +namespace p4_unnamed_namespaces_in_two_files { +namespace { +int counter = 1; + +int bump() { return ++counter; } + +struct Record { + int id = 100; +}; + +namespace Nested { +int depth = 3; +} +} // namespace + +int bump_in_b(); +int record_id_in_b(); +int depth_in_b(); + +void test() { + assert(bump() == 2); + assert(bump_in_b() == 51); + assert(counter == 2); + + Record record; + assert(record.id == 100); + assert(record_id_in_b() == 200); + + assert(Nested::depth == 3); + assert(depth_in_b() == 4); +} +} // namespace p4_unnamed_namespaces_in_two_files + +// N4950 [basic.link]/4.1: otherwise the name of a variable that belongs to a +// namespace scope has external linkage. +namespace p4_1_variable_defined_in_other_file { +extern int shared_total; + +void add_in_b(int amount); + +void test() { + assert(shared_total == 5); + shared_total = 7; + add_in_b(3); + assert(shared_total == 10); +} +} // namespace p4_1_variable_defined_in_other_file + +// N4950 [basic.link]/4.9: the name of an entity that belongs to a namespace +// with external linkage has external linkage. +namespace p4_9_members_of_named_namespace { +namespace Config { +extern int level; + +int raise(int by); +} // namespace Config + +void test() { + assert(Config::level == 1); + assert(Config::raise(2) == 3); + Config::level = 10; + assert(Config::raise(1) == 11); +} +} // namespace p4_9_members_of_named_namespace + +// N4950 [basic.link]/5: a member function or static data member has the same +// linkage as the name of the class of which it is a member. +namespace p5_members_of_classes_in_unnamed_namespaces { +namespace { +struct Tally { + static int total; + + int add(int amount) { + total += amount; + return total; + } +}; +int Tally::total = 10; +} // namespace + +int add_in_b(int amount); + +void test() { + Tally tally; + assert(tally.add(1) == 11); + assert(add_in_b(1) == 102); + assert(Tally::total == 11); +} +} // namespace p5_members_of_classes_in_unnamed_namespaces + +namespace p5_members_of_class_with_external_linkage { +struct Ledger { + static int balance; + + static int deposit(int amount); +}; + +void test() { + assert(Ledger::balance == 50); + Ledger::balance = 60; + assert(Ledger::deposit(5) == 65); + assert(Ledger::balance == 65); +} +} // namespace p5_members_of_class_with_external_linkage + +// N4950 [basic.link]/6: a block-scope extern declaration redeclares the +// entity of the enclosing namespace, with that entity's linkage. +namespace p6_block_scope_extern_names_entity_in_other_file { +int read_remote() { + extern int remote; + return remote; +} + +void test() { + extern void set_remote_in_b(int value); + assert(read_remote() == 70); + set_remote_in_b(71); + assert(read_remote() == 71); +} +} // namespace p6_block_scope_extern_names_entity_in_other_file + +namespace p6_block_scope_extern_names_hidden_static { +static int hidden = 80; + +int hidden_in_b(); + +int read_hidden_through_extern() { + int hidden = 1; + { + extern int hidden; + return hidden; + } +} + +void test() { + assert(read_hidden_through_extern() == 80); + hidden = 81; + assert(read_hidden_through_extern() == 81); + assert(hidden_in_b() == 90); +} +} // namespace p6_block_scope_extern_names_hidden_static + +// N4950 [basic.link]/7: a name declared at block scope has no linkage. +namespace p7_block_scope_static_variables { +int next_even() { + static int count = 0; + count += 2; + return count; +} + +int next_odd() { + static int count = 1; + count += 2; + return count; +} + +int next_in_b(); + +void test() { + assert(next_even() == 2); + assert(next_odd() == 3); + assert(next_in_b() == 1000); + assert(next_even() == 4); + assert(next_odd() == 5); + assert(next_in_b() == 2000); +} +} // namespace p7_block_scope_static_variables + +namespace p7_local_classes { +int first_key() { + struct Entry { + int key = 1; + }; + Entry entry; + return entry.key; +} + +int second_key_plus_value() { + struct Entry { + int key = 2; + int value = 30; + }; + Entry entry; + return entry.key + entry.value; +} + +int key_in_b(); + +void test() { + assert(first_key() == 1); + assert(second_key_plus_value() == 32); + assert(key_in_b() == 400); +} +} // namespace p7_local_classes + +// N4950 [basic.link]/11: declarations for an array object can specify array +// types that differ by the presence or absence of a major array bound. +namespace p11_array_declared_without_bound { +extern int table[]; + +int table_sum_in_b(); + +void test() { + assert(table[1] == 2); + table[2] = 30; + assert(table_sum_in_b() == 33); +} +} // namespace p11_array_declared_without_bound + +int main() { + p3_1_static_functions_in_two_files::test(); + p3_2_const_variables_in_two_files::test(); + p3_2_2_extern_const_variable::test(); + p3_2_4_const_variable_previously_declared_extern::test(); + p3_3_anonymous_union_members_in_two_files::test(); + p4_unnamed_namespaces_in_two_files::test(); + p4_1_variable_defined_in_other_file::test(); + p4_9_members_of_named_namespace::test(); + p5_members_of_classes_in_unnamed_namespaces::test(); + p5_members_of_class_with_external_linkage::test(); + p6_block_scope_extern_names_entity_in_other_file::test(); + p6_block_scope_extern_names_hidden_static::test(); + p7_block_scope_static_variables::test(); + p7_local_classes::test(); + p11_array_declared_without_bound::test(); + return 0; +} diff --git a/tests/std/basic/basic.link/b.cpp b/tests/std/basic/basic.link/b.cpp new file mode 100644 index 0000000000..2c7ce2b6c2 --- /dev/null +++ b/tests/std/basic/basic.link/b.cpp @@ -0,0 +1,146 @@ +namespace p3_1_static_functions_in_two_files { +static int pick() { return 2; } + +int pick_in_b() { return pick(); } +} // namespace p3_1_static_functions_in_two_files + +namespace p3_2_const_variables_in_two_files { +const int limit = 20; + +int limit_in_b() { return limit; } +const int *limit_address_in_b() { return &limit; } +} // namespace p3_2_const_variables_in_two_files + +namespace p3_2_2_extern_const_variable { +extern const int threshold = 30; + +const int *threshold_address_in_b() { return &threshold; } +} // namespace p3_2_2_extern_const_variable + +namespace p3_2_4_const_variable_previously_declared_extern { +extern const int ceiling; +const int ceiling = 40; + +const int *ceiling_address_in_b() { return &ceiling; } +} // namespace p3_2_4_const_variable_previously_declared_extern + +namespace p3_3_anonymous_union_members_in_two_files { +static union { + int whole; + float fraction; +}; + +void set_whole_in_b(int value) { whole = value; } +int whole_in_b() { return whole; } +} // namespace p3_3_anonymous_union_members_in_two_files + +namespace p4_unnamed_namespaces_in_two_files { +namespace { +int counter = 50; + +int bump() { return ++counter; } + +struct Record { + long id = 200; + int extra = 1; +}; + +namespace Nested { +int depth = 4; +} +} // namespace + +int bump_in_b() { return bump(); } +int record_id_in_b() { + Record record; + return static_cast(record.id); +} +int depth_in_b() { return Nested::depth; } +} // namespace p4_unnamed_namespaces_in_two_files + +namespace p4_1_variable_defined_in_other_file { +int shared_total = 5; + +void add_in_b(int amount) { shared_total += amount; } +} // namespace p4_1_variable_defined_in_other_file + +namespace p4_9_members_of_named_namespace { +namespace Config { +int level = 1; + +int raise(int by) { + level += by; + return level; +} +} // namespace Config +} // namespace p4_9_members_of_named_namespace + +namespace p5_members_of_classes_in_unnamed_namespaces { +namespace { +struct Tally { + static int total; + + int add(int amount) { + total += amount * 2; + return total; + } +}; +int Tally::total = 100; +} // namespace + +int add_in_b(int amount) { + Tally tally; + return tally.add(amount); +} +} // namespace p5_members_of_classes_in_unnamed_namespaces + +namespace p5_members_of_class_with_external_linkage { +struct Ledger { + static int balance; + + static int deposit(int amount); +}; + +int Ledger::balance = 50; + +int Ledger::deposit(int amount) { + balance += amount; + return balance; +} +} // namespace p5_members_of_class_with_external_linkage + +namespace p6_block_scope_extern_names_entity_in_other_file { +int remote = 70; + +void set_remote_in_b(int value) { remote = value; } +} // namespace p6_block_scope_extern_names_entity_in_other_file + +namespace p6_block_scope_extern_names_hidden_static { +static int hidden = 90; + +int hidden_in_b() { return hidden; } +} // namespace p6_block_scope_extern_names_hidden_static + +namespace p7_block_scope_static_variables { +int next_in_b() { + static int count = 0; + count += 1000; + return count; +} +} // namespace p7_block_scope_static_variables + +namespace p7_local_classes { +int key_in_b() { + struct Entry { + long key = 400; + }; + Entry entry; + return static_cast(entry.key); +} +} // namespace p7_local_classes + +namespace p11_array_declared_without_bound { +int table[3] = {1, 2, 3}; + +int table_sum_in_b() { return table[0] + table[1] + table[2]; } +} // namespace p11_array_declared_without_bound diff --git a/tests/std/basic/basic.link/out/refcount/basic.link.rs b/tests/std/basic/basic.link/out/refcount/basic.link.rs new file mode 100644 index 0000000000..cc95be6e1a --- /dev/null +++ b/tests/std/basic/basic.link/out/refcount/basic.link.rs @@ -0,0 +1,436 @@ +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 pick_0() -> i32 { + return 1; +} +pub fn test_1() { + assert!((({ pick_0() }) == 1)); + assert!((({ pick_in_b_2() }) == 2)); +} +thread_local!( + pub static limit_3: Value = Rc::new(RefCell::new(10)); +); +pub fn test_4() { + assert!((limit_3.with(|rc| *rc.borrow()) == 10)); + assert!((({ limit_in_b_5() }) == 20)); + assert!(((limit_3.with(|v| v.as_pointer())) != ({ limit_address_in_b_6() }))); +} +pub fn test_8() { + assert!((threshold_7.with(|rc| *rc.borrow()) == 30)); + assert!(((threshold_7.with(|v| v.as_pointer())) == ({ threshold_address_in_b_9() }))); +} +pub fn test_11() { + assert!((ceiling_10.with(|rc| *rc.borrow()) == 40)); + assert!(((ceiling_10.with(|v| v.as_pointer())) == ({ ceiling_address_in_b_12() }))); +} +#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[byte_size(4)] +pub struct anon_13 { + #[offset(0)] + #[byte_size(4)] + __bytes: Box<[u8]>, +} +impl anon_13 { + pub fn whole(this: Ptr) -> Ptr { + this.reinterpret_cast() + } + pub fn fraction(this: Ptr) -> Ptr { + this.reinterpret_cast() + } +} +impl Default for anon_13 { + fn default() -> Self { + anon_13 { + __bytes: Box::from([0u8; 4]), + } + } +} +pub fn test_14() { + anon_13::whole(anon_13.with(|v| v.as_pointer())).write(5); + ({ set_whole_in_b_15(6) }); + assert!(((anon_13::whole(anon_13.with(|v| v.as_pointer())).read()) == 5)); + assert!((({ whole_in_b_16() }) == 6)); +} +thread_local!( + pub static counter_17: Value = Rc::new(RefCell::new(1)); +); +pub fn bump_18() -> i32 { + return (*counter_17.with(Value::clone).borrow_mut()).prefix_inc(); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(4)] +pub struct p4_unnamed_namespaces_in_two_files_Record { + #[offset(0)] + pub id: i32, +} +impl Default for p4_unnamed_namespaces_in_two_files_Record { + fn default() -> Self { + { p4_unnamed_namespaces_in_two_files_Record { id: 100 } } + } +} +thread_local!( + pub static depth_19: Value = Rc::new(RefCell::new(3)); +); +pub fn test_20() { + assert!((({ bump_18() }) == 2)); + assert!((({ bump_in_b_21() }) == 51)); + assert!((counter_17.with(|rc| *rc.borrow()) == 2)); + let mut record: p4_unnamed_namespaces_in_two_files_Record = + ::default(); + assert!((record.id == 100)); + assert!((({ record_id_in_b_22() }) == 200)); + assert!((depth_19.with(|rc| *rc.borrow()) == 3)); + assert!((({ depth_in_b_23() }) == 4)); +} +pub fn test_25() { + assert!((shared_total_24.with(|rc| *rc.borrow()) == 5)); + shared_total_24.with(|rc| *rc.borrow_mut() = 7); + ({ add_in_b_26(3) }); + assert!((shared_total_24.with(|rc| *rc.borrow()) == 10)); +} +pub fn test_28() { + assert!((level_27.with(|rc| *rc.borrow()) == 1)); + assert!((({ raise_29(2,) }) == 3)); + level_27.with(|rc| *rc.borrow_mut() = 10); + assert!((({ raise_29(1,) }) == 11)); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(1)] +pub struct p5_members_of_classes_in_unnamed_namespaces_Tally {} +thread_local!( + pub static total_30: Value = Rc::new(RefCell::new(10)); +); +pub fn test_31() { + let tally: Value = Rc::new(RefCell::new( + ::default(), + )); + assert!( + (({ p5_members_of_classes_in_unnamed_namespaces_TallyImpl::add(&tally.as_pointer(), 1,) }) + == 11) + ); + assert!((({ add_in_b_32(1,) }) == 102)); + assert!((total_30.with(|rc| *rc.borrow()) == 11)); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(1)] +pub struct p5_members_of_class_with_external_linkage_Ledger {} +pub fn test_34() { + assert!((balance_33.with(|rc| *rc.borrow()) == 50)); + balance_33.with(|rc| *rc.borrow_mut() = 60); + assert!((({ p5_members_of_class_with_external_linkage_Ledger::deposit(5,) }) == 65)); + assert!((balance_33.with(|rc| *rc.borrow()) == 65)); +} +pub fn read_remote_35() -> i32 { + let mut remote: i32 = 0_i32; + return remote; +} +pub fn test_36() { + assert!((({ read_remote_35() }) == 70)); + ({ set_remote_in_b_37(71) }); + assert!((({ read_remote_35() }) == 71)); +} +thread_local!( + pub static hidden_38: Value = Rc::new(RefCell::new(80)); +); +pub fn read_hidden_through_extern_39() -> i32 { + let mut hidden: i32 = 1; + { + let mut hidden: i32 = 0_i32; + return hidden; + } + panic!("ub: non-void function does not return a value") +} +pub fn test_40() { + assert!((({ read_hidden_through_extern_39() }) == 80)); + hidden_38.with(|rc| *rc.borrow_mut() = 81); + assert!((({ read_hidden_through_extern_39() }) == 81)); + assert!((({ hidden_in_b_41() }) == 90)); +} +pub fn next_even_42() -> i32 { + count_43.with(|rc| *rc.borrow_mut() += 2); + return count_43.with(|rc| *rc.borrow()); +} +pub fn next_odd_44() -> i32 { + count_45.with(|rc| *rc.borrow_mut() += 2); + return count_45.with(|rc| *rc.borrow()); +} +pub fn test_46() { + assert!((({ next_even_42() }) == 2)); + assert!((({ next_odd_44() }) == 3)); + assert!((({ next_in_b_47() }) == 1000)); + assert!((({ next_even_42() }) == 4)); + assert!((({ next_odd_44() }) == 5)); + assert!((({ next_in_b_47() }) == 2000)); +} +thread_local!( + static count_43: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + static count_45: Value = Rc::new(RefCell::new(1)); +); +pub fn first_key_48() -> i32 { + let mut entry: Entry_49 = ::default(); + return entry.key; +} +pub fn second_key_plus_value_50() -> i32 { + let mut entry: Entry_51 = ::default(); + return (entry.key + entry.value); +} +pub fn test_52() { + assert!((({ first_key_48() }) == 1)); + assert!((({ second_key_plus_value_50() }) == 32)); + assert!((({ key_in_b_53() }) == 400)); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(4)] +pub struct Entry_49 { + #[offset(0)] + pub key: i32, +} +impl Default for Entry_49 { + fn default() -> Self { + { Entry_49 { key: 1 } } + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(8)] +pub struct Entry_51 { + #[offset(0)] + pub key: i32, + #[offset(4)] + pub value: i32, +} +impl Default for Entry_51 { + fn default() -> Self { + { Entry_51 { key: 2, value: 30 } } + } +} +pub fn test_55() { + assert!( + (({ + let __idx0 = (1) as usize; + table_54.with(|rc| rc.borrow()[__idx0]) + }) == 2) + ); + (*table_54.with(Value::clone).borrow_mut())[(2) as usize] = 30; + assert!((({ table_sum_in_b_56() }) == 33)); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_1() }); + ({ test_4() }); + ({ test_8() }); + ({ test_11() }); + ({ test_14() }); + ({ test_20() }); + ({ test_25() }); + ({ test_28() }); + ({ test_31() }); + ({ test_34() }); + ({ test_36() }); + ({ test_40() }); + ({ test_46() }); + ({ test_52() }); + ({ test_55() }); + return 0; +} +pub fn pick_57() -> i32 { + return 2; +} +pub fn pick_in_b_2() -> i32 { + return ({ pick_57() }); +} +thread_local!( + pub static limit_58: Value = Rc::new(RefCell::new(20)); +); +pub fn limit_in_b_5() -> i32 { + return limit_58.with(|rc| *rc.borrow()); +} +pub fn limit_address_in_b_6() -> Ptr { + return (limit_58.with(|v| v.as_pointer())); +} +thread_local!( + pub static threshold_7: Value = Rc::new(RefCell::new(30)); +); +pub fn threshold_address_in_b_9() -> Ptr { + return (threshold_7.with(|v| v.as_pointer())); +} +thread_local!( + pub static ceiling_10: Value = Rc::new(RefCell::new(40)); +); +pub fn ceiling_address_in_b_12() -> Ptr { + return (ceiling_10.with(|v| v.as_pointer())); +} +#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[byte_size(4)] +pub struct anon_59 { + #[offset(0)] + #[byte_size(4)] + __bytes: Box<[u8]>, +} +impl anon_59 { + pub fn whole(this: Ptr) -> Ptr { + this.reinterpret_cast() + } + pub fn fraction(this: Ptr) -> Ptr { + this.reinterpret_cast() + } +} +impl Default for anon_59 { + fn default() -> Self { + anon_59 { + __bytes: Box::from([0u8; 4]), + } + } +} +pub fn set_whole_in_b_15(mut value: i32) { + anon_59::whole(anon_59.with(|v| v.as_pointer())).write(value); +} +pub fn whole_in_b_16() -> i32 { + return (anon_59::whole(anon_59.with(|v| v.as_pointer())).read()); +} +thread_local!( + pub static counter_60: Value = Rc::new(RefCell::new(50)); +); +pub fn bump_61() -> i32 { + return (*counter_60.with(Value::clone).borrow_mut()).prefix_inc(); +} +thread_local!( + pub static depth_62: Value = Rc::new(RefCell::new(4)); +); +pub fn bump_in_b_21() -> i32 { + return ({ bump_61() }); +} +pub fn record_id_in_b_22() -> i32 { + let mut record: p4_unnamed_namespaces_in_two_files_Record = + ::default(); + return (record.id as i32); +} +pub fn depth_in_b_23() -> i32 { + return depth_62.with(|rc| *rc.borrow()); +} +thread_local!( + pub static shared_total_24: Value = Rc::new(RefCell::new(5)); +); +pub fn add_in_b_26(mut amount: i32) { + shared_total_24.with(|rc| *rc.borrow_mut() += amount); +} +thread_local!( + pub static level_27: Value = Rc::new(RefCell::new(1)); +); +pub fn raise_29(mut by: i32) -> i32 { + level_27.with(|rc| *rc.borrow_mut() += by); + return level_27.with(|rc| *rc.borrow()); +} +thread_local!( + pub static total_63: Value = Rc::new(RefCell::new(100)); +); +pub fn add_in_b_32(mut amount: i32) -> i32 { + let tally: Value = Rc::new(RefCell::new( + ::default(), + )); + return ({ + p5_members_of_classes_in_unnamed_namespaces_TallyImpl::add(&tally.as_pointer(), amount) + }); +} +thread_local!( + pub static balance_33: Value = Rc::new(RefCell::new(50)); +); +impl p5_members_of_class_with_external_linkage_Ledger { + pub fn deposit(mut amount: i32) -> i32 { + balance_33.with(|rc| *rc.borrow_mut() += amount); + return balance_33.with(|rc| *rc.borrow()); + } +} +thread_local!( + pub static remote_64: Value = Rc::new(RefCell::new(70)); +); +pub fn set_remote_in_b_37(mut value: i32) { + remote_64.with(|rc| *rc.borrow_mut() = value); +} +thread_local!( + pub static hidden_65: Value = Rc::new(RefCell::new(90)); +); +pub fn hidden_in_b_41() -> i32 { + return hidden_65.with(|rc| *rc.borrow()); +} +pub fn next_in_b_47() -> i32 { + count_66.with(|rc| *rc.borrow_mut() += 1000); + return count_66.with(|rc| *rc.borrow()); +} +thread_local!( + static count_66: Value = Rc::new(RefCell::new(0)); +); +pub fn key_in_b_53() -> i32 { + let mut entry: Entry_67 = ::default(); + return (entry.key as i32); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(8)] +pub struct Entry_67 { + #[offset(0)] + pub key: i64, +} +impl Default for Entry_67 { + fn default() -> Self { + { Entry_67 { key: 400_i64 } } + } +} +thread_local!( + pub static table_54: Value> = Rc::new(RefCell::new(Box::new([1, 2, 3]))); +); +pub fn table_sum_in_b_56() -> i32 { + return ((({ + let __idx0 = (0) as usize; + table_54.with(|rc| rc.borrow()[__idx0]) + }) + ({ + let __idx0 = (1) as usize; + table_54.with(|rc| rc.borrow()[__idx0]) + })) + ({ + let __idx0 = (2) as usize; + table_54.with(|rc| rc.borrow()[__idx0]) + })); +} +pub trait p5_members_of_classes_in_unnamed_namespaces_TallyImpl { + fn add(&self, amount: i32) -> i32; +} +impl p5_members_of_classes_in_unnamed_namespaces_TallyImpl + for Ptr +{ + fn add(&self, mut amount: i32) -> i32 { + total_30.with(|rc| *rc.borrow_mut() += amount); + return total_30.with(|rc| *rc.borrow()); + } + fn add(&self, mut amount: i32) -> i32 { + total_63.with(|rc| *rc.borrow_mut() += (amount * 2)); + return total_63.with(|rc| *rc.borrow()); + } +} +pub fn __cpp2rust_init_globals() { + let _ = limit_3.with(|_| ()); + let _ = counter_17.with(|_| ()); + let _ = depth_19.with(|_| ()); + let _ = total_30.with(|_| ()); + let _ = hidden_38.with(|_| ()); + let _ = limit_58.with(|_| ()); + let _ = threshold_7.with(|_| ()); + let _ = ceiling_10.with(|_| ()); + let _ = counter_60.with(|_| ()); + let _ = depth_62.with(|_| ()); + let _ = shared_total_24.with(|_| ()); + let _ = level_27.with(|_| ()); + let _ = total_63.with(|_| ()); + let _ = balance_33.with(|_| ()); + let _ = remote_64.with(|_| ()); + let _ = hidden_65.with(|_| ()); + let _ = table_54.with(|_| ()); +} diff --git a/tests/std/basic/basic.link/out/unsafe/basic.link.rs b/tests/std/basic/basic.link/out/unsafe/basic.link.rs new file mode 100644 index 0000000000..6c71741c77 --- /dev/null +++ b/tests/std/basic/basic.link/out/unsafe/basic.link.rs @@ -0,0 +1,364 @@ +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 pick_0() -> i32 { + return 1; +} +pub unsafe fn test_1() { + assert!(((unsafe { pick_0() }) == (1))); + assert!(((unsafe { pick_in_b_2() }) == (2))); +} +pub static mut limit_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10 }); +pub unsafe fn test_4() { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut limit_3)) == (10))); + assert!(((unsafe { limit_in_b_5() }) == (20))); + assert!( + ((&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut limit_3)) as *const i32) + != (unsafe { limit_address_in_b_6() })) + ); +} +pub unsafe fn test_8() { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut threshold_7)) == (30))); + assert!( + ((&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut threshold_7)) as *const i32) + == (unsafe { threshold_address_in_b_9() })) + ); +} +pub unsafe fn test_11() { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ceiling_10)) == (40))); + assert!( + ((&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut ceiling_10)) as *const i32) + == (unsafe { ceiling_address_in_b_12() })) + ); +} +#[repr(C)] +#[derive(Copy, Clone, FnPtrArg, VaArg)] +pub union anon_13 { + pub whole: i32, + pub fraction: f32, +} +impl Default for anon_13 { + fn default() -> Self { + unsafe { std::mem::zeroed() } + } +} +pub unsafe fn test_14() { + (*std::cell::LazyCell::force_mut(&mut *&raw mut anon_13)).whole = 5; + (unsafe { set_whole_in_b_15(6) }); + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut anon_13)).whole) == (5))); + assert!(((unsafe { whole_in_b_16() }) == (6))); +} +pub static mut counter_17: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 1 }); +pub unsafe fn bump_18() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut counter_17)).prefix_inc(); +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct p4_unnamed_namespaces_in_two_files_Record { + pub id: i32, +} +impl Default for p4_unnamed_namespaces_in_two_files_Record { + fn default() -> Self { + unsafe { p4_unnamed_namespaces_in_two_files_Record { id: 100 } } + } +} +pub static mut depth_19: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 3 }); +pub unsafe fn test_20() { + assert!(((unsafe { bump_18() }) == (2))); + assert!(((unsafe { bump_in_b_21() }) == (51))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut counter_17)) == (2))); + let mut record: p4_unnamed_namespaces_in_two_files_Record = + ::default(); + assert!(((record.id) == (100))); + assert!(((unsafe { record_id_in_b_22() }) == (200))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut depth_19)) == (3))); + assert!(((unsafe { depth_in_b_23() }) == (4))); +} +pub unsafe fn test_25() { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut shared_total_24)) == (5))); + (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_total_24)) = 7; + (unsafe { add_in_b_26(3) }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut shared_total_24)) == (10))); +} +pub unsafe fn test_28() { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut level_27)) == (1))); + assert!(((unsafe { raise_29(2,) }) == (3))); + (*std::cell::LazyCell::force_mut(&mut *&raw mut level_27)) = 10; + assert!(((unsafe { raise_29(1,) }) == (11))); +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p5_members_of_classes_in_unnamed_namespaces_Tally {} +impl p5_members_of_classes_in_unnamed_namespaces_Tally { + pub unsafe fn add(&mut self, mut amount: i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut total_30)) += amount; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut total_30)); + } +} +pub static mut total_30: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10 }); +pub unsafe fn test_31() { + let mut tally: p5_members_of_classes_in_unnamed_namespaces_Tally = + ::default(); + assert!( + ((unsafe { p5_members_of_classes_in_unnamed_namespaces_Tally::add(&mut tally, 1,) }) + == (11)) + ); + assert!(((unsafe { add_in_b_32(1,) }) == (102))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_30)) == (11))); +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p5_members_of_class_with_external_linkage_Ledger {} +pub unsafe fn test_34() { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut balance_33)) == (50))); + (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_33)) = 60; + assert!(((unsafe { p5_members_of_class_with_external_linkage_Ledger::deposit(5,) }) == (65))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut balance_33)) == (65))); +} +pub unsafe fn read_remote_35() -> i32 { + let mut remote: i32 = 0_i32; + return remote; +} +pub unsafe fn test_36() { + assert!(((unsafe { read_remote_35() }) == (70))); + (unsafe { set_remote_in_b_37(71) }); + assert!(((unsafe { read_remote_35() }) == (71))); +} +pub static mut hidden_38: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 80 }); +pub unsafe fn read_hidden_through_extern_39() -> i32 { + let mut hidden: i32 = 1; + { + let mut hidden: i32 = 0_i32; + return hidden; + } + panic!("ub: non-void function does not return a value") +} +pub unsafe fn test_40() { + assert!(((unsafe { read_hidden_through_extern_39() }) == (80))); + (*std::cell::LazyCell::force_mut(&mut *&raw mut hidden_38)) = 81; + assert!(((unsafe { read_hidden_through_extern_39() }) == (81))); + assert!(((unsafe { hidden_in_b_41() }) == (90))); +} +pub unsafe fn next_even_42() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut count_43)) += 2; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut count_43)); +} +pub unsafe fn next_odd_44() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut count_45)) += 2; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut count_45)); +} +pub unsafe fn test_46() { + assert!(((unsafe { next_even_42() }) == (2))); + assert!(((unsafe { next_odd_44() }) == (3))); + assert!(((unsafe { next_in_b_47() }) == (1000))); + assert!(((unsafe { next_even_42() }) == (4))); + assert!(((unsafe { next_odd_44() }) == (5))); + assert!(((unsafe { next_in_b_47() }) == (2000))); +} +static mut count_43: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +static mut count_45: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 1 }); +pub unsafe fn first_key_48() -> i32 { + let mut entry: Entry_49 = ::default(); + return entry.key; +} +pub unsafe fn second_key_plus_value_50() -> i32 { + let mut entry: Entry_51 = ::default(); + return ((entry.key) + (entry.value)); +} +pub unsafe fn test_52() { + assert!(((unsafe { first_key_48() }) == (1))); + assert!(((unsafe { second_key_plus_value_50() }) == (32))); + assert!(((unsafe { key_in_b_53() }) == (400))); +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct Entry_49 { + pub key: i32, +} +impl Default for Entry_49 { + fn default() -> Self { + unsafe { Entry_49 { key: 1 } } + } +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct Entry_51 { + pub key: i32, + pub value: i32, +} +impl Default for Entry_51 { + fn default() -> Self { + unsafe { Entry_51 { key: 2, value: 30 } } + } +} +pub unsafe fn test_55() { + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut table_54))[(1) as usize]) == (2))); + (*std::cell::LazyCell::force_mut(&mut *&raw mut table_54))[(2) as usize] = 30; + assert!(((unsafe { table_sum_in_b_56() }) == (33))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_1() }); + (unsafe { test_4() }); + (unsafe { test_8() }); + (unsafe { test_11() }); + (unsafe { test_14() }); + (unsafe { test_20() }); + (unsafe { test_25() }); + (unsafe { test_28() }); + (unsafe { test_31() }); + (unsafe { test_34() }); + (unsafe { test_36() }); + (unsafe { test_40() }); + (unsafe { test_46() }); + (unsafe { test_52() }); + (unsafe { test_55() }); + return 0; +} +pub unsafe fn pick_57() -> i32 { + return 2; +} +pub unsafe fn pick_in_b_2() -> i32 { + return (unsafe { pick_57() }); +} +pub static mut limit_58: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 20 }); +pub unsafe fn limit_in_b_5() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut limit_58)); +} +pub unsafe fn limit_address_in_b_6() -> *const i32 { + return (&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut limit_58)) as *const i32); +} +pub static mut threshold_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 30 }); +pub unsafe fn threshold_address_in_b_9() -> *const i32 { + return (&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut threshold_7)) + as *const i32); +} +pub static mut ceiling_10: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 40 }); +pub unsafe fn ceiling_address_in_b_12() -> *const i32 { + return (&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut ceiling_10)) as *const i32); +} +#[repr(C)] +#[derive(Copy, Clone, FnPtrArg, VaArg)] +pub union anon_59 { + pub whole: i32, + pub fraction: f32, +} +impl Default for anon_59 { + fn default() -> Self { + unsafe { std::mem::zeroed() } + } +} +pub unsafe fn set_whole_in_b_15(mut value: i32) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut anon_59)).whole = value; +} +pub unsafe fn whole_in_b_16() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut anon_59)).whole; +} +pub static mut counter_60: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 50 }); +pub unsafe fn bump_61() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut counter_60)).prefix_inc(); +} +pub static mut depth_62: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 4 }); +pub unsafe fn bump_in_b_21() -> i32 { + return (unsafe { bump_61() }); +} +pub unsafe fn record_id_in_b_22() -> i32 { + let mut record: p4_unnamed_namespaces_in_two_files_Record = + ::default(); + return (record.id as i32); +} +pub unsafe fn depth_in_b_23() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut depth_62)); +} +pub static mut shared_total_24: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 5 }); +pub unsafe fn add_in_b_26(mut amount: i32) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_total_24)) += amount; +} +pub static mut level_27: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 1 }); +pub unsafe fn raise_29(mut by: i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut level_27)) += by; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut level_27)); +} +impl p5_members_of_classes_in_unnamed_namespaces_Tally { + pub unsafe fn add(&mut self, mut amount: i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut total_63)) += ((amount) * (2)); + return (*std::cell::LazyCell::force_mut(&mut *&raw mut total_63)); + } +} +pub static mut total_63: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); +pub unsafe fn add_in_b_32(mut amount: i32) -> i32 { + let mut tally: p5_members_of_classes_in_unnamed_namespaces_Tally = + ::default(); + return (unsafe { p5_members_of_classes_in_unnamed_namespaces_Tally::add(&mut tally, amount) }); +} +pub static mut balance_33: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 50 }); +impl p5_members_of_class_with_external_linkage_Ledger { + pub unsafe fn deposit(mut amount: i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_33)) += amount; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_33)); + } +} +pub static mut remote_64: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 70 }); +pub unsafe fn set_remote_in_b_37(mut value: i32) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut remote_64)) = value; +} +pub static mut hidden_65: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 90 }); +pub unsafe fn hidden_in_b_41() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut hidden_65)); +} +pub unsafe fn next_in_b_47() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut count_66)) += 1000; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut count_66)); +} +static mut count_66: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub unsafe fn key_in_b_53() -> i32 { + let mut entry: Entry_67 = ::default(); + return (entry.key as i32); +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct Entry_67 { + pub key: i64, +} +impl Default for Entry_67 { + fn default() -> Self { + unsafe { Entry_67 { key: 400_i64 } } + } +} +pub static mut table_54: std::cell::LazyCell<[i32; 3]> = + std::cell::LazyCell::new(|| unsafe { [1, 2, 3] }); +pub unsafe fn table_sum_in_b_56() -> i32 { + return ((((*std::cell::LazyCell::force_mut(&mut *&raw mut table_54))[(0) as usize]) + + ((*std::cell::LazyCell::force_mut(&mut *&raw mut table_54))[(1) as usize])) + + ((*std::cell::LazyCell::force_mut(&mut *&raw mut table_54))[(2) as usize])); +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const limit_3); + std::cell::LazyCell::force(&*&raw const counter_17); + std::cell::LazyCell::force(&*&raw const depth_19); + std::cell::LazyCell::force(&*&raw const total_30); + std::cell::LazyCell::force(&*&raw const hidden_38); + std::cell::LazyCell::force(&*&raw const limit_58); + std::cell::LazyCell::force(&*&raw const threshold_7); + std::cell::LazyCell::force(&*&raw const ceiling_10); + std::cell::LazyCell::force(&*&raw const counter_60); + std::cell::LazyCell::force(&*&raw const depth_62); + std::cell::LazyCell::force(&*&raw const shared_total_24); + std::cell::LazyCell::force(&*&raw const level_27); + std::cell::LazyCell::force(&*&raw const total_63); + std::cell::LazyCell::force(&*&raw const balance_33); + std::cell::LazyCell::force(&*&raw const remote_64); + std::cell::LazyCell::force(&*&raw const hidden_65); + std::cell::LazyCell::force(&*&raw const table_54); +} From 4f558cfb165f01711f6b287a68c3a00a2b8ee9f6 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Mon, 16 Nov 2026 21:36:26 +0000 Subject: [PATCH 2/4] Update tests --- .../basic.link/out/refcount/basic.link.rs | 184 ++++++++--------- .../basic/basic.link/out/unsafe/basic.link.rs | 186 +++++++++--------- 2 files changed, 190 insertions(+), 180 deletions(-) diff --git a/tests/std/basic/basic.link/out/refcount/basic.link.rs b/tests/std/basic/basic.link/out/refcount/basic.link.rs index cc95be6e1a..abadb49c60 100644 --- a/tests/std/basic/basic.link/out/refcount/basic.link.rs +++ b/tests/std/basic/basic.link/out/refcount/basic.link.rs @@ -51,6 +51,9 @@ impl Default for anon_13 { } } } +thread_local!( + pub static anon_13: Value = Rc::new(RefCell::new(::default())); +); pub fn test_14() { anon_13::whole(anon_13.with(|v| v.as_pointer())).write(5); ({ set_whole_in_b_15(6) }); @@ -127,99 +130,97 @@ pub fn test_34() { assert!((balance_33.with(|rc| *rc.borrow()) == 65)); } pub fn read_remote_35() -> i32 { - let mut remote: i32 = 0_i32; - return remote; + return remote_36.with(|rc| *rc.borrow()); } -pub fn test_36() { +pub fn test_37() { assert!((({ read_remote_35() }) == 70)); - ({ set_remote_in_b_37(71) }); + ({ set_remote_in_b_38(71) }); assert!((({ read_remote_35() }) == 71)); } thread_local!( - pub static hidden_38: Value = Rc::new(RefCell::new(80)); + pub static hidden_39: Value = Rc::new(RefCell::new(80)); ); -pub fn read_hidden_through_extern_39() -> i32 { +pub fn read_hidden_through_extern_40() -> i32 { let mut hidden: i32 = 1; { - let mut hidden: i32 = 0_i32; - return hidden; + return hidden_39.with(|rc| *rc.borrow()); } panic!("ub: non-void function does not return a value") } -pub fn test_40() { - assert!((({ read_hidden_through_extern_39() }) == 80)); - hidden_38.with(|rc| *rc.borrow_mut() = 81); - assert!((({ read_hidden_through_extern_39() }) == 81)); - assert!((({ hidden_in_b_41() }) == 90)); +pub fn test_41() { + assert!((({ read_hidden_through_extern_40() }) == 80)); + hidden_39.with(|rc| *rc.borrow_mut() = 81); + assert!((({ read_hidden_through_extern_40() }) == 81)); + assert!((({ hidden_in_b_42() }) == 90)); } -pub fn next_even_42() -> i32 { - count_43.with(|rc| *rc.borrow_mut() += 2); - return count_43.with(|rc| *rc.borrow()); +pub fn next_even_43() -> i32 { + count_44.with(|rc| *rc.borrow_mut() += 2); + return count_44.with(|rc| *rc.borrow()); } -pub fn next_odd_44() -> i32 { - count_45.with(|rc| *rc.borrow_mut() += 2); - return count_45.with(|rc| *rc.borrow()); +pub fn next_odd_45() -> i32 { + count_46.with(|rc| *rc.borrow_mut() += 2); + return count_46.with(|rc| *rc.borrow()); } -pub fn test_46() { - assert!((({ next_even_42() }) == 2)); - assert!((({ next_odd_44() }) == 3)); - assert!((({ next_in_b_47() }) == 1000)); - assert!((({ next_even_42() }) == 4)); - assert!((({ next_odd_44() }) == 5)); - assert!((({ next_in_b_47() }) == 2000)); +pub fn test_47() { + assert!((({ next_even_43() }) == 2)); + assert!((({ next_odd_45() }) == 3)); + assert!((({ next_in_b_48() }) == 1000)); + assert!((({ next_even_43() }) == 4)); + assert!((({ next_odd_45() }) == 5)); + assert!((({ next_in_b_48() }) == 2000)); } thread_local!( - static count_43: Value = Rc::new(RefCell::new(0)); + static count_44: Value = Rc::new(RefCell::new(0)); ); thread_local!( - static count_45: Value = Rc::new(RefCell::new(1)); + static count_46: Value = Rc::new(RefCell::new(1)); ); -pub fn first_key_48() -> i32 { - let mut entry: Entry_49 = ::default(); +pub fn first_key_49() -> i32 { + let mut entry: Entry_50 = ::default(); return entry.key; } -pub fn second_key_plus_value_50() -> i32 { - let mut entry: Entry_51 = ::default(); +pub fn second_key_plus_value_51() -> i32 { + let mut entry: Entry_52 = ::default(); return (entry.key + entry.value); } -pub fn test_52() { - assert!((({ first_key_48() }) == 1)); - assert!((({ second_key_plus_value_50() }) == 32)); - assert!((({ key_in_b_53() }) == 400)); +pub fn test_53() { + assert!((({ first_key_49() }) == 1)); + assert!((({ second_key_plus_value_51() }) == 32)); + assert!((({ key_in_b_54() }) == 400)); } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] #[byte_size(4)] -pub struct Entry_49 { +pub struct Entry_50 { #[offset(0)] pub key: i32, } -impl Default for Entry_49 { +impl Default for Entry_50 { fn default() -> Self { - { Entry_49 { key: 1 } } + { Entry_50 { key: 1 } } } } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] #[byte_size(8)] -pub struct Entry_51 { +pub struct Entry_52 { #[offset(0)] pub key: i32, #[offset(4)] pub value: i32, } -impl Default for Entry_51 { +impl Default for Entry_52 { fn default() -> Self { - { Entry_51 { key: 2, value: 30 } } + { Entry_52 { key: 2, value: 30 } } } } -pub fn test_55() { +pub fn test_56() { assert!( (({ let __idx0 = (1) as usize; - table_54.with(|rc| rc.borrow()[__idx0]) + table_55.with(|rc| rc.borrow()[__idx0]) }) == 2) ); - (*table_54.with(Value::clone).borrow_mut())[(2) as usize] = 30; - assert!((({ table_sum_in_b_56() }) == 33)); + (*table_55.with(Value::clone).borrow_mut())[(2) as usize] = 30; + assert!((({ table_sum_in_b_57() }) == 33)); } pub fn main() { __cpp2rust_init_globals(); @@ -236,27 +237,27 @@ fn main_0() -> i32 { ({ test_28() }); ({ test_31() }); ({ test_34() }); - ({ test_36() }); - ({ test_40() }); - ({ test_46() }); - ({ test_52() }); - ({ test_55() }); + ({ test_37() }); + ({ test_41() }); + ({ test_47() }); + ({ test_53() }); + ({ test_56() }); return 0; } -pub fn pick_57() -> i32 { +pub fn pick_58() -> i32 { return 2; } pub fn pick_in_b_2() -> i32 { - return ({ pick_57() }); + return ({ pick_58() }); } thread_local!( - pub static limit_58: Value = Rc::new(RefCell::new(20)); + pub static limit_59: Value = Rc::new(RefCell::new(20)); ); pub fn limit_in_b_5() -> i32 { - return limit_58.with(|rc| *rc.borrow()); + return limit_59.with(|rc| *rc.borrow()); } pub fn limit_address_in_b_6() -> Ptr { - return (limit_58.with(|v| v.as_pointer())); + return (limit_59.with(|v| v.as_pointer())); } thread_local!( pub static threshold_7: Value = Rc::new(RefCell::new(30)); @@ -272,12 +273,12 @@ pub fn ceiling_address_in_b_12() -> Ptr { } #[derive(VaArg, FnPtrArg, ByteRepr, Clone)] #[byte_size(4)] -pub struct anon_59 { +pub struct anon_60 { #[offset(0)] #[byte_size(4)] __bytes: Box<[u8]>, } -impl anon_59 { +impl anon_60 { pub fn whole(this: Ptr) -> Ptr { this.reinterpret_cast() } @@ -285,30 +286,33 @@ impl anon_59 { this.reinterpret_cast() } } -impl Default for anon_59 { +impl Default for anon_60 { fn default() -> Self { - anon_59 { + anon_60 { __bytes: Box::from([0u8; 4]), } } } +thread_local!( + pub static anon_60: Value = Rc::new(RefCell::new(::default())); +); pub fn set_whole_in_b_15(mut value: i32) { - anon_59::whole(anon_59.with(|v| v.as_pointer())).write(value); + anon_60::whole(anon_60.with(|v| v.as_pointer())).write(value); } pub fn whole_in_b_16() -> i32 { - return (anon_59::whole(anon_59.with(|v| v.as_pointer())).read()); + return (anon_60::whole(anon_60.with(|v| v.as_pointer())).read()); } thread_local!( - pub static counter_60: Value = Rc::new(RefCell::new(50)); + pub static counter_61: Value = Rc::new(RefCell::new(50)); ); -pub fn bump_61() -> i32 { - return (*counter_60.with(Value::clone).borrow_mut()).prefix_inc(); +pub fn bump_62() -> i32 { + return (*counter_61.with(Value::clone).borrow_mut()).prefix_inc(); } thread_local!( - pub static depth_62: Value = Rc::new(RefCell::new(4)); + pub static depth_63: Value = Rc::new(RefCell::new(4)); ); pub fn bump_in_b_21() -> i32 { - return ({ bump_61() }); + return ({ bump_62() }); } pub fn record_id_in_b_22() -> i32 { let mut record: p4_unnamed_namespaces_in_two_files_Record = @@ -316,7 +320,7 @@ pub fn record_id_in_b_22() -> i32 { return (record.id as i32); } pub fn depth_in_b_23() -> i32 { - return depth_62.with(|rc| *rc.borrow()); + return depth_63.with(|rc| *rc.borrow()); } thread_local!( pub static shared_total_24: Value = Rc::new(RefCell::new(5)); @@ -332,7 +336,7 @@ pub fn raise_29(mut by: i32) -> i32 { return level_27.with(|rc| *rc.borrow()); } thread_local!( - pub static total_63: Value = Rc::new(RefCell::new(100)); + pub static total_64: Value = Rc::new(RefCell::new(100)); ); pub fn add_in_b_32(mut amount: i32) -> i32 { let tally: Value = Rc::new(RefCell::new( @@ -352,25 +356,25 @@ impl p5_members_of_class_with_external_linkage_Ledger { } } thread_local!( - pub static remote_64: Value = Rc::new(RefCell::new(70)); + pub static remote_36: Value = Rc::new(RefCell::new(70)); ); -pub fn set_remote_in_b_37(mut value: i32) { - remote_64.with(|rc| *rc.borrow_mut() = value); +pub fn set_remote_in_b_38(mut value: i32) { + remote_36.with(|rc| *rc.borrow_mut() = value); } thread_local!( pub static hidden_65: Value = Rc::new(RefCell::new(90)); ); -pub fn hidden_in_b_41() -> i32 { +pub fn hidden_in_b_42() -> i32 { return hidden_65.with(|rc| *rc.borrow()); } -pub fn next_in_b_47() -> i32 { +pub fn next_in_b_48() -> i32 { count_66.with(|rc| *rc.borrow_mut() += 1000); return count_66.with(|rc| *rc.borrow()); } thread_local!( static count_66: Value = Rc::new(RefCell::new(0)); ); -pub fn key_in_b_53() -> i32 { +pub fn key_in_b_54() -> i32 { let mut entry: Entry_67 = ::default(); return (entry.key as i32); } @@ -386,18 +390,18 @@ impl Default for Entry_67 { } } thread_local!( - pub static table_54: Value> = Rc::new(RefCell::new(Box::new([1, 2, 3]))); + pub static table_55: Value> = Rc::new(RefCell::new(Box::new([1, 2, 3]))); ); -pub fn table_sum_in_b_56() -> i32 { +pub fn table_sum_in_b_57() -> i32 { return ((({ let __idx0 = (0) as usize; - table_54.with(|rc| rc.borrow()[__idx0]) + table_55.with(|rc| rc.borrow()[__idx0]) }) + ({ let __idx0 = (1) as usize; - table_54.with(|rc| rc.borrow()[__idx0]) + table_55.with(|rc| rc.borrow()[__idx0]) })) + ({ let __idx0 = (2) as usize; - table_54.with(|rc| rc.borrow()[__idx0]) + table_55.with(|rc| rc.borrow()[__idx0]) })); } pub trait p5_members_of_classes_in_unnamed_namespaces_TallyImpl { @@ -411,26 +415,28 @@ impl p5_members_of_classes_in_unnamed_namespaces_TallyImpl return total_30.with(|rc| *rc.borrow()); } fn add(&self, mut amount: i32) -> i32 { - total_63.with(|rc| *rc.borrow_mut() += (amount * 2)); - return total_63.with(|rc| *rc.borrow()); + total_64.with(|rc| *rc.borrow_mut() += (amount * 2)); + return total_64.with(|rc| *rc.borrow()); } } pub fn __cpp2rust_init_globals() { let _ = limit_3.with(|_| ()); + let _ = anon_13.with(|_| ()); let _ = counter_17.with(|_| ()); let _ = depth_19.with(|_| ()); let _ = total_30.with(|_| ()); - let _ = hidden_38.with(|_| ()); - let _ = limit_58.with(|_| ()); + let _ = hidden_39.with(|_| ()); + let _ = limit_59.with(|_| ()); let _ = threshold_7.with(|_| ()); let _ = ceiling_10.with(|_| ()); - let _ = counter_60.with(|_| ()); - let _ = depth_62.with(|_| ()); + let _ = anon_60.with(|_| ()); + let _ = counter_61.with(|_| ()); + let _ = depth_63.with(|_| ()); let _ = shared_total_24.with(|_| ()); let _ = level_27.with(|_| ()); - let _ = total_63.with(|_| ()); + let _ = total_64.with(|_| ()); let _ = balance_33.with(|_| ()); - let _ = remote_64.with(|_| ()); + let _ = remote_36.with(|_| ()); let _ = hidden_65.with(|_| ()); - let _ = table_54.with(|_| ()); + let _ = table_55.with(|_| ()); } diff --git a/tests/std/basic/basic.link/out/unsafe/basic.link.rs b/tests/std/basic/basic.link/out/unsafe/basic.link.rs index 6c71741c77..f4fcb0685e 100644 --- a/tests/std/basic/basic.link/out/unsafe/basic.link.rs +++ b/tests/std/basic/basic.link/out/unsafe/basic.link.rs @@ -47,6 +47,8 @@ impl Default for anon_13 { unsafe { std::mem::zeroed() } } } +pub static mut anon_13: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { ::default() }); pub unsafe fn test_14() { (*std::cell::LazyCell::force_mut(&mut *&raw mut anon_13)).whole = 5; (unsafe { set_whole_in_b_15(6) }); @@ -121,85 +123,83 @@ pub unsafe fn test_34() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut balance_33)) == (65))); } pub unsafe fn read_remote_35() -> i32 { - let mut remote: i32 = 0_i32; - return remote; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut remote_36)); } -pub unsafe fn test_36() { +pub unsafe fn test_37() { assert!(((unsafe { read_remote_35() }) == (70))); - (unsafe { set_remote_in_b_37(71) }); + (unsafe { set_remote_in_b_38(71) }); assert!(((unsafe { read_remote_35() }) == (71))); } -pub static mut hidden_38: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 80 }); -pub unsafe fn read_hidden_through_extern_39() -> i32 { +pub static mut hidden_39: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 80 }); +pub unsafe fn read_hidden_through_extern_40() -> i32 { let mut hidden: i32 = 1; { - let mut hidden: i32 = 0_i32; - return hidden; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut hidden_39)); } panic!("ub: non-void function does not return a value") } -pub unsafe fn test_40() { - assert!(((unsafe { read_hidden_through_extern_39() }) == (80))); - (*std::cell::LazyCell::force_mut(&mut *&raw mut hidden_38)) = 81; - assert!(((unsafe { read_hidden_through_extern_39() }) == (81))); - assert!(((unsafe { hidden_in_b_41() }) == (90))); -} -pub unsafe fn next_even_42() -> i32 { - (*std::cell::LazyCell::force_mut(&mut *&raw mut count_43)) += 2; - return (*std::cell::LazyCell::force_mut(&mut *&raw mut count_43)); -} -pub unsafe fn next_odd_44() -> i32 { - (*std::cell::LazyCell::force_mut(&mut *&raw mut count_45)) += 2; - return (*std::cell::LazyCell::force_mut(&mut *&raw mut count_45)); -} -pub unsafe fn test_46() { - assert!(((unsafe { next_even_42() }) == (2))); - assert!(((unsafe { next_odd_44() }) == (3))); - assert!(((unsafe { next_in_b_47() }) == (1000))); - assert!(((unsafe { next_even_42() }) == (4))); - assert!(((unsafe { next_odd_44() }) == (5))); - assert!(((unsafe { next_in_b_47() }) == (2000))); -} -static mut count_43: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -static mut count_45: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 1 }); -pub unsafe fn first_key_48() -> i32 { - let mut entry: Entry_49 = ::default(); +pub unsafe fn test_41() { + assert!(((unsafe { read_hidden_through_extern_40() }) == (80))); + (*std::cell::LazyCell::force_mut(&mut *&raw mut hidden_39)) = 81; + assert!(((unsafe { read_hidden_through_extern_40() }) == (81))); + assert!(((unsafe { hidden_in_b_42() }) == (90))); +} +pub unsafe fn next_even_43() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut count_44)) += 2; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut count_44)); +} +pub unsafe fn next_odd_45() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut count_46)) += 2; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut count_46)); +} +pub unsafe fn test_47() { + assert!(((unsafe { next_even_43() }) == (2))); + assert!(((unsafe { next_odd_45() }) == (3))); + assert!(((unsafe { next_in_b_48() }) == (1000))); + assert!(((unsafe { next_even_43() }) == (4))); + assert!(((unsafe { next_odd_45() }) == (5))); + assert!(((unsafe { next_in_b_48() }) == (2000))); +} +static mut count_44: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +static mut count_46: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 1 }); +pub unsafe fn first_key_49() -> i32 { + let mut entry: Entry_50 = ::default(); return entry.key; } -pub unsafe fn second_key_plus_value_50() -> i32 { - let mut entry: Entry_51 = ::default(); +pub unsafe fn second_key_plus_value_51() -> i32 { + let mut entry: Entry_52 = ::default(); return ((entry.key) + (entry.value)); } -pub unsafe fn test_52() { - assert!(((unsafe { first_key_48() }) == (1))); - assert!(((unsafe { second_key_plus_value_50() }) == (32))); - assert!(((unsafe { key_in_b_53() }) == (400))); +pub unsafe fn test_53() { + assert!(((unsafe { first_key_49() }) == (1))); + assert!(((unsafe { second_key_plus_value_51() }) == (32))); + assert!(((unsafe { key_in_b_54() }) == (400))); } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg)] -pub struct Entry_49 { +pub struct Entry_50 { pub key: i32, } -impl Default for Entry_49 { +impl Default for Entry_50 { fn default() -> Self { - unsafe { Entry_49 { key: 1 } } + unsafe { Entry_50 { key: 1 } } } } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg)] -pub struct Entry_51 { +pub struct Entry_52 { pub key: i32, pub value: i32, } -impl Default for Entry_51 { +impl Default for Entry_52 { fn default() -> Self { - unsafe { Entry_51 { key: 2, value: 30 } } + unsafe { Entry_52 { key: 2, value: 30 } } } } -pub unsafe fn test_55() { - assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut table_54))[(1) as usize]) == (2))); - (*std::cell::LazyCell::force_mut(&mut *&raw mut table_54))[(2) as usize] = 30; - assert!(((unsafe { table_sum_in_b_56() }) == (33))); +pub unsafe fn test_56() { + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut table_55))[(1) as usize]) == (2))); + (*std::cell::LazyCell::force_mut(&mut *&raw mut table_55))[(2) as usize] = 30; + assert!(((unsafe { table_sum_in_b_57() }) == (33))); } pub fn main() { unsafe { @@ -218,25 +218,25 @@ unsafe fn main_0() -> i32 { (unsafe { test_28() }); (unsafe { test_31() }); (unsafe { test_34() }); - (unsafe { test_36() }); - (unsafe { test_40() }); - (unsafe { test_46() }); - (unsafe { test_52() }); - (unsafe { test_55() }); + (unsafe { test_37() }); + (unsafe { test_41() }); + (unsafe { test_47() }); + (unsafe { test_53() }); + (unsafe { test_56() }); return 0; } -pub unsafe fn pick_57() -> i32 { +pub unsafe fn pick_58() -> i32 { return 2; } pub unsafe fn pick_in_b_2() -> i32 { - return (unsafe { pick_57() }); + return (unsafe { pick_58() }); } -pub static mut limit_58: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 20 }); +pub static mut limit_59: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 20 }); pub unsafe fn limit_in_b_5() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut limit_58)); + return (*std::cell::LazyCell::force_mut(&mut *&raw mut limit_59)); } pub unsafe fn limit_address_in_b_6() -> *const i32 { - return (&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut limit_58)) as *const i32); + return (&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut limit_59)) as *const i32); } pub static mut threshold_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 30 }); pub unsafe fn threshold_address_in_b_9() -> *const i32 { @@ -249,28 +249,30 @@ pub unsafe fn ceiling_address_in_b_12() -> *const i32 { } #[repr(C)] #[derive(Copy, Clone, FnPtrArg, VaArg)] -pub union anon_59 { +pub union anon_60 { pub whole: i32, pub fraction: f32, } -impl Default for anon_59 { +impl Default for anon_60 { fn default() -> Self { unsafe { std::mem::zeroed() } } } +pub static mut anon_60: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { ::default() }); pub unsafe fn set_whole_in_b_15(mut value: i32) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut anon_59)).whole = value; + (*std::cell::LazyCell::force_mut(&mut *&raw mut anon_60)).whole = value; } pub unsafe fn whole_in_b_16() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut anon_59)).whole; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut anon_60)).whole; } -pub static mut counter_60: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 50 }); -pub unsafe fn bump_61() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut counter_60)).prefix_inc(); +pub static mut counter_61: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 50 }); +pub unsafe fn bump_62() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut counter_61)).prefix_inc(); } -pub static mut depth_62: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 4 }); +pub static mut depth_63: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 4 }); pub unsafe fn bump_in_b_21() -> i32 { - return (unsafe { bump_61() }); + return (unsafe { bump_62() }); } pub unsafe fn record_id_in_b_22() -> i32 { let mut record: p4_unnamed_namespaces_in_two_files_Record = @@ -278,7 +280,7 @@ pub unsafe fn record_id_in_b_22() -> i32 { return (record.id as i32); } pub unsafe fn depth_in_b_23() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut depth_62)); + return (*std::cell::LazyCell::force_mut(&mut *&raw mut depth_63)); } pub static mut shared_total_24: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 5 }); @@ -292,11 +294,11 @@ pub unsafe fn raise_29(mut by: i32) -> i32 { } impl p5_members_of_classes_in_unnamed_namespaces_Tally { pub unsafe fn add(&mut self, mut amount: i32) -> i32 { - (*std::cell::LazyCell::force_mut(&mut *&raw mut total_63)) += ((amount) * (2)); - return (*std::cell::LazyCell::force_mut(&mut *&raw mut total_63)); + (*std::cell::LazyCell::force_mut(&mut *&raw mut total_64)) += ((amount) * (2)); + return (*std::cell::LazyCell::force_mut(&mut *&raw mut total_64)); } } -pub static mut total_63: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); +pub static mut total_64: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); pub unsafe fn add_in_b_32(mut amount: i32) -> i32 { let mut tally: p5_members_of_classes_in_unnamed_namespaces_Tally = ::default(); @@ -309,20 +311,20 @@ impl p5_members_of_class_with_external_linkage_Ledger { return (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_33)); } } -pub static mut remote_64: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 70 }); -pub unsafe fn set_remote_in_b_37(mut value: i32) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut remote_64)) = value; +pub static mut remote_36: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 70 }); +pub unsafe fn set_remote_in_b_38(mut value: i32) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut remote_36)) = value; } pub static mut hidden_65: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 90 }); -pub unsafe fn hidden_in_b_41() -> i32 { +pub unsafe fn hidden_in_b_42() -> i32 { return (*std::cell::LazyCell::force_mut(&mut *&raw mut hidden_65)); } -pub unsafe fn next_in_b_47() -> i32 { +pub unsafe fn next_in_b_48() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut count_66)) += 1000; return (*std::cell::LazyCell::force_mut(&mut *&raw mut count_66)); } static mut count_66: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub unsafe fn key_in_b_53() -> i32 { +pub unsafe fn key_in_b_54() -> i32 { let mut entry: Entry_67 = ::default(); return (entry.key as i32); } @@ -336,29 +338,31 @@ impl Default for Entry_67 { unsafe { Entry_67 { key: 400_i64 } } } } -pub static mut table_54: std::cell::LazyCell<[i32; 3]> = +pub static mut table_55: std::cell::LazyCell<[i32; 3]> = std::cell::LazyCell::new(|| unsafe { [1, 2, 3] }); -pub unsafe fn table_sum_in_b_56() -> i32 { - return ((((*std::cell::LazyCell::force_mut(&mut *&raw mut table_54))[(0) as usize]) - + ((*std::cell::LazyCell::force_mut(&mut *&raw mut table_54))[(1) as usize])) - + ((*std::cell::LazyCell::force_mut(&mut *&raw mut table_54))[(2) as usize])); +pub unsafe fn table_sum_in_b_57() -> i32 { + return ((((*std::cell::LazyCell::force_mut(&mut *&raw mut table_55))[(0) as usize]) + + ((*std::cell::LazyCell::force_mut(&mut *&raw mut table_55))[(1) as usize])) + + ((*std::cell::LazyCell::force_mut(&mut *&raw mut table_55))[(2) as usize])); } pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const limit_3); + std::cell::LazyCell::force(&*&raw const anon_13); std::cell::LazyCell::force(&*&raw const counter_17); std::cell::LazyCell::force(&*&raw const depth_19); std::cell::LazyCell::force(&*&raw const total_30); - std::cell::LazyCell::force(&*&raw const hidden_38); - std::cell::LazyCell::force(&*&raw const limit_58); + std::cell::LazyCell::force(&*&raw const hidden_39); + std::cell::LazyCell::force(&*&raw const limit_59); std::cell::LazyCell::force(&*&raw const threshold_7); std::cell::LazyCell::force(&*&raw const ceiling_10); - std::cell::LazyCell::force(&*&raw const counter_60); - std::cell::LazyCell::force(&*&raw const depth_62); + std::cell::LazyCell::force(&*&raw const anon_60); + std::cell::LazyCell::force(&*&raw const counter_61); + std::cell::LazyCell::force(&*&raw const depth_63); std::cell::LazyCell::force(&*&raw const shared_total_24); std::cell::LazyCell::force(&*&raw const level_27); - std::cell::LazyCell::force(&*&raw const total_63); + std::cell::LazyCell::force(&*&raw const total_64); std::cell::LazyCell::force(&*&raw const balance_33); - std::cell::LazyCell::force(&*&raw const remote_64); + std::cell::LazyCell::force(&*&raw const remote_36); std::cell::LazyCell::force(&*&raw const hidden_65); - std::cell::LazyCell::force(&*&raw const table_54); + std::cell::LazyCell::force(&*&raw const table_55); } From 3bb21bf934a0836cbe6bac428c7286af82bc41d6 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Mon, 16 Nov 2026 21:41:58 +0000 Subject: [PATCH 3/4] Update tests --- .../basic.link/out/refcount/basic.link.rs | 371 ++++++++++-------- .../basic/basic.link/out/unsafe/basic.link.rs | 359 +++++++++-------- 2 files changed, 390 insertions(+), 340 deletions(-) diff --git a/tests/std/basic/basic.link/out/refcount/basic.link.rs b/tests/std/basic/basic.link/out/refcount/basic.link.rs index abadb49c60..b4d56730ed 100644 --- a/tests/std/basic/basic.link/out/refcount/basic.link.rs +++ b/tests/std/basic/basic.link/out/refcount/basic.link.rs @@ -68,159 +68,160 @@ pub fn bump_18() -> i32 { } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] #[byte_size(4)] -pub struct p4_unnamed_namespaces_in_two_files_Record { +pub struct p4_unnamed_namespaces_in_two_files_Record_19 { #[offset(0)] pub id: i32, } -impl Default for p4_unnamed_namespaces_in_two_files_Record { +impl Default for p4_unnamed_namespaces_in_two_files_Record_19 { fn default() -> Self { - { p4_unnamed_namespaces_in_two_files_Record { id: 100 } } + { p4_unnamed_namespaces_in_two_files_Record_19 { id: 100 } } } } thread_local!( - pub static depth_19: Value = Rc::new(RefCell::new(3)); + pub static depth_20: Value = Rc::new(RefCell::new(3)); ); -pub fn test_20() { +pub fn test_21() { assert!((({ bump_18() }) == 2)); - assert!((({ bump_in_b_21() }) == 51)); + assert!((({ bump_in_b_22() }) == 51)); assert!((counter_17.with(|rc| *rc.borrow()) == 2)); - let mut record: p4_unnamed_namespaces_in_two_files_Record = - ::default(); + let mut record: p4_unnamed_namespaces_in_two_files_Record_19 = + ::default(); assert!((record.id == 100)); - assert!((({ record_id_in_b_22() }) == 200)); - assert!((depth_19.with(|rc| *rc.borrow()) == 3)); - assert!((({ depth_in_b_23() }) == 4)); -} -pub fn test_25() { - assert!((shared_total_24.with(|rc| *rc.borrow()) == 5)); - shared_total_24.with(|rc| *rc.borrow_mut() = 7); - ({ add_in_b_26(3) }); - assert!((shared_total_24.with(|rc| *rc.borrow()) == 10)); -} -pub fn test_28() { - assert!((level_27.with(|rc| *rc.borrow()) == 1)); - assert!((({ raise_29(2,) }) == 3)); - level_27.with(|rc| *rc.borrow_mut() = 10); - assert!((({ raise_29(1,) }) == 11)); + assert!((({ record_id_in_b_23() }) == 200)); + assert!((depth_20.with(|rc| *rc.borrow()) == 3)); + assert!((({ depth_in_b_24() }) == 4)); +} +pub fn test_26() { + assert!((shared_total_25.with(|rc| *rc.borrow()) == 5)); + shared_total_25.with(|rc| *rc.borrow_mut() = 7); + ({ add_in_b_27(3) }); + assert!((shared_total_25.with(|rc| *rc.borrow()) == 10)); +} +pub fn test_29() { + assert!((level_28.with(|rc| *rc.borrow()) == 1)); + assert!((({ raise_30(2,) }) == 3)); + level_28.with(|rc| *rc.borrow_mut() = 10); + assert!((({ raise_30(1,) }) == 11)); } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(1)] -pub struct p5_members_of_classes_in_unnamed_namespaces_Tally {} +pub struct p5_members_of_classes_in_unnamed_namespaces_Tally_31 {} thread_local!( - pub static total_30: Value = Rc::new(RefCell::new(10)); + pub static total_32: Value = Rc::new(RefCell::new(10)); ); -pub fn test_31() { - let tally: Value = Rc::new(RefCell::new( - ::default(), +pub fn test_33() { + let tally: Value = Rc::new(RefCell::new( + ::default(), )); assert!( - (({ p5_members_of_classes_in_unnamed_namespaces_TallyImpl::add(&tally.as_pointer(), 1,) }) - == 11) + (({ + p5_members_of_classes_in_unnamed_namespaces_Tally_31Impl::add(&tally.as_pointer(), 1) + }) == 11) ); - assert!((({ add_in_b_32(1,) }) == 102)); - assert!((total_30.with(|rc| *rc.borrow()) == 11)); + assert!((({ add_in_b_34(1,) }) == 102)); + assert!((total_32.with(|rc| *rc.borrow()) == 11)); } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p5_members_of_class_with_external_linkage_Ledger {} -pub fn test_34() { - assert!((balance_33.with(|rc| *rc.borrow()) == 50)); - balance_33.with(|rc| *rc.borrow_mut() = 60); +pub fn test_36() { + assert!((balance_35.with(|rc| *rc.borrow()) == 50)); + balance_35.with(|rc| *rc.borrow_mut() = 60); assert!((({ p5_members_of_class_with_external_linkage_Ledger::deposit(5,) }) == 65)); - assert!((balance_33.with(|rc| *rc.borrow()) == 65)); + assert!((balance_35.with(|rc| *rc.borrow()) == 65)); } -pub fn read_remote_35() -> i32 { - return remote_36.with(|rc| *rc.borrow()); +pub fn read_remote_37() -> i32 { + return remote_38.with(|rc| *rc.borrow()); } -pub fn test_37() { - assert!((({ read_remote_35() }) == 70)); - ({ set_remote_in_b_38(71) }); - assert!((({ read_remote_35() }) == 71)); +pub fn test_39() { + assert!((({ read_remote_37() }) == 70)); + ({ set_remote_in_b_40(71) }); + assert!((({ read_remote_37() }) == 71)); } thread_local!( - pub static hidden_39: Value = Rc::new(RefCell::new(80)); + pub static hidden_41: Value = Rc::new(RefCell::new(80)); ); -pub fn read_hidden_through_extern_40() -> i32 { +pub fn read_hidden_through_extern_42() -> i32 { let mut hidden: i32 = 1; { - return hidden_39.with(|rc| *rc.borrow()); + return hidden_41.with(|rc| *rc.borrow()); } panic!("ub: non-void function does not return a value") } -pub fn test_41() { - assert!((({ read_hidden_through_extern_40() }) == 80)); - hidden_39.with(|rc| *rc.borrow_mut() = 81); - assert!((({ read_hidden_through_extern_40() }) == 81)); - assert!((({ hidden_in_b_42() }) == 90)); -} -pub fn next_even_43() -> i32 { - count_44.with(|rc| *rc.borrow_mut() += 2); - return count_44.with(|rc| *rc.borrow()); +pub fn test_43() { + assert!((({ read_hidden_through_extern_42() }) == 80)); + hidden_41.with(|rc| *rc.borrow_mut() = 81); + assert!((({ read_hidden_through_extern_42() }) == 81)); + assert!((({ hidden_in_b_44() }) == 90)); } -pub fn next_odd_45() -> i32 { +pub fn next_even_45() -> i32 { count_46.with(|rc| *rc.borrow_mut() += 2); return count_46.with(|rc| *rc.borrow()); } -pub fn test_47() { - assert!((({ next_even_43() }) == 2)); - assert!((({ next_odd_45() }) == 3)); - assert!((({ next_in_b_48() }) == 1000)); - assert!((({ next_even_43() }) == 4)); - assert!((({ next_odd_45() }) == 5)); - assert!((({ next_in_b_48() }) == 2000)); +pub fn next_odd_47() -> i32 { + count_48.with(|rc| *rc.borrow_mut() += 2); + return count_48.with(|rc| *rc.borrow()); +} +pub fn test_49() { + assert!((({ next_even_45() }) == 2)); + assert!((({ next_odd_47() }) == 3)); + assert!((({ next_in_b_50() }) == 1000)); + assert!((({ next_even_45() }) == 4)); + assert!((({ next_odd_47() }) == 5)); + assert!((({ next_in_b_50() }) == 2000)); } thread_local!( - static count_44: Value = Rc::new(RefCell::new(0)); + static count_46: Value = Rc::new(RefCell::new(0)); ); thread_local!( - static count_46: Value = Rc::new(RefCell::new(1)); + static count_48: Value = Rc::new(RefCell::new(1)); ); -pub fn first_key_49() -> i32 { - let mut entry: Entry_50 = ::default(); +pub fn first_key_51() -> i32 { + let mut entry: Entry_52 = ::default(); return entry.key; } -pub fn second_key_plus_value_51() -> i32 { - let mut entry: Entry_52 = ::default(); +pub fn second_key_plus_value_53() -> i32 { + let mut entry: Entry_54 = ::default(); return (entry.key + entry.value); } -pub fn test_53() { - assert!((({ first_key_49() }) == 1)); - assert!((({ second_key_plus_value_51() }) == 32)); - assert!((({ key_in_b_54() }) == 400)); +pub fn test_55() { + assert!((({ first_key_51() }) == 1)); + assert!((({ second_key_plus_value_53() }) == 32)); + assert!((({ key_in_b_56() }) == 400)); } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] #[byte_size(4)] -pub struct Entry_50 { +pub struct Entry_52 { #[offset(0)] pub key: i32, } -impl Default for Entry_50 { +impl Default for Entry_52 { fn default() -> Self { - { Entry_50 { key: 1 } } + { Entry_52 { key: 1 } } } } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] #[byte_size(8)] -pub struct Entry_52 { +pub struct Entry_54 { #[offset(0)] pub key: i32, #[offset(4)] pub value: i32, } -impl Default for Entry_52 { +impl Default for Entry_54 { fn default() -> Self { - { Entry_52 { key: 2, value: 30 } } + { Entry_54 { key: 2, value: 30 } } } } -pub fn test_56() { +pub fn test_58() { assert!( (({ let __idx0 = (1) as usize; - table_55.with(|rc| rc.borrow()[__idx0]) + table_57.with(|rc| rc.borrow()[__idx0]) }) == 2) ); - (*table_55.with(Value::clone).borrow_mut())[(2) as usize] = 30; - assert!((({ table_sum_in_b_57() }) == 33)); + (*table_57.with(Value::clone).borrow_mut())[(2) as usize] = 30; + assert!((({ table_sum_in_b_59() }) == 33)); } pub fn main() { __cpp2rust_init_globals(); @@ -232,32 +233,32 @@ fn main_0() -> i32 { ({ test_8() }); ({ test_11() }); ({ test_14() }); - ({ test_20() }); - ({ test_25() }); - ({ test_28() }); - ({ test_31() }); - ({ test_34() }); - ({ test_37() }); - ({ test_41() }); - ({ test_47() }); - ({ test_53() }); - ({ test_56() }); + ({ test_21() }); + ({ test_26() }); + ({ test_29() }); + ({ test_33() }); + ({ test_36() }); + ({ test_39() }); + ({ test_43() }); + ({ test_49() }); + ({ test_55() }); + ({ test_58() }); return 0; } -pub fn pick_58() -> i32 { +pub fn pick_60() -> i32 { return 2; } pub fn pick_in_b_2() -> i32 { - return ({ pick_58() }); + return ({ pick_60() }); } thread_local!( - pub static limit_59: Value = Rc::new(RefCell::new(20)); + pub static limit_61: Value = Rc::new(RefCell::new(20)); ); pub fn limit_in_b_5() -> i32 { - return limit_59.with(|rc| *rc.borrow()); + return limit_61.with(|rc| *rc.borrow()); } pub fn limit_address_in_b_6() -> Ptr { - return (limit_59.with(|v| v.as_pointer())); + return (limit_61.with(|v| v.as_pointer())); } thread_local!( pub static threshold_7: Value = Rc::new(RefCell::new(30)); @@ -273,12 +274,12 @@ pub fn ceiling_address_in_b_12() -> Ptr { } #[derive(VaArg, FnPtrArg, ByteRepr, Clone)] #[byte_size(4)] -pub struct anon_60 { +pub struct anon_62 { #[offset(0)] #[byte_size(4)] __bytes: Box<[u8]>, } -impl anon_60 { +impl anon_62 { pub fn whole(this: Ptr) -> Ptr { this.reinterpret_cast() } @@ -286,157 +287,185 @@ impl anon_60 { this.reinterpret_cast() } } -impl Default for anon_60 { +impl Default for anon_62 { fn default() -> Self { - anon_60 { + anon_62 { __bytes: Box::from([0u8; 4]), } } } thread_local!( - pub static anon_60: Value = Rc::new(RefCell::new(::default())); + pub static anon_62: Value = Rc::new(RefCell::new(::default())); ); pub fn set_whole_in_b_15(mut value: i32) { - anon_60::whole(anon_60.with(|v| v.as_pointer())).write(value); + anon_62::whole(anon_62.with(|v| v.as_pointer())).write(value); } pub fn whole_in_b_16() -> i32 { - return (anon_60::whole(anon_60.with(|v| v.as_pointer())).read()); + return (anon_62::whole(anon_62.with(|v| v.as_pointer())).read()); } thread_local!( - pub static counter_61: Value = Rc::new(RefCell::new(50)); + pub static counter_63: Value = Rc::new(RefCell::new(50)); ); -pub fn bump_62() -> i32 { - return (*counter_61.with(Value::clone).borrow_mut()).prefix_inc(); +pub fn bump_64() -> i32 { + return (*counter_63.with(Value::clone).borrow_mut()).prefix_inc(); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(16)] +pub struct p4_unnamed_namespaces_in_two_files_Record_65 { + #[offset(0)] + pub id: i64, + #[offset(8)] + pub extra: i32, +} +impl Default for p4_unnamed_namespaces_in_two_files_Record_65 { + fn default() -> Self { + { + p4_unnamed_namespaces_in_two_files_Record_65 { + id: 200_i64, + extra: 1, + } + } + } } thread_local!( - pub static depth_63: Value = Rc::new(RefCell::new(4)); + pub static depth_66: Value = Rc::new(RefCell::new(4)); ); -pub fn bump_in_b_21() -> i32 { - return ({ bump_62() }); +pub fn bump_in_b_22() -> i32 { + return ({ bump_64() }); } -pub fn record_id_in_b_22() -> i32 { - let mut record: p4_unnamed_namespaces_in_two_files_Record = - ::default(); +pub fn record_id_in_b_23() -> i32 { + let mut record: p4_unnamed_namespaces_in_two_files_Record_65 = + ::default(); return (record.id as i32); } -pub fn depth_in_b_23() -> i32 { - return depth_63.with(|rc| *rc.borrow()); +pub fn depth_in_b_24() -> i32 { + return depth_66.with(|rc| *rc.borrow()); } thread_local!( - pub static shared_total_24: Value = Rc::new(RefCell::new(5)); + pub static shared_total_25: Value = Rc::new(RefCell::new(5)); ); -pub fn add_in_b_26(mut amount: i32) { - shared_total_24.with(|rc| *rc.borrow_mut() += amount); +pub fn add_in_b_27(mut amount: i32) { + shared_total_25.with(|rc| *rc.borrow_mut() += amount); } thread_local!( - pub static level_27: Value = Rc::new(RefCell::new(1)); + pub static level_28: Value = Rc::new(RefCell::new(1)); ); -pub fn raise_29(mut by: i32) -> i32 { - level_27.with(|rc| *rc.borrow_mut() += by); - return level_27.with(|rc| *rc.borrow()); +pub fn raise_30(mut by: i32) -> i32 { + level_28.with(|rc| *rc.borrow_mut() += by); + return level_28.with(|rc| *rc.borrow()); } +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(1)] +pub struct p5_members_of_classes_in_unnamed_namespaces_Tally_67 {} thread_local!( - pub static total_64: Value = Rc::new(RefCell::new(100)); + pub static total_68: Value = Rc::new(RefCell::new(100)); ); -pub fn add_in_b_32(mut amount: i32) -> i32 { - let tally: Value = Rc::new(RefCell::new( - ::default(), +pub fn add_in_b_34(mut amount: i32) -> i32 { + let tally: Value = Rc::new(RefCell::new( + ::default(), )); return ({ - p5_members_of_classes_in_unnamed_namespaces_TallyImpl::add(&tally.as_pointer(), amount) + p5_members_of_classes_in_unnamed_namespaces_Tally_67Impl::add(&tally.as_pointer(), amount) }); } thread_local!( - pub static balance_33: Value = Rc::new(RefCell::new(50)); + pub static balance_35: Value = Rc::new(RefCell::new(50)); ); impl p5_members_of_class_with_external_linkage_Ledger { pub fn deposit(mut amount: i32) -> i32 { - balance_33.with(|rc| *rc.borrow_mut() += amount); - return balance_33.with(|rc| *rc.borrow()); + balance_35.with(|rc| *rc.borrow_mut() += amount); + return balance_35.with(|rc| *rc.borrow()); } } thread_local!( - pub static remote_36: Value = Rc::new(RefCell::new(70)); + pub static remote_38: Value = Rc::new(RefCell::new(70)); ); -pub fn set_remote_in_b_38(mut value: i32) { - remote_36.with(|rc| *rc.borrow_mut() = value); +pub fn set_remote_in_b_40(mut value: i32) { + remote_38.with(|rc| *rc.borrow_mut() = value); } thread_local!( - pub static hidden_65: Value = Rc::new(RefCell::new(90)); + pub static hidden_69: Value = Rc::new(RefCell::new(90)); ); -pub fn hidden_in_b_42() -> i32 { - return hidden_65.with(|rc| *rc.borrow()); +pub fn hidden_in_b_44() -> i32 { + return hidden_69.with(|rc| *rc.borrow()); } -pub fn next_in_b_48() -> i32 { - count_66.with(|rc| *rc.borrow_mut() += 1000); - return count_66.with(|rc| *rc.borrow()); +pub fn next_in_b_50() -> i32 { + count_70.with(|rc| *rc.borrow_mut() += 1000); + return count_70.with(|rc| *rc.borrow()); } thread_local!( - static count_66: Value = Rc::new(RefCell::new(0)); + static count_70: Value = Rc::new(RefCell::new(0)); ); -pub fn key_in_b_54() -> i32 { - let mut entry: Entry_67 = ::default(); +pub fn key_in_b_56() -> i32 { + let mut entry: Entry_71 = ::default(); return (entry.key as i32); } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] #[byte_size(8)] -pub struct Entry_67 { +pub struct Entry_71 { #[offset(0)] pub key: i64, } -impl Default for Entry_67 { +impl Default for Entry_71 { fn default() -> Self { - { Entry_67 { key: 400_i64 } } + { Entry_71 { key: 400_i64 } } } } thread_local!( - pub static table_55: Value> = Rc::new(RefCell::new(Box::new([1, 2, 3]))); + pub static table_57: Value> = Rc::new(RefCell::new(Box::new([1, 2, 3]))); ); -pub fn table_sum_in_b_57() -> i32 { +pub fn table_sum_in_b_59() -> i32 { return ((({ let __idx0 = (0) as usize; - table_55.with(|rc| rc.borrow()[__idx0]) + table_57.with(|rc| rc.borrow()[__idx0]) }) + ({ let __idx0 = (1) as usize; - table_55.with(|rc| rc.borrow()[__idx0]) + table_57.with(|rc| rc.borrow()[__idx0]) })) + ({ let __idx0 = (2) as usize; - table_55.with(|rc| rc.borrow()[__idx0]) + table_57.with(|rc| rc.borrow()[__idx0]) })); } -pub trait p5_members_of_classes_in_unnamed_namespaces_TallyImpl { +pub trait p5_members_of_classes_in_unnamed_namespaces_Tally_31Impl { fn add(&self, amount: i32) -> i32; } -impl p5_members_of_classes_in_unnamed_namespaces_TallyImpl - for Ptr +impl p5_members_of_classes_in_unnamed_namespaces_Tally_31Impl + for Ptr { fn add(&self, mut amount: i32) -> i32 { - total_30.with(|rc| *rc.borrow_mut() += amount); - return total_30.with(|rc| *rc.borrow()); + total_32.with(|rc| *rc.borrow_mut() += amount); + return total_32.with(|rc| *rc.borrow()); } +} +pub trait p5_members_of_classes_in_unnamed_namespaces_Tally_67Impl { + fn add(&self, amount: i32) -> i32; +} +impl p5_members_of_classes_in_unnamed_namespaces_Tally_67Impl + for Ptr +{ fn add(&self, mut amount: i32) -> i32 { - total_64.with(|rc| *rc.borrow_mut() += (amount * 2)); - return total_64.with(|rc| *rc.borrow()); + total_68.with(|rc| *rc.borrow_mut() += (amount * 2)); + return total_68.with(|rc| *rc.borrow()); } } pub fn __cpp2rust_init_globals() { let _ = limit_3.with(|_| ()); let _ = anon_13.with(|_| ()); let _ = counter_17.with(|_| ()); - let _ = depth_19.with(|_| ()); - let _ = total_30.with(|_| ()); - let _ = hidden_39.with(|_| ()); - let _ = limit_59.with(|_| ()); + let _ = depth_20.with(|_| ()); + let _ = total_32.with(|_| ()); + let _ = hidden_41.with(|_| ()); + let _ = limit_61.with(|_| ()); let _ = threshold_7.with(|_| ()); let _ = ceiling_10.with(|_| ()); - let _ = anon_60.with(|_| ()); - let _ = counter_61.with(|_| ()); - let _ = depth_63.with(|_| ()); - let _ = shared_total_24.with(|_| ()); - let _ = level_27.with(|_| ()); - let _ = total_64.with(|_| ()); - let _ = balance_33.with(|_| ()); - let _ = remote_36.with(|_| ()); - let _ = hidden_65.with(|_| ()); - let _ = table_55.with(|_| ()); + let _ = anon_62.with(|_| ()); + let _ = counter_63.with(|_| ()); + let _ = depth_66.with(|_| ()); + let _ = shared_total_25.with(|_| ()); + let _ = level_28.with(|_| ()); + let _ = total_68.with(|_| ()); + let _ = balance_35.with(|_| ()); + let _ = remote_38.with(|_| ()); + let _ = hidden_69.with(|_| ()); + let _ = table_57.with(|_| ()); } diff --git a/tests/std/basic/basic.link/out/unsafe/basic.link.rs b/tests/std/basic/basic.link/out/unsafe/basic.link.rs index f4fcb0685e..77aac06248 100644 --- a/tests/std/basic/basic.link/out/unsafe/basic.link.rs +++ b/tests/std/basic/basic.link/out/unsafe/basic.link.rs @@ -61,145 +61,145 @@ pub unsafe fn bump_18() -> i32 { } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg)] -pub struct p4_unnamed_namespaces_in_two_files_Record { +pub struct p4_unnamed_namespaces_in_two_files_Record_19 { pub id: i32, } -impl Default for p4_unnamed_namespaces_in_two_files_Record { +impl Default for p4_unnamed_namespaces_in_two_files_Record_19 { fn default() -> Self { - unsafe { p4_unnamed_namespaces_in_two_files_Record { id: 100 } } + unsafe { p4_unnamed_namespaces_in_two_files_Record_19 { id: 100 } } } } -pub static mut depth_19: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 3 }); -pub unsafe fn test_20() { +pub static mut depth_20: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 3 }); +pub unsafe fn test_21() { assert!(((unsafe { bump_18() }) == (2))); - assert!(((unsafe { bump_in_b_21() }) == (51))); + assert!(((unsafe { bump_in_b_22() }) == (51))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut counter_17)) == (2))); - let mut record: p4_unnamed_namespaces_in_two_files_Record = - ::default(); + let mut record: p4_unnamed_namespaces_in_two_files_Record_19 = + ::default(); assert!(((record.id) == (100))); - assert!(((unsafe { record_id_in_b_22() }) == (200))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut depth_19)) == (3))); - assert!(((unsafe { depth_in_b_23() }) == (4))); -} -pub unsafe fn test_25() { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut shared_total_24)) == (5))); - (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_total_24)) = 7; - (unsafe { add_in_b_26(3) }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut shared_total_24)) == (10))); -} -pub unsafe fn test_28() { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut level_27)) == (1))); - assert!(((unsafe { raise_29(2,) }) == (3))); - (*std::cell::LazyCell::force_mut(&mut *&raw mut level_27)) = 10; - assert!(((unsafe { raise_29(1,) }) == (11))); + assert!(((unsafe { record_id_in_b_23() }) == (200))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut depth_20)) == (3))); + assert!(((unsafe { depth_in_b_24() }) == (4))); +} +pub unsafe fn test_26() { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut shared_total_25)) == (5))); + (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_total_25)) = 7; + (unsafe { add_in_b_27(3) }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut shared_total_25)) == (10))); +} +pub unsafe fn test_29() { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut level_28)) == (1))); + assert!(((unsafe { raise_30(2,) }) == (3))); + (*std::cell::LazyCell::force_mut(&mut *&raw mut level_28)) = 10; + assert!(((unsafe { raise_30(1,) }) == (11))); } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct p5_members_of_classes_in_unnamed_namespaces_Tally {} -impl p5_members_of_classes_in_unnamed_namespaces_Tally { +pub struct p5_members_of_classes_in_unnamed_namespaces_Tally_31 {} +impl p5_members_of_classes_in_unnamed_namespaces_Tally_31 { pub unsafe fn add(&mut self, mut amount: i32) -> i32 { - (*std::cell::LazyCell::force_mut(&mut *&raw mut total_30)) += amount; - return (*std::cell::LazyCell::force_mut(&mut *&raw mut total_30)); + (*std::cell::LazyCell::force_mut(&mut *&raw mut total_32)) += amount; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut total_32)); } } -pub static mut total_30: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10 }); -pub unsafe fn test_31() { - let mut tally: p5_members_of_classes_in_unnamed_namespaces_Tally = - ::default(); +pub static mut total_32: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10 }); +pub unsafe fn test_33() { + let mut tally: p5_members_of_classes_in_unnamed_namespaces_Tally_31 = + ::default(); assert!( - ((unsafe { p5_members_of_classes_in_unnamed_namespaces_Tally::add(&mut tally, 1,) }) + ((unsafe { p5_members_of_classes_in_unnamed_namespaces_Tally_31::add(&mut tally, 1,) }) == (11)) ); - assert!(((unsafe { add_in_b_32(1,) }) == (102))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_30)) == (11))); + assert!(((unsafe { add_in_b_34(1,) }) == (102))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_32)) == (11))); } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] pub struct p5_members_of_class_with_external_linkage_Ledger {} -pub unsafe fn test_34() { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut balance_33)) == (50))); - (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_33)) = 60; +pub unsafe fn test_36() { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut balance_35)) == (50))); + (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_35)) = 60; assert!(((unsafe { p5_members_of_class_with_external_linkage_Ledger::deposit(5,) }) == (65))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut balance_33)) == (65))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut balance_35)) == (65))); } -pub unsafe fn read_remote_35() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut remote_36)); +pub unsafe fn read_remote_37() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut remote_38)); } -pub unsafe fn test_37() { - assert!(((unsafe { read_remote_35() }) == (70))); - (unsafe { set_remote_in_b_38(71) }); - assert!(((unsafe { read_remote_35() }) == (71))); +pub unsafe fn test_39() { + assert!(((unsafe { read_remote_37() }) == (70))); + (unsafe { set_remote_in_b_40(71) }); + assert!(((unsafe { read_remote_37() }) == (71))); } -pub static mut hidden_39: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 80 }); -pub unsafe fn read_hidden_through_extern_40() -> i32 { +pub static mut hidden_41: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 80 }); +pub unsafe fn read_hidden_through_extern_42() -> i32 { let mut hidden: i32 = 1; { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut hidden_39)); + return (*std::cell::LazyCell::force_mut(&mut *&raw mut hidden_41)); } panic!("ub: non-void function does not return a value") } -pub unsafe fn test_41() { - assert!(((unsafe { read_hidden_through_extern_40() }) == (80))); - (*std::cell::LazyCell::force_mut(&mut *&raw mut hidden_39)) = 81; - assert!(((unsafe { read_hidden_through_extern_40() }) == (81))); - assert!(((unsafe { hidden_in_b_42() }) == (90))); +pub unsafe fn test_43() { + assert!(((unsafe { read_hidden_through_extern_42() }) == (80))); + (*std::cell::LazyCell::force_mut(&mut *&raw mut hidden_41)) = 81; + assert!(((unsafe { read_hidden_through_extern_42() }) == (81))); + assert!(((unsafe { hidden_in_b_44() }) == (90))); } -pub unsafe fn next_even_43() -> i32 { - (*std::cell::LazyCell::force_mut(&mut *&raw mut count_44)) += 2; - return (*std::cell::LazyCell::force_mut(&mut *&raw mut count_44)); -} -pub unsafe fn next_odd_45() -> i32 { +pub unsafe fn next_even_45() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut count_46)) += 2; return (*std::cell::LazyCell::force_mut(&mut *&raw mut count_46)); } -pub unsafe fn test_47() { - assert!(((unsafe { next_even_43() }) == (2))); - assert!(((unsafe { next_odd_45() }) == (3))); - assert!(((unsafe { next_in_b_48() }) == (1000))); - assert!(((unsafe { next_even_43() }) == (4))); - assert!(((unsafe { next_odd_45() }) == (5))); - assert!(((unsafe { next_in_b_48() }) == (2000))); -} -static mut count_44: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -static mut count_46: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 1 }); -pub unsafe fn first_key_49() -> i32 { - let mut entry: Entry_50 = ::default(); +pub unsafe fn next_odd_47() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut count_48)) += 2; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut count_48)); +} +pub unsafe fn test_49() { + assert!(((unsafe { next_even_45() }) == (2))); + assert!(((unsafe { next_odd_47() }) == (3))); + assert!(((unsafe { next_in_b_50() }) == (1000))); + assert!(((unsafe { next_even_45() }) == (4))); + assert!(((unsafe { next_odd_47() }) == (5))); + assert!(((unsafe { next_in_b_50() }) == (2000))); +} +static mut count_46: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +static mut count_48: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 1 }); +pub unsafe fn first_key_51() -> i32 { + let mut entry: Entry_52 = ::default(); return entry.key; } -pub unsafe fn second_key_plus_value_51() -> i32 { - let mut entry: Entry_52 = ::default(); +pub unsafe fn second_key_plus_value_53() -> i32 { + let mut entry: Entry_54 = ::default(); return ((entry.key) + (entry.value)); } -pub unsafe fn test_53() { - assert!(((unsafe { first_key_49() }) == (1))); - assert!(((unsafe { second_key_plus_value_51() }) == (32))); - assert!(((unsafe { key_in_b_54() }) == (400))); +pub unsafe fn test_55() { + assert!(((unsafe { first_key_51() }) == (1))); + assert!(((unsafe { second_key_plus_value_53() }) == (32))); + assert!(((unsafe { key_in_b_56() }) == (400))); } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg)] -pub struct Entry_50 { +pub struct Entry_52 { pub key: i32, } -impl Default for Entry_50 { +impl Default for Entry_52 { fn default() -> Self { - unsafe { Entry_50 { key: 1 } } + unsafe { Entry_52 { key: 1 } } } } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg)] -pub struct Entry_52 { +pub struct Entry_54 { pub key: i32, pub value: i32, } -impl Default for Entry_52 { +impl Default for Entry_54 { fn default() -> Self { - unsafe { Entry_52 { key: 2, value: 30 } } + unsafe { Entry_54 { key: 2, value: 30 } } } } -pub unsafe fn test_56() { - assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut table_55))[(1) as usize]) == (2))); - (*std::cell::LazyCell::force_mut(&mut *&raw mut table_55))[(2) as usize] = 30; - assert!(((unsafe { table_sum_in_b_57() }) == (33))); +pub unsafe fn test_58() { + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut table_57))[(1) as usize]) == (2))); + (*std::cell::LazyCell::force_mut(&mut *&raw mut table_57))[(2) as usize] = 30; + assert!(((unsafe { table_sum_in_b_59() }) == (33))); } pub fn main() { unsafe { @@ -213,30 +213,30 @@ unsafe fn main_0() -> i32 { (unsafe { test_8() }); (unsafe { test_11() }); (unsafe { test_14() }); - (unsafe { test_20() }); - (unsafe { test_25() }); - (unsafe { test_28() }); - (unsafe { test_31() }); - (unsafe { test_34() }); - (unsafe { test_37() }); - (unsafe { test_41() }); - (unsafe { test_47() }); - (unsafe { test_53() }); - (unsafe { test_56() }); + (unsafe { test_21() }); + (unsafe { test_26() }); + (unsafe { test_29() }); + (unsafe { test_33() }); + (unsafe { test_36() }); + (unsafe { test_39() }); + (unsafe { test_43() }); + (unsafe { test_49() }); + (unsafe { test_55() }); + (unsafe { test_58() }); return 0; } -pub unsafe fn pick_58() -> i32 { +pub unsafe fn pick_60() -> i32 { return 2; } pub unsafe fn pick_in_b_2() -> i32 { - return (unsafe { pick_58() }); + return (unsafe { pick_60() }); } -pub static mut limit_59: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 20 }); +pub static mut limit_61: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 20 }); pub unsafe fn limit_in_b_5() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut limit_59)); + return (*std::cell::LazyCell::force_mut(&mut *&raw mut limit_61)); } pub unsafe fn limit_address_in_b_6() -> *const i32 { - return (&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut limit_59)) as *const i32); + return (&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut limit_61)) as *const i32); } pub static mut threshold_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 30 }); pub unsafe fn threshold_address_in_b_9() -> *const i32 { @@ -249,120 +249,141 @@ pub unsafe fn ceiling_address_in_b_12() -> *const i32 { } #[repr(C)] #[derive(Copy, Clone, FnPtrArg, VaArg)] -pub union anon_60 { +pub union anon_62 { pub whole: i32, pub fraction: f32, } -impl Default for anon_60 { +impl Default for anon_62 { fn default() -> Self { unsafe { std::mem::zeroed() } } } -pub static mut anon_60: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { ::default() }); +pub static mut anon_62: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { ::default() }); pub unsafe fn set_whole_in_b_15(mut value: i32) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut anon_60)).whole = value; + (*std::cell::LazyCell::force_mut(&mut *&raw mut anon_62)).whole = value; } pub unsafe fn whole_in_b_16() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut anon_60)).whole; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut anon_62)).whole; } -pub static mut counter_61: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 50 }); -pub unsafe fn bump_62() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut counter_61)).prefix_inc(); +pub static mut counter_63: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 50 }); +pub unsafe fn bump_64() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut counter_63)).prefix_inc(); } -pub static mut depth_63: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 4 }); -pub unsafe fn bump_in_b_21() -> i32 { - return (unsafe { bump_62() }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct p4_unnamed_namespaces_in_two_files_Record_65 { + pub id: i64, + pub extra: i32, +} +impl Default for p4_unnamed_namespaces_in_two_files_Record_65 { + fn default() -> Self { + unsafe { + p4_unnamed_namespaces_in_two_files_Record_65 { + id: 200_i64, + extra: 1, + } + } + } } -pub unsafe fn record_id_in_b_22() -> i32 { - let mut record: p4_unnamed_namespaces_in_two_files_Record = - ::default(); +pub static mut depth_66: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 4 }); +pub unsafe fn bump_in_b_22() -> i32 { + return (unsafe { bump_64() }); +} +pub unsafe fn record_id_in_b_23() -> i32 { + let mut record: p4_unnamed_namespaces_in_two_files_Record_65 = + ::default(); return (record.id as i32); } -pub unsafe fn depth_in_b_23() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut depth_63)); +pub unsafe fn depth_in_b_24() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut depth_66)); } -pub static mut shared_total_24: std::cell::LazyCell = +pub static mut shared_total_25: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 5 }); -pub unsafe fn add_in_b_26(mut amount: i32) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_total_24)) += amount; +pub unsafe fn add_in_b_27(mut amount: i32) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_total_25)) += amount; } -pub static mut level_27: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 1 }); -pub unsafe fn raise_29(mut by: i32) -> i32 { - (*std::cell::LazyCell::force_mut(&mut *&raw mut level_27)) += by; - return (*std::cell::LazyCell::force_mut(&mut *&raw mut level_27)); +pub static mut level_28: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 1 }); +pub unsafe fn raise_30(mut by: i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut level_28)) += by; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut level_28)); } -impl p5_members_of_classes_in_unnamed_namespaces_Tally { +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p5_members_of_classes_in_unnamed_namespaces_Tally_67 {} +impl p5_members_of_classes_in_unnamed_namespaces_Tally_67 { pub unsafe fn add(&mut self, mut amount: i32) -> i32 { - (*std::cell::LazyCell::force_mut(&mut *&raw mut total_64)) += ((amount) * (2)); - return (*std::cell::LazyCell::force_mut(&mut *&raw mut total_64)); + (*std::cell::LazyCell::force_mut(&mut *&raw mut total_68)) += ((amount) * (2)); + return (*std::cell::LazyCell::force_mut(&mut *&raw mut total_68)); } } -pub static mut total_64: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); -pub unsafe fn add_in_b_32(mut amount: i32) -> i32 { - let mut tally: p5_members_of_classes_in_unnamed_namespaces_Tally = - ::default(); - return (unsafe { p5_members_of_classes_in_unnamed_namespaces_Tally::add(&mut tally, amount) }); +pub static mut total_68: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); +pub unsafe fn add_in_b_34(mut amount: i32) -> i32 { + let mut tally: p5_members_of_classes_in_unnamed_namespaces_Tally_67 = + ::default(); + return (unsafe { + p5_members_of_classes_in_unnamed_namespaces_Tally_67::add(&mut tally, amount) + }); } -pub static mut balance_33: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 50 }); +pub static mut balance_35: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 50 }); impl p5_members_of_class_with_external_linkage_Ledger { pub unsafe fn deposit(mut amount: i32) -> i32 { - (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_33)) += amount; - return (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_33)); + (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_35)) += amount; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_35)); } } -pub static mut remote_36: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 70 }); -pub unsafe fn set_remote_in_b_38(mut value: i32) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut remote_36)) = value; +pub static mut remote_38: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 70 }); +pub unsafe fn set_remote_in_b_40(mut value: i32) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut remote_38)) = value; } -pub static mut hidden_65: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 90 }); -pub unsafe fn hidden_in_b_42() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut hidden_65)); +pub static mut hidden_69: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 90 }); +pub unsafe fn hidden_in_b_44() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut hidden_69)); } -pub unsafe fn next_in_b_48() -> i32 { - (*std::cell::LazyCell::force_mut(&mut *&raw mut count_66)) += 1000; - return (*std::cell::LazyCell::force_mut(&mut *&raw mut count_66)); +pub unsafe fn next_in_b_50() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut count_70)) += 1000; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut count_70)); } -static mut count_66: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub unsafe fn key_in_b_54() -> i32 { - let mut entry: Entry_67 = ::default(); +static mut count_70: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub unsafe fn key_in_b_56() -> i32 { + let mut entry: Entry_71 = ::default(); return (entry.key as i32); } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg)] -pub struct Entry_67 { +pub struct Entry_71 { pub key: i64, } -impl Default for Entry_67 { +impl Default for Entry_71 { fn default() -> Self { - unsafe { Entry_67 { key: 400_i64 } } + unsafe { Entry_71 { key: 400_i64 } } } } -pub static mut table_55: std::cell::LazyCell<[i32; 3]> = +pub static mut table_57: std::cell::LazyCell<[i32; 3]> = std::cell::LazyCell::new(|| unsafe { [1, 2, 3] }); -pub unsafe fn table_sum_in_b_57() -> i32 { - return ((((*std::cell::LazyCell::force_mut(&mut *&raw mut table_55))[(0) as usize]) - + ((*std::cell::LazyCell::force_mut(&mut *&raw mut table_55))[(1) as usize])) - + ((*std::cell::LazyCell::force_mut(&mut *&raw mut table_55))[(2) as usize])); +pub unsafe fn table_sum_in_b_59() -> i32 { + return ((((*std::cell::LazyCell::force_mut(&mut *&raw mut table_57))[(0) as usize]) + + ((*std::cell::LazyCell::force_mut(&mut *&raw mut table_57))[(1) as usize])) + + ((*std::cell::LazyCell::force_mut(&mut *&raw mut table_57))[(2) as usize])); } pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const limit_3); std::cell::LazyCell::force(&*&raw const anon_13); std::cell::LazyCell::force(&*&raw const counter_17); - std::cell::LazyCell::force(&*&raw const depth_19); - std::cell::LazyCell::force(&*&raw const total_30); - std::cell::LazyCell::force(&*&raw const hidden_39); - std::cell::LazyCell::force(&*&raw const limit_59); + std::cell::LazyCell::force(&*&raw const depth_20); + std::cell::LazyCell::force(&*&raw const total_32); + std::cell::LazyCell::force(&*&raw const hidden_41); + std::cell::LazyCell::force(&*&raw const limit_61); std::cell::LazyCell::force(&*&raw const threshold_7); std::cell::LazyCell::force(&*&raw const ceiling_10); - std::cell::LazyCell::force(&*&raw const anon_60); - std::cell::LazyCell::force(&*&raw const counter_61); - std::cell::LazyCell::force(&*&raw const depth_63); - std::cell::LazyCell::force(&*&raw const shared_total_24); - std::cell::LazyCell::force(&*&raw const level_27); - std::cell::LazyCell::force(&*&raw const total_64); - std::cell::LazyCell::force(&*&raw const balance_33); - std::cell::LazyCell::force(&*&raw const remote_36); - std::cell::LazyCell::force(&*&raw const hidden_65); - std::cell::LazyCell::force(&*&raw const table_55); + std::cell::LazyCell::force(&*&raw const anon_62); + std::cell::LazyCell::force(&*&raw const counter_63); + std::cell::LazyCell::force(&*&raw const depth_66); + std::cell::LazyCell::force(&*&raw const shared_total_25); + std::cell::LazyCell::force(&*&raw const level_28); + std::cell::LazyCell::force(&*&raw const total_68); + std::cell::LazyCell::force(&*&raw const balance_35); + std::cell::LazyCell::force(&*&raw const remote_38); + std::cell::LazyCell::force(&*&raw const hidden_69); + std::cell::LazyCell::force(&*&raw const table_57); } From 39ed1463ffa1af613b330fd7cd87fcc0c6482206 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Mon, 16 Nov 2026 21:43:49 +0000 Subject: [PATCH 4/4] Handle anonymous namespace tags --- cpp2rust/converter/converter_lib.cpp | 5 +- cpp2rust/converter/printer.cpp | 4 +- .../basic.link/out/refcount/basic.link.rs | 52 +++++++------------ .../basic/basic.link/out/unsafe/basic.link.rs | 41 ++++++--------- 4 files changed, 40 insertions(+), 62 deletions(-) diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 80fd5acf39..6c2d9961c7 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -1201,8 +1201,9 @@ std::string GetNamedDeclAsString(const clang::NamedDecl *decl) { id = GetDeclId(var->getCanonicalDecl(), var->getFormalLinkage() != clang::Linkage::External); } else if (auto *tag = clang::dyn_cast(decl); - tag && tag->getDeclContext()->isFunctionOrMethod()) { - id = GetUniqueNumber(GetID(tag)); + tag && (tag->getDeclContext()->isFunctionOrMethod() || + tag->isInAnonymousNamespace())) { + id = GetUniqueNumber(GetID(tag->getCanonicalDecl())); } if (id) { name += '_'; diff --git a/cpp2rust/converter/printer.cpp b/cpp2rust/converter/printer.cpp index 384aef9b32..bd186d8afd 100644 --- a/cpp2rust/converter/printer.cpp +++ b/cpp2rust/converter/printer.cpp @@ -168,7 +168,9 @@ std::string ToString(clang::ASTContext &ctx, clang::QualType qual_type, if (auto *tag = qual_type->getAsTagDecl(); tag && tag->getIdentifier() && - tag->getDeclContext()->isFunctionOrMethod()) { + (tag->getDeclContext()->isFunctionOrMethod() || + (tag->isInAnonymousNamespace() && + !clang::isa(tag)))) { return GetNamedDeclAsString(tag); } diff --git a/tests/std/basic/basic.link/out/refcount/basic.link.rs b/tests/std/basic/basic.link/out/refcount/basic.link.rs index b4d56730ed..5aeb51e2df 100644 --- a/tests/std/basic/basic.link/out/refcount/basic.link.rs +++ b/tests/std/basic/basic.link/out/refcount/basic.link.rs @@ -68,13 +68,13 @@ pub fn bump_18() -> i32 { } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] #[byte_size(4)] -pub struct p4_unnamed_namespaces_in_two_files_Record_19 { +pub struct Record_19 { #[offset(0)] pub id: i32, } -impl Default for p4_unnamed_namespaces_in_two_files_Record_19 { +impl Default for Record_19 { fn default() -> Self { - { p4_unnamed_namespaces_in_two_files_Record_19 { id: 100 } } + { Record_19 { id: 100 } } } } thread_local!( @@ -84,8 +84,7 @@ pub fn test_21() { assert!((({ bump_18() }) == 2)); assert!((({ bump_in_b_22() }) == 51)); assert!((counter_17.with(|rc| *rc.borrow()) == 2)); - let mut record: p4_unnamed_namespaces_in_two_files_Record_19 = - ::default(); + let mut record: Record_19 = ::default(); assert!((record.id == 100)); assert!((({ record_id_in_b_23() }) == 200)); assert!((depth_20.with(|rc| *rc.borrow()) == 3)); @@ -105,19 +104,13 @@ pub fn test_29() { } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(1)] -pub struct p5_members_of_classes_in_unnamed_namespaces_Tally_31 {} +pub struct Tally_31 {} thread_local!( pub static total_32: Value = Rc::new(RefCell::new(10)); ); pub fn test_33() { - let tally: Value = Rc::new(RefCell::new( - ::default(), - )); - assert!( - (({ - p5_members_of_classes_in_unnamed_namespaces_Tally_31Impl::add(&tally.as_pointer(), 1) - }) == 11) - ); + let tally: Value = Rc::new(RefCell::new(::default())); + assert!((({ Tally_31Impl::add(&tally.as_pointer(), 1,) }) == 11)); assert!((({ add_in_b_34(1,) }) == 102)); assert!((total_32.with(|rc| *rc.borrow()) == 11)); } @@ -311,16 +304,16 @@ pub fn bump_64() -> i32 { } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] #[byte_size(16)] -pub struct p4_unnamed_namespaces_in_two_files_Record_65 { +pub struct Record_65 { #[offset(0)] pub id: i64, #[offset(8)] pub extra: i32, } -impl Default for p4_unnamed_namespaces_in_two_files_Record_65 { +impl Default for Record_65 { fn default() -> Self { { - p4_unnamed_namespaces_in_two_files_Record_65 { + Record_65 { id: 200_i64, extra: 1, } @@ -334,8 +327,7 @@ pub fn bump_in_b_22() -> i32 { return ({ bump_64() }); } pub fn record_id_in_b_23() -> i32 { - let mut record: p4_unnamed_namespaces_in_two_files_Record_65 = - ::default(); + let mut record: Record_65 = ::default(); return (record.id as i32); } pub fn depth_in_b_24() -> i32 { @@ -356,17 +348,13 @@ pub fn raise_30(mut by: i32) -> i32 { } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(1)] -pub struct p5_members_of_classes_in_unnamed_namespaces_Tally_67 {} +pub struct Tally_67 {} thread_local!( pub static total_68: Value = Rc::new(RefCell::new(100)); ); pub fn add_in_b_34(mut amount: i32) -> i32 { - let tally: Value = Rc::new(RefCell::new( - ::default(), - )); - return ({ - p5_members_of_classes_in_unnamed_namespaces_Tally_67Impl::add(&tally.as_pointer(), amount) - }); + let tally: Value = Rc::new(RefCell::new(::default())); + return ({ Tally_67Impl::add(&tally.as_pointer(), amount) }); } thread_local!( pub static balance_35: Value = Rc::new(RefCell::new(50)); @@ -426,23 +414,19 @@ pub fn table_sum_in_b_59() -> i32 { table_57.with(|rc| rc.borrow()[__idx0]) })); } -pub trait p5_members_of_classes_in_unnamed_namespaces_Tally_31Impl { +pub trait Tally_31Impl { fn add(&self, amount: i32) -> i32; } -impl p5_members_of_classes_in_unnamed_namespaces_Tally_31Impl - for Ptr -{ +impl Tally_31Impl for Ptr { fn add(&self, mut amount: i32) -> i32 { total_32.with(|rc| *rc.borrow_mut() += amount); return total_32.with(|rc| *rc.borrow()); } } -pub trait p5_members_of_classes_in_unnamed_namespaces_Tally_67Impl { +pub trait Tally_67Impl { fn add(&self, amount: i32) -> i32; } -impl p5_members_of_classes_in_unnamed_namespaces_Tally_67Impl - for Ptr -{ +impl Tally_67Impl for Ptr { fn add(&self, mut amount: i32) -> i32 { total_68.with(|rc| *rc.borrow_mut() += (amount * 2)); return total_68.with(|rc| *rc.borrow()); diff --git a/tests/std/basic/basic.link/out/unsafe/basic.link.rs b/tests/std/basic/basic.link/out/unsafe/basic.link.rs index 77aac06248..46c81ed457 100644 --- a/tests/std/basic/basic.link/out/unsafe/basic.link.rs +++ b/tests/std/basic/basic.link/out/unsafe/basic.link.rs @@ -61,12 +61,12 @@ pub unsafe fn bump_18() -> i32 { } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg)] -pub struct p4_unnamed_namespaces_in_two_files_Record_19 { +pub struct Record_19 { pub id: i32, } -impl Default for p4_unnamed_namespaces_in_two_files_Record_19 { +impl Default for Record_19 { fn default() -> Self { - unsafe { p4_unnamed_namespaces_in_two_files_Record_19 { id: 100 } } + unsafe { Record_19 { id: 100 } } } } pub static mut depth_20: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 3 }); @@ -74,8 +74,7 @@ pub unsafe fn test_21() { assert!(((unsafe { bump_18() }) == (2))); assert!(((unsafe { bump_in_b_22() }) == (51))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut counter_17)) == (2))); - let mut record: p4_unnamed_namespaces_in_two_files_Record_19 = - ::default(); + let mut record: Record_19 = ::default(); assert!(((record.id) == (100))); assert!(((unsafe { record_id_in_b_23() }) == (200))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut depth_20)) == (3))); @@ -95,8 +94,8 @@ pub unsafe fn test_29() { } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct p5_members_of_classes_in_unnamed_namespaces_Tally_31 {} -impl p5_members_of_classes_in_unnamed_namespaces_Tally_31 { +pub struct Tally_31 {} +impl Tally_31 { pub unsafe fn add(&mut self, mut amount: i32) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut total_32)) += amount; return (*std::cell::LazyCell::force_mut(&mut *&raw mut total_32)); @@ -104,12 +103,8 @@ impl p5_members_of_classes_in_unnamed_namespaces_Tally_31 { } pub static mut total_32: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10 }); pub unsafe fn test_33() { - let mut tally: p5_members_of_classes_in_unnamed_namespaces_Tally_31 = - ::default(); - assert!( - ((unsafe { p5_members_of_classes_in_unnamed_namespaces_Tally_31::add(&mut tally, 1,) }) - == (11)) - ); + let mut tally: Tally_31 = ::default(); + assert!(((unsafe { Tally_31::add(&mut tally, 1,) }) == (11))); assert!(((unsafe { add_in_b_34(1,) }) == (102))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_32)) == (11))); } @@ -272,14 +267,14 @@ pub unsafe fn bump_64() -> i32 { } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg)] -pub struct p4_unnamed_namespaces_in_two_files_Record_65 { +pub struct Record_65 { pub id: i64, pub extra: i32, } -impl Default for p4_unnamed_namespaces_in_two_files_Record_65 { +impl Default for Record_65 { fn default() -> Self { unsafe { - p4_unnamed_namespaces_in_two_files_Record_65 { + Record_65 { id: 200_i64, extra: 1, } @@ -291,8 +286,7 @@ pub unsafe fn bump_in_b_22() -> i32 { return (unsafe { bump_64() }); } pub unsafe fn record_id_in_b_23() -> i32 { - let mut record: p4_unnamed_namespaces_in_two_files_Record_65 = - ::default(); + let mut record: Record_65 = ::default(); return (record.id as i32); } pub unsafe fn depth_in_b_24() -> i32 { @@ -310,8 +304,8 @@ pub unsafe fn raise_30(mut by: i32) -> i32 { } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct p5_members_of_classes_in_unnamed_namespaces_Tally_67 {} -impl p5_members_of_classes_in_unnamed_namespaces_Tally_67 { +pub struct Tally_67 {} +impl Tally_67 { pub unsafe fn add(&mut self, mut amount: i32) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut total_68)) += ((amount) * (2)); return (*std::cell::LazyCell::force_mut(&mut *&raw mut total_68)); @@ -319,11 +313,8 @@ impl p5_members_of_classes_in_unnamed_namespaces_Tally_67 { } pub static mut total_68: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); pub unsafe fn add_in_b_34(mut amount: i32) -> i32 { - let mut tally: p5_members_of_classes_in_unnamed_namespaces_Tally_67 = - ::default(); - return (unsafe { - p5_members_of_classes_in_unnamed_namespaces_Tally_67::add(&mut tally, amount) - }); + let mut tally: Tally_67 = ::default(); + return (unsafe { Tally_67::add(&mut tally, amount) }); } pub static mut balance_35: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 50 }); impl p5_members_of_class_with_external_linkage_Ledger {