From a8e61b19f5ea3c345789860f68071307d1ad210a Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Mon, 13 Apr 2026 21:31:32 +0100 Subject: [PATCH 01/10] Use concerete default val for initializing globals --- cpp2rust/converter/converter.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 0f6f48d3..33970272 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -1663,7 +1663,11 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) { ConvertEqualsNullPtr(sub_expr); break; case clang::CastKind::CK_NullToPointer: - StrCat(keyword_default_); + if (type->isFunctionPointerType()) { + StrCat("None"); + } else { + StrCat(keyword_default_); + } computed_expr_type_ = ComputedExprType::FreshPointer; break; default: @@ -2679,18 +2683,18 @@ std::string Converter::GetDefaultAsString(clang::QualType qual_type) { } std::string Converter::GetDefaultAsStringFallback(clang::QualType qual_type) { - static llvm::DenseMap default_for_type = { - {clang::BuiltinType::Char_U, "0_u8"}, - {clang::BuiltinType::SChar, "0_i8"}, - {clang::BuiltinType::UChar, "0_u8"}, - }; - qual_type = qual_type.getUnqualifiedType().getCanonicalType(); - if (auto builtin = qual_type->getAs()) { - auto it = default_for_type.find(builtin->getKind()); - if (it != default_for_type.end()) { - return it->second; - } + + if (qual_type->isBooleanType()) { + return "false"; + } + + if (qual_type->isIntegerType()) { + return std::format("0 as {}", ToString(qual_type)); + } + + if (qual_type->isFloatingType()) { + return std::format("0.0 as {}", ToString(qual_type)); } return std::format("<{}>::default()", ToString(qual_type)); From 175a62b909ae100a6b2e7c7fcdbfe37b3f4de5b0 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 16 Apr 2026 20:11:35 +0100 Subject: [PATCH 02/10] Use suffix for default integers --- cpp2rust/converter/converter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 33970272..422e3c1c 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -2690,11 +2690,11 @@ std::string Converter::GetDefaultAsStringFallback(clang::QualType qual_type) { } if (qual_type->isIntegerType()) { - return std::format("0 as {}", ToString(qual_type)); + return std::format("0_{}", ToString(qual_type)); } if (qual_type->isFloatingType()) { - return std::format("0.0 as {}", ToString(qual_type)); + return std::format("0.0_{}", ToString(qual_type)); } return std::format("<{}>::default()", ToString(qual_type)); From 5905b86eef49ffba1fe2c58e22644eac99bb1d28 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 15 Apr 2026 15:23:26 +0100 Subject: [PATCH 03/10] Omit enumeral types on generating default integers --- cpp2rust/converter/converter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 422e3c1c..e8d73128 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -2689,7 +2689,7 @@ std::string Converter::GetDefaultAsStringFallback(clang::QualType qual_type) { return "false"; } - if (qual_type->isIntegerType()) { + if (qual_type->isIntegerType() && !qual_type->isEnumeralType()) { return std::format("0_{}", ToString(qual_type)); } From 90eb182581edab4df6c6883f751ef8f991fbd044 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Mon, 13 Apr 2026 21:30:42 +0100 Subject: [PATCH 04/10] Translate non-const globals as static mut --- cpp2rust/converter/converter.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index e8d73128..82bad3b6 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -383,9 +383,15 @@ bool Converter::ConvertVarDeclSkipInit(clang::VarDecl *decl) { return false; } StrCat(AccessSpecifierAsString(decl->getAccess()), keyword::kStatic); + if (!qual_type.isConstQualified()) { + StrCat(keyword_mut_); + } ENSURE(decl_ids_.insert(GetID(decl)).second); } else if (decl->isStaticLocal()) { StrCat(keyword::kStatic); + if (!qual_type.isConstQualified()) { + StrCat(keyword_mut_); + } } else if (decl->isLocalVarDecl()) { StrCat(keyword::kLet); } From 778d72bcf3c9a791019d46cba65af79ae986d025 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 16 Apr 2026 20:16:04 +0100 Subject: [PATCH 05/10] static_local compiles fine in unsafe --- tests/unit/out/unsafe/static_local.rs | 2 +- tests/unit/static_local.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/unit/out/unsafe/static_local.rs b/tests/unit/out/unsafe/static_local.rs index c6fe9391..042a7008 100644 --- a/tests/unit/out/unsafe/static_local.rs +++ b/tests/unit/out/unsafe/static_local.rs @@ -8,7 +8,7 @@ use std::io::{Read, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn foo_0() -> i32 { - static kX1: i32 = 1;; + static mut kX1: i32 = 1;; static kX2: i32 = 2;; kX1 += 1; return ((kX1) + (kX2)); diff --git a/tests/unit/static_local.cpp b/tests/unit/static_local.cpp index 4378e997..acb9117d 100644 --- a/tests/unit/static_local.cpp +++ b/tests/unit/static_local.cpp @@ -1,7 +1,6 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// no-compile: unsafe int foo() { static int kX1 = 1; static const int kX2 = 2; From a417fcf5fb31089b681fa97ef110565583f4ebc2 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 16 Apr 2026 20:25:44 +0100 Subject: [PATCH 06/10] Revert unrelated function pointer change --- cpp2rust/converter/converter.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 82bad3b6..3f778a93 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -1669,11 +1669,7 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) { ConvertEqualsNullPtr(sub_expr); break; case clang::CastKind::CK_NullToPointer: - if (type->isFunctionPointerType()) { - StrCat("None"); - } else { - StrCat(keyword_default_); - } + StrCat(keyword_default_); computed_expr_type_ = ComputedExprType::FreshPointer; break; default: From 82263581ea3bdb4539d2deb0ea98cf9581a4f394 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 16 Apr 2026 20:36:39 +0100 Subject: [PATCH 07/10] Add test for default initialized static local vars --- tests/unit/out/refcount/static_local.rs | 12 +++++++++++- tests/unit/out/unsafe/static_local.rs | 5 ++++- tests/unit/static_local.cpp | 6 +++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/unit/out/refcount/static_local.rs b/tests/unit/out/refcount/static_local.rs index ffe8b7bd..62ebbaa7 100644 --- a/tests/unit/out/refcount/static_local.rs +++ b/tests/unit/out/refcount/static_local.rs @@ -8,6 +8,15 @@ use std::io::{Read, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn foo_0() -> i32 { + thread_local!( + static static_i: Value = >::default(); + ); + thread_local!( + static static_f: Value = >::default(); + ); + thread_local!( + static static_b: Value = >::default(); + ); thread_local!( static kX1: Value = Rc::new(RefCell::new(1)); ); @@ -15,7 +24,8 @@ pub fn foo_0() -> i32 { static kX2: Value = Rc::new(RefCell::new(2)); ); (*kX1.with(Value::clone).borrow_mut()) += 1; - return ((*kX1.with(Value::clone).borrow()) + (*kX2.with(Value::clone).borrow())); + return (((*kX1.with(Value::clone).borrow()) + (*kX2.with(Value::clone).borrow())) + + (*static_i.with(Value::clone).borrow())); } pub fn main() { std::process::exit(main_0()); diff --git a/tests/unit/out/unsafe/static_local.rs b/tests/unit/out/unsafe/static_local.rs index 042a7008..9b27215d 100644 --- a/tests/unit/out/unsafe/static_local.rs +++ b/tests/unit/out/unsafe/static_local.rs @@ -8,10 +8,13 @@ use std::io::{Read, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn foo_0() -> i32 { + static mut static_i: i32 = 0_i32;; + static mut static_f: f32 = 0.0_f32;; + static mut static_b: bool = false;; static mut kX1: i32 = 1;; static kX2: i32 = 2;; kX1 += 1; - return ((kX1) + (kX2)); + return (((kX1) + (kX2)) + (static_i)); } pub fn main() { unsafe { diff --git a/tests/unit/static_local.cpp b/tests/unit/static_local.cpp index acb9117d..023c59c4 100644 --- a/tests/unit/static_local.cpp +++ b/tests/unit/static_local.cpp @@ -2,10 +2,14 @@ // Distributed under the MIT license that can be found in the LICENSE file. int foo() { + static int static_i; + static float static_f; + static bool static_b; + static int kX1 = 1; static const int kX2 = 2; kX1 += 1; - return kX1 + kX2; + return kX1 + kX2 + static_i; } int main() { return foo() + foo() + foo(); } From 584573a0a17a634b2c8de46557630015748c66be Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 16 Apr 2026 20:50:55 +0100 Subject: [PATCH 08/10] Update tests --- tests/ub/out/unsafe/ub10.rs | 8 ++------ tests/ub/out/unsafe/ub14.rs | 8 ++------ tests/ub/out/unsafe/ub15.rs | 8 ++------ tests/ub/out/unsafe/ub16.rs | 8 ++------ tests/ub/out/unsafe/ub20.rs | 8 ++------ tests/ub/out/unsafe/ub9.rs | 8 ++------ tests/unit/out/unsafe/06_new_array.rs | 3 +-- tests/unit/out/unsafe/clone_vs_move.rs | 4 ++-- tests/unit/out/unsafe/default.rs | 2 +- tests/unit/out/unsafe/init.rs | 2 +- tests/unit/out/unsafe/init_list.rs | 4 ++-- tests/unit/out/unsafe/memset.rs | 8 ++------ tests/unit/out/unsafe/new_alloc_array.rs | 8 ++------ tests/unit/out/unsafe/new_array.rs | 8 ++------ tests/unit/out/unsafe/new_array_var_size.rs | 16 ++++------------ tests/unit/out/unsafe/pointer_call_offset.rs | 8 ++------ tests/unit/out/unsafe/random.rs | 6 +++--- .../out/unsafe/reinterpret_cast_large_array.rs | 8 ++------ .../out/unsafe/reinterpret_cast_new_array.rs | 2 +- tests/unit/out/unsafe/stdcopy.rs | 2 +- tests/unit/out/unsafe/swap_extended.rs | 2 +- tests/unit/out/unsafe/unique_ptr.rs | 8 ++------ tests/unit/out/unsafe/vector2.rs | 2 +- 23 files changed, 42 insertions(+), 99 deletions(-) diff --git a/tests/ub/out/unsafe/ub10.rs b/tests/ub/out/unsafe/ub10.rs index 14ba0eaf..f684d128 100644 --- a/tests/ub/out/unsafe/ub10.rs +++ b/tests/ub/out/unsafe/ub10.rs @@ -13,12 +13,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut arr: *mut i32 = Box::leak( - (0..10_u64) - .map(|_| ::default()) - .collect::>(), - ) - .as_mut_ptr(); + let mut arr: *mut i32 = + Box::leak((0..10_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); let mut ptr: *mut i32 = arr.offset((1) as isize); let mut out: i32 = (*ptr); diff --git a/tests/ub/out/unsafe/ub14.rs b/tests/ub/out/unsafe/ub14.rs index 491de599..61c89588 100644 --- a/tests/ub/out/unsafe/ub14.rs +++ b/tests/ub/out/unsafe/ub14.rs @@ -13,12 +13,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut arr1: *mut i32 = Box::leak( - (0..100_u64) - .map(|_| ::default()) - .collect::>(), - ) - .as_mut_ptr(); + let mut arr1: *mut i32 = + Box::leak((0..100_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); (*arr1.offset((100) as isize)) = 1; ::std::mem::drop(Box::from_raw(::std::slice::from_raw_parts_mut( diff --git a/tests/ub/out/unsafe/ub15.rs b/tests/ub/out/unsafe/ub15.rs index dc08aa16..669d188a 100644 --- a/tests/ub/out/unsafe/ub15.rs +++ b/tests/ub/out/unsafe/ub15.rs @@ -13,12 +13,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut arr: *mut i32 = Box::leak( - (0..15_u64) - .map(|_| ::default()) - .collect::>(), - ) - .as_mut_ptr(); + let mut arr: *mut i32 = + Box::leak((0..15_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); let mut ptr: *mut i32 = arr.offset((15) as isize); let mut out: i32 = (*ptr); diff --git a/tests/ub/out/unsafe/ub16.rs b/tests/ub/out/unsafe/ub16.rs index a53d8844..a4c801eb 100644 --- a/tests/ub/out/unsafe/ub16.rs +++ b/tests/ub/out/unsafe/ub16.rs @@ -16,12 +16,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut p1: *mut i32 = Box::leak( - (0..10_u64) - .map(|_| ::default()) - .collect::>(), - ) - .as_mut_ptr(); + let mut p1: *mut i32 = + Box::leak((0..10_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); let mut out: i32 = (*(unsafe { let _a: *mut i32 = (&mut (*p1.offset((1) as isize)) as *mut i32); foo_0(_a) diff --git a/tests/ub/out/unsafe/ub20.rs b/tests/ub/out/unsafe/ub20.rs index 8517a699..053b3532 100644 --- a/tests/ub/out/unsafe/ub20.rs +++ b/tests/ub/out/unsafe/ub20.rs @@ -16,12 +16,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut x: *mut i32 = Box::leak( - (0..10_u64) - .map(|_| ::default()) - .collect::>(), - ) - .as_mut_ptr(); + let mut x: *mut i32 = + Box::leak((0..10_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); (unsafe { let _single: *mut i32 = x; foo_0(_single) diff --git a/tests/ub/out/unsafe/ub9.rs b/tests/ub/out/unsafe/ub9.rs index f2136e71..8f574181 100644 --- a/tests/ub/out/unsafe/ub9.rs +++ b/tests/ub/out/unsafe/ub9.rs @@ -13,12 +13,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut arr: *mut i32 = Box::leak( - (0..10_u64) - .map(|_| ::default()) - .collect::>(), - ) - .as_mut_ptr(); + let mut arr: *mut i32 = + Box::leak((0..10_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); let mut out: i32 = (*arr.offset((10) as isize)); ::std::mem::drop(Box::from_raw(::std::slice::from_raw_parts_mut( diff --git a/tests/unit/out/unsafe/06_new_array.rs b/tests/unit/out/unsafe/06_new_array.rs index cdb76f92..d7bb799c 100644 --- a/tests/unit/out/unsafe/06_new_array.rs +++ b/tests/unit/out/unsafe/06_new_array.rs @@ -13,8 +13,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut e: *mut i32 = - Box::leak((0..2_u64).map(|_| ::default()).collect::>()).as_mut_ptr(); + let mut e: *mut i32 = Box::leak((0..2_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); (*e.offset((0) as isize)) = 6; (*e.offset((1) as isize)) = 7; diff --git a/tests/unit/out/unsafe/clone_vs_move.rs b/tests/unit/out/unsafe/clone_vs_move.rs index c19f9ec1..d0fcde2a 100644 --- a/tests/unit/out/unsafe/clone_vs_move.rs +++ b/tests/unit/out/unsafe/clone_vs_move.rs @@ -22,10 +22,10 @@ pub struct Foo { impl Default for Foo { fn default() -> Self { Foo { - x: ::default(), + x: 0_i32, y: <*mut i32>::default(), z: Default::default(), - a: [::default(); 3], + a: [0_i32; 3], bar: ::default(), } } diff --git a/tests/unit/out/unsafe/default.rs b/tests/unit/out/unsafe/default.rs index 68683773..952ccd85 100644 --- a/tests/unit/out/unsafe/default.rs +++ b/tests/unit/out/unsafe/default.rs @@ -22,7 +22,7 @@ impl Default for Pointers { x2: Default::default(), x3: [Default::default(); 5], x4: [Default::default(); 10], - x5: ::default(), + x5: 0_i32, } } } diff --git a/tests/unit/out/unsafe/init.rs b/tests/unit/out/unsafe/init.rs index 894070b2..5e615764 100644 --- a/tests/unit/out/unsafe/init.rs +++ b/tests/unit/out/unsafe/init.rs @@ -20,7 +20,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut x: i32 = ::default(); + let mut x: i32 = 0_i32; let mut p: *mut i32 = Default::default(); let g: *mut i32 = &mut x as *mut i32; let mut q: *mut i32 = (&mut x as *mut i32); diff --git a/tests/unit/out/unsafe/init_list.rs b/tests/unit/out/unsafe/init_list.rs index d8e2166f..1f6a2b52 100644 --- a/tests/unit/out/unsafe/init_list.rs +++ b/tests/unit/out/unsafe/init_list.rs @@ -15,9 +15,9 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut i1: i32 = 3; - let mut i2: i32 = ::default(); + let mut i2: i32 = 0_i32; let mut carr1: [i32; 2] = [1, 2]; - let mut carr2: [i32; 3] = [1, ::default(), ::default()]; + let mut carr2: [i32; 3] = [1, 0_i32, 0_i32]; let mut arr: Vec = vec![1, 2, 3]; let mut vec_: Vec = vec![1, 2, 3]; (unsafe { diff --git a/tests/unit/out/unsafe/memset.rs b/tests/unit/out/unsafe/memset.rs index ec8fd428..284f9765 100644 --- a/tests/unit/out/unsafe/memset.rs +++ b/tests/unit/out/unsafe/memset.rs @@ -14,12 +14,8 @@ pub fn main() { } unsafe fn main_0() -> i32 { let N: i32 = 3; - let mut arr: *mut i32 = Box::leak( - (0..(N as u64)) - .map(|_| ::default()) - .collect::>(), - ) - .as_mut_ptr(); + let mut arr: *mut i32 = + Box::leak((0..(N as u64)).map(|_| 0_i32).collect::>()).as_mut_ptr(); { let byte_0 = (arr as *mut i32 as *mut ::libc::c_void) as *mut u8; for offset in 0..(::std::mem::size_of::() as u64 as u64).wrapping_mul((N as u64)) { diff --git a/tests/unit/out/unsafe/new_alloc_array.rs b/tests/unit/out/unsafe/new_alloc_array.rs index 697fe0a1..1814e52a 100644 --- a/tests/unit/out/unsafe/new_alloc_array.rs +++ b/tests/unit/out/unsafe/new_alloc_array.rs @@ -13,12 +13,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut array: *mut i32 = Box::leak( - (0..100_u64) - .map(|_| ::default()) - .collect::>(), - ) - .as_mut_ptr(); + let mut array: *mut i32 = + Box::leak((0..100_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); { let byte_0 = (array as *mut i32 as *mut ::libc::c_void) as *mut u8; for offset in 0..(::std::mem::size_of::() as u64 as u64).wrapping_mul(100_u64) { diff --git a/tests/unit/out/unsafe/new_array.rs b/tests/unit/out/unsafe/new_array.rs index e2243eea..514fc12c 100644 --- a/tests/unit/out/unsafe/new_array.rs +++ b/tests/unit/out/unsafe/new_array.rs @@ -13,12 +13,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut array: *mut i32 = Box::leak( - (0..100_u64) - .map(|_| ::default()) - .collect::>(), - ) - .as_mut_ptr(); + let mut array: *mut i32 = + Box::leak((0..100_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); ::std::mem::drop(Box::from_raw(::std::slice::from_raw_parts_mut( array, diff --git a/tests/unit/out/unsafe/new_array_var_size.rs b/tests/unit/out/unsafe/new_array_var_size.rs index cfdf0c19..f9be6146 100644 --- a/tests/unit/out/unsafe/new_array_var_size.rs +++ b/tests/unit/out/unsafe/new_array_var_size.rs @@ -14,24 +14,16 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut N: i32 = 5; - let mut A: *mut i32 = Box::leak( - (0..(N as u64)) - .map(|_| ::default()) - .collect::>(), - ) - .as_mut_ptr(); + let mut A: *mut i32 = + Box::leak((0..(N as u64)).map(|_| 0_i32).collect::>()).as_mut_ptr(); ::std::mem::drop(Box::from_raw(::std::slice::from_raw_parts_mut( A, libcc2rs::malloc_usable_size(A as *mut ::libc::c_void) / ::std::mem::size_of::(), ))); let N2: *mut i32 = &mut N as *mut i32; - let mut A2: *mut i32 = Box::leak( - (0..((*N2) as u64)) - .map(|_| ::default()) - .collect::>(), - ) - .as_mut_ptr(); + let mut A2: *mut i32 = + Box::leak((0..((*N2) as u64)).map(|_| 0_i32).collect::>()).as_mut_ptr(); ::std::mem::drop(Box::from_raw(::std::slice::from_raw_parts_mut( A2, diff --git a/tests/unit/out/unsafe/pointer_call_offset.rs b/tests/unit/out/unsafe/pointer_call_offset.rs index fdbca43a..76f2a3d8 100644 --- a/tests/unit/out/unsafe/pointer_call_offset.rs +++ b/tests/unit/out/unsafe/pointer_call_offset.rs @@ -16,12 +16,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut p1: *mut i32 = Box::leak( - (0..10_u64) - .map(|_| ::default()) - .collect::>(), - ) - .as_mut_ptr(); + let mut p1: *mut i32 = + Box::leak((0..10_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); let mut i: u32 = 0_u32; 'loop_: while ((i) < (10_u32)) { (*p1.offset((i) as isize)) = (i as i32); diff --git a/tests/unit/out/unsafe/random.rs b/tests/unit/out/unsafe/random.rs index 87397236..05efa2b1 100644 --- a/tests/unit/out/unsafe/random.rs +++ b/tests/unit/out/unsafe/random.rs @@ -40,9 +40,9 @@ impl Pair { impl Default for Pair { fn default() -> Self { Pair { - x: ::default(), - y: ::default(), - a: [::default(); 5], + x: 0_i32, + y: 0_i32, + a: [0_i32; 5], r: <*mut i32>::default(), p: Default::default(), pair: Default::default(), diff --git a/tests/unit/out/unsafe/reinterpret_cast_large_array.rs b/tests/unit/out/unsafe/reinterpret_cast_large_array.rs index 6d85d331..d3e0fd8e 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_large_array.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_large_array.rs @@ -14,12 +14,8 @@ pub fn main() { } unsafe fn main_0() -> i32 { let N: i32 = 10000; - let mut arr: *mut u32 = Box::leak( - (0..(N as u64)) - .map(|_| ::default()) - .collect::>(), - ) - .as_mut_ptr(); + let mut arr: *mut u32 = + Box::leak((0..(N as u64)).map(|_| 0_u32).collect::>()).as_mut_ptr(); let mut i: i32 = 0; 'loop_: while ((i) < (N)) { (*arr.offset((i) as isize)) = 0_u32; diff --git a/tests/unit/out/unsafe/reinterpret_cast_new_array.rs b/tests/unit/out/unsafe/reinterpret_cast_new_array.rs index 87840ed1..3a71d5be 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_new_array.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_new_array.rs @@ -14,7 +14,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut arr: *mut u32 = - Box::leak((0..2_u64).map(|_| ::default()).collect::>()).as_mut_ptr(); + Box::leak((0..2_u64).map(|_| 0_u32).collect::>()).as_mut_ptr(); (*arr.offset((0) as isize)) = 67305985_u32; (*arr.offset((1) as isize)) = 134678021_u32; let mut bytes: *mut u8 = (arr as *mut u8); diff --git a/tests/unit/out/unsafe/stdcopy.rs b/tests/unit/out/unsafe/stdcopy.rs index 4c813830..15c58095 100644 --- a/tests/unit/out/unsafe/stdcopy.rs +++ b/tests/unit/out/unsafe/stdcopy.rs @@ -14,7 +14,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut input: [i32; 3] = [1, 2, 3]; - let mut output: [i32; 3] = [::default(); 3]; + let mut output: [i32; 3] = [0_i32; 3]; { let mut outptr = output.as_mut_ptr().clone(); let mut curr = input.as_mut_ptr().clone(); diff --git a/tests/unit/out/unsafe/swap_extended.rs b/tests/unit/out/unsafe/swap_extended.rs index adc9da12..d1e3a3b4 100644 --- a/tests/unit/out/unsafe/swap_extended.rs +++ b/tests/unit/out/unsafe/swap_extended.rs @@ -94,7 +94,7 @@ unsafe fn main_0() -> i32 { (*h), ); ::std::mem::drop(Box::from_raw(h)); - let mut i: *mut i32 = Box::leak(Box::new([7, 8, ::default()])).as_mut_ptr(); + let mut i: *mut i32 = Box::leak(Box::new([7, 8, 0_i32])).as_mut_ptr(); write!( std::fs::File::from_raw_fd( std::io::stdout() diff --git a/tests/unit/out/unsafe/unique_ptr.rs b/tests/unit/out/unsafe/unique_ptr.rs index 1db51390..73a1a4ba 100644 --- a/tests/unit/out/unsafe/unique_ptr.rs +++ b/tests/unit/out/unsafe/unique_ptr.rs @@ -72,9 +72,7 @@ pub unsafe fn Consume_1(mut safe_ptr: Option>) -> i32 { pub unsafe fn RndStuff_2() { let mut x1: Option> = None; let mut x2: Option> = Some(Box::from_raw(Box::leak( - (0..100_u64) - .map(|_| ::default()) - .collect::>(), + (0..100_u64).map(|_| 0_i32).collect::>(), ))); let mut i: i32 = 0; 'loop_: while ((i) < (100)) { @@ -82,9 +80,7 @@ pub unsafe fn RndStuff_2() { i.prefix_inc(); } x2 = Some(Box::from_raw(Box::leak( - (0..200_u64) - .map(|_| ::default()) - .collect::>(), + (0..200_u64).map(|_| 0_i32).collect::>(), ))); let mut i: i32 = 0; 'loop_: while ((i) < (200)) { diff --git a/tests/unit/out/unsafe/vector2.rs b/tests/unit/out/unsafe/vector2.rs index a62467e9..dd5b4d4e 100644 --- a/tests/unit/out/unsafe/vector2.rs +++ b/tests/unit/out/unsafe/vector2.rs @@ -9,7 +9,7 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn fn_0(v: *mut Vec, mut v3: Vec) { (*v).push(20); - let mut x: i32 = ::default(); + let mut x: i32 = 0_i32; let mut v2: Vec = Vec::new(); let mut v4: *mut Vec = (&mut v3 as *mut Vec); v2.push(0); From dcaddaf985dfdc86c6d3261d1a090d91fbf9af3e Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 16 Apr 2026 21:06:48 +0100 Subject: [PATCH 09/10] Update tests --- tests/benchmarks/out/unsafe/bfs.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/benchmarks/out/unsafe/bfs.rs b/tests/benchmarks/out/unsafe/bfs.rs index ae9be6fd..956d7541 100644 --- a/tests/benchmarks/out/unsafe/bfs.rs +++ b/tests/benchmarks/out/unsafe/bfs.rs @@ -62,7 +62,7 @@ pub unsafe fn BFS_0(graph: *const Graph, mut start_vertex: u32) -> *mut u32 { let mut Q: Queue = Queue { elems: Box::leak( (0..((*graph).V as u64)) - .map(|_| ::default()) + .map(|_| 0_u32) .collect::>(), ) .as_mut_ptr(), @@ -72,13 +72,13 @@ pub unsafe fn BFS_0(graph: *const Graph, mut start_vertex: u32) -> *mut u32 { }; let mut visited: *mut bool = Box::leak( (0..((*graph).V as u64)) - .map(|_| ::default()) + .map(|_| false) .collect::>(), ) .as_mut_ptr(); let mut pred: *mut u32 = Box::leak( (0..((*graph).V as u64)) - .map(|_| ::default()) + .map(|_| 0_u32) .collect::>(), ) .as_mut_ptr(); From 0ac9b1a80fba45a87e0cb963aa3e7240ab913424 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 16 Apr 2026 22:19:30 +0100 Subject: [PATCH 10/10] Triger CI