From 6ac40b591f63a8656af63de4ade3547e1bc689bb Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 9 Oct 2026 13:44:38 +0100 Subject: [PATCH 1/5] Translate va_list references and pointers in fields --- .../converter/models/converter_refcount.cpp | 22 ++++++---- libcc2rs/src/va_args.rs | 17 ++++--- tests/unit/va_list_field.cpp | 44 +++++++++++++++++++ 3 files changed, 69 insertions(+), 14 deletions(-) create mode 100644 tests/unit/va_list_field.cpp diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 9a5f74873f..1fd66f1855 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -291,7 +291,7 @@ bool ConverterRefCount::VisitReferenceType(clang::ReferenceType *type) { PushConversionKind push(*this, ConversionKind::Unboxed); return Convert(ctx_.getPointerType(pointee_type)); } - if (pointee_type->isArrayType()) { + if (pointee_type->isArrayType() && !IsVaListType(pointee_type)) { // A reference to an array decays straight to a pointer to its first // element, the same way a by-value array parameter would, instead of // going through a pointer to the whole boxed array. @@ -335,10 +335,11 @@ bool ConverterRefCount::VisitPointerType(clang::PointerType *type) { } auto pointee_type = type->getPointeeType(); - PushConversionKind push1(*this, ConversionKind::Ptr, - !pointee_type->isArrayType()); + bool pointee_is_array = + pointee_type->isArrayType() && !IsVaListType(pointee_type); + PushConversionKind push1(*this, ConversionKind::Ptr, !pointee_is_array); PushConversionKind push2(*this, ConversionKind::FullRefCount, - pointee_type->isArrayType()); + pointee_is_array); if (pointee_type->isRecordType() && abstract_structs_.contains(GetID(pointee_type->getAsRecordDecl()))) { StrCat("PtrDyn(va_list_expr)) { va_list_expr = cast->getSubExpr(); } - StrCat(ConvertLValue(va_list_expr)); - StrCat(".arg::<"); + auto str = ConvertLValue(va_list_expr); + std::string arg_type; { PushConversionKind push(*this, ConversionKind::Unboxed); - StrCat(ToString(expr->getType())); + arg_type = ToString(expr->getType()); + } + if (!pending_deref_.empty()) { + StrCat(pending_deref_.take(), ".with_mut(|__v| __v.arg::<", arg_type, + ">())"); + } else { + StrCat(str, ".arg::<", arg_type, ">()"); } - StrCat(">()"); SetFreshType(expr->getType()); return false; } diff --git a/libcc2rs/src/va_args.rs b/libcc2rs/src/va_args.rs index 941b20a3bf..b2d1b4a514 100644 --- a/libcc2rs/src/va_args.rs +++ b/libcc2rs/src/va_args.rs @@ -52,15 +52,20 @@ impl From> for VaAr } } -#[derive(Clone, Copy, Default)] -pub struct VaList<'a> { - args: &'a [VaArg], +#[derive(Clone, Default)] +pub struct VaList { + args: Rc<[VaArg]>, pos: usize, } -impl<'a> VaList<'a> { - pub fn new(args: &'a [VaArg]) -> Self { - VaList { args, pos: 0 } +impl crate::reinterpret::ByteRepr for VaList {} + +impl VaList { + pub fn new(args: &[VaArg]) -> Self { + VaList { + args: Rc::from(args), + pos: 0, + } } pub fn arg(&mut self) -> T { diff --git a/tests/unit/va_list_field.cpp b/tests/unit/va_list_field.cpp new file mode 100644 index 0000000000..0677ca1bdf --- /dev/null +++ b/tests/unit/va_list_field.cpp @@ -0,0 +1,44 @@ +#include +#include + +static int sum(int n, ...) { + struct Guard { + va_list ≈ + bool active; + Guard(va_list &val) : ap(val), active(true) {} + ~Guard() { + if (active) { + va_end(ap); + } + } + }; + va_list ap; + va_start(ap, n); + Guard guard(ap); + int total = 0; + for (int i = 0; i < n; ++i) { + total += va_arg(guard.ap, int); + } + return total; +} + +static int sum_ptr(int n, ...) { + struct Cursor { + va_list *ap; + }; + va_list ap; + va_start(ap, n); + Cursor cursor{&ap}; + int total = 0; + for (int i = 0; i < n; ++i) { + total += va_arg(*cursor.ap, int); + } + va_end(ap); + return total; +} + +int main() { + assert(sum(3, 1, 2, 3) == 6); + assert(sum_ptr(2, 4, 5) == 9); + return 0; +} From e87f10e559455770591be2b06ae28fe756d5d608 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 9 Oct 2026 21:46:45 +0100 Subject: [PATCH 2/5] Update tests --- tests/unit/out/refcount/va_list_field.rs | 79 ++++++++++++++++++++++++ tests/unit/out/unsafe/va_list_field.rs | 70 +++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 tests/unit/out/refcount/va_list_field.rs create mode 100644 tests/unit/out/unsafe/va_list_field.rs diff --git a/tests/unit/out/refcount/va_list_field.rs b/tests/unit/out/refcount/va_list_field.rs new file mode 100644 index 0000000000..45d671d6c9 --- /dev/null +++ b/tests/unit/out/refcount/va_list_field.rs @@ -0,0 +1,79 @@ +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 sum_0(n: i32, __args: &[VaArg]) -> i32 { + let n: Value = Rc::new(RefCell::new(n)); + let ap: Value = Rc::new(RefCell::new(VaList::default())); + (*ap.borrow_mut()) = VaList::new(__args); + let guard: Value = Rc::new(RefCell::new(Guard_1::new({ ap.as_pointer() }))); + let _dtor_guard = ScopedDestructor::new(&guard, |__p| __p.destructor()); + let mut total: i32 = 0; + let mut i: i32 = 0; + 'loop_: while (i < (*n.borrow())) { + total += { (*guard.borrow()).ap.clone() }.with_mut(|__v| __v.arg::()); + i.prefix_inc(); + } + return total; +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(16)] +pub struct Guard_1 { + #[offset(0)] + #[byte_size(8)] + pub ap: Ptr, + #[offset(8)] + pub active: bool, +} +impl Guard_1 { + pub fn new(val: Ptr) -> Self { + Self { + ap: (val).clone(), + active: true, + } + } +} +pub fn sum_ptr_2(n: i32, __args: &[VaArg]) -> i32 { + let n: Value = Rc::new(RefCell::new(n)); + let ap: Value = Rc::new(RefCell::new(VaList::default())); + (*ap.borrow_mut()) = VaList::new(__args); + let mut cursor: Cursor_3 = Cursor_3 { + ap: (ap.as_pointer()), + }; + let mut total: i32 = 0; + let mut i: i32 = 0; + 'loop_: while (i < (*n.borrow())) { + total += cursor.ap.with_mut(|__v| __v.arg::()); + i.prefix_inc(); + } + return total; +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct Cursor_3 { + #[offset(0)] + #[byte_size(8)] + pub ap: Ptr, +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!((({ sum_0(3, &[(1).into(), (2).into(), (3).into(),]) }) == 6)); + assert!((({ sum_ptr_2(2, &[(4).into(), (5).into(),]) }) == 9)); + return 0; +} +pub trait Guard_1Impl { + fn destructor(&self); +} +impl Guard_1Impl for Ptr { + fn destructor(&self) { + if (*self).with(|__s| __s.active) {} + } +} +pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/va_list_field.rs b/tests/unit/out/unsafe/va_list_field.rs new file mode 100644 index 0000000000..14948ff551 --- /dev/null +++ b/tests/unit/out/unsafe/va_list_field.rs @@ -0,0 +1,70 @@ +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 sum_0(mut n: i32, __args: &[VaArg]) -> i32 { + let mut ap: VaList = VaList::default(); + ap = VaList::new(__args); + let mut guard: Guard_1 = Guard_1::new({ &mut ap }); + let _dtor_guard = ScopedDestructorUnsafe::new(&raw mut guard, Guard_1::destructor); + let mut total: i32 = 0; + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + total += (*guard.ap).arg::(); + i.prefix_inc(); + } + return total; +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct Guard_1 { + pub ap: *mut VaList, + pub active: bool, +} +impl Guard_1 { + pub unsafe fn new(val: *mut VaList) -> Self { + let mut this = Self { + ap: val, + active: true, + }; + this + } + pub unsafe fn destructor(&mut self) { + if self.active {} + } +} +pub unsafe fn sum_ptr_2(mut n: i32, __args: &[VaArg]) -> i32 { + let mut ap: VaList = VaList::default(); + ap = VaList::new(__args); + let mut cursor: Cursor_3 = Cursor_3 { + ap: (&mut ap as *mut VaList), + }; + let mut total: i32 = 0; + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + total += (*cursor.ap).arg::(); + i.prefix_inc(); + } + return total; +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Cursor_3 { + pub ap: *mut VaList, +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!(((unsafe { sum_0(3, &[(1).into(), (2).into(), (3).into(),]) }) == (6))); + assert!(((unsafe { sum_ptr_2(2, &[(4).into(), (5).into(),]) }) == (9))); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() {} From 43765d0c93b2e0a132d11dd49a873776d4cb7637 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sat, 10 Oct 2026 13:01:31 +0100 Subject: [PATCH 3/5] VaList -> Ptr --- cpp2rust/converter/converter.cpp | 11 +++--- .../converter/models/converter_refcount.cpp | 19 +++++++--- libcc2rs/src/va_args.rs | 35 ++++++++++--------- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index b63c7fcb36..6e3c8cb62c 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -116,7 +116,7 @@ bool Converter::VisitRecoveryExpr(clang::RecoveryExpr *expr) { bool Converter::Convert(clang::QualType qual_type) { // Catch va_list before desugaring if (IsVaListType(qual_type)) { - StrCat("VaList"); + StrCat("*const VaArg"); return false; } @@ -307,7 +307,7 @@ bool Converter::VisitPointerType(clang::PointerType *type) { } if (IsVaListType(clang::QualType(type, 0))) { - StrCat("VaList"); + StrCat("*const VaArg"); return false; } @@ -472,7 +472,8 @@ void Converter::ConvertVaListVarDecl(clang::VarDecl *decl) { // va_list local variable StrCat(keyword::kLet); } - StrCat(keyword_mut_, GetNamedDeclAsString(decl), token::kColon, "VaList"); + StrCat(keyword_mut_, GetNamedDeclAsString(decl), token::kColon, + "*const VaArg"); } bool Converter::NeedsMut(const clang::VarDecl *decl, clang::QualType type, @@ -1864,7 +1865,7 @@ void Converter::ConvertVariadicArg(clang::Expr *arg) { void Converter::ConvertVAArgCall(clang::CallExpr *expr) { if (IsBuiltinVaStart(expr)) { StrCat(ToString(expr->getArg(0)->IgnoreImpCasts()), - "= VaList::new(__args)"); + "= __args.as_ptr()"); return; } if (IsBuiltinVaEnd(expr)) { @@ -4244,7 +4245,7 @@ std::string Converter::GetDefaultAsString(clang::QualType qual_type) { if (IsVaListType(qual_type)) { computed_expr_type_ = ComputedExprType::FreshValue; - return "VaList::default()"; + return "::std::ptr::null()"; } if (auto arr = GetArrayDefaultAsString(qual_type); !arr.empty()) { diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 1fd66f1855..c8a399386b 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -259,7 +259,7 @@ std::string ConverterRefCount::BoxValue(std::string &&str) const { bool ConverterRefCount::Convert(clang::QualType qual_type) { // Catch va_list before desugaring if (IsVaListType(qual_type)) { - StrCat(BoxType("VaList")); + StrCat(BoxType("Ptr")); return false; } @@ -325,7 +325,7 @@ bool ConverterRefCount::VisitPointerType(clang::PointerType *type) { } if (IsVaListType(clang::QualType(type, 0))) { - StrCat("VaList"); + StrCat("Ptr"); return false; } @@ -792,6 +792,10 @@ void ConverterRefCount::EmitFunctionPreamble(clang::FunctionDecl *decl) { // name_2)'. We want to get the parameters from the definition if possible, // i.e. name_2. PushConversionKind push(*this, ConversionKind::FullRefCount); + if (decl->isVariadic()) { + StrCat("let __args: Value> = " + "Rc::new(RefCell::new(__args.into()));"); + } auto params = decl->getDefinition() ? decl->getDefinition()->parameters() : decl->parameters(); for (auto *param : params) { @@ -854,7 +858,7 @@ void ConverterRefCount::ConvertVaListVarDecl(clang::VarDecl *decl) { StrCat(keyword::kLet); } - StrCat(GetNamedDeclAsString(decl), token::kColon, "Value"); + StrCat(GetNamedDeclAsString(decl), token::kColon, "Value>"); } bool ConverterRefCount::ConvertVarDeclSkipInit(clang::VarDecl *decl) { @@ -1283,7 +1287,12 @@ void ConverterRefCount::ConvertPrintf(clang::CallExpr *expr) { } bool ConverterRefCount::VisitCallExpr(clang::CallExpr *expr) { - if (IsBuiltinVaStart(expr) || IsBuiltinVaEnd(expr) || IsBuiltinVaCopy(expr)) { + if (IsBuiltinVaStart(expr)) { + StrCat(ToString(expr->getArg(0)->IgnoreImpCasts()), + "= __args.as_pointer()"); + return false; + } + if (IsBuiltinVaEnd(expr) || IsBuiltinVaCopy(expr)) { ConvertVAArgCall(expr); return false; } @@ -2526,7 +2535,7 @@ std::string ConverterRefCount::GetDefaultAsString(clang::QualType qual_type) { if (IsVaListType(qual_type)) { computed_expr_type_ = ComputedExprType::FreshValue; - return BoxValue("VaList::default()"); + return BoxValue("Ptr::::default()"); } if (auto arr = GetArrayDefaultAsString(qual_type); !arr.empty()) { diff --git a/libcc2rs/src/va_args.rs b/libcc2rs/src/va_args.rs index b2d1b4a514..753fabdf55 100644 --- a/libcc2rs/src/va_args.rs +++ b/libcc2rs/src/va_args.rs @@ -5,6 +5,8 @@ use std::any::Any; use std::ffi::c_void; use std::rc::Rc; +use crate::inc::PrefixInc; +use crate::rc::Ptr; use crate::void::AnyPtr; #[derive(Clone)] @@ -52,27 +54,28 @@ impl From> for VaAr } } -#[derive(Clone, Default)] -pub struct VaList { - args: Rc<[VaArg]>, - pos: usize, +impl crate::reinterpret::ByteRepr for VaArg {} + +impl Ptr { + pub fn arg(&mut self) -> T { + let val = self.with(T::get); + self.prefix_inc(); + val + } } -impl crate::reinterpret::ByteRepr for VaList {} +pub trait VaArgs { + unsafe fn arg(&mut self) -> T; +} -impl VaList { - pub fn new(args: &[VaArg]) -> Self { - VaList { - args: Rc::from(args), - pos: 0, +impl VaArgs for *const VaArg { + unsafe fn arg(&mut self) -> T { + unsafe { + let val = T::get(&**self); + *self = self.add(1); + val } } - - pub fn arg(&mut self) -> T { - let val = &self.args[self.pos]; - self.pos += 1; - T::get(val) - } } pub trait VaArgGet { From ce9d59ef988d7dd4250e4496dc81d6e31a6485dc Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sat, 10 Oct 2026 13:06:39 +0100 Subject: [PATCH 4/5] Update tests --- cpp2rust/converter/converter.cpp | 3 +-- tests/unit/out/refcount/va_arg_chain.rs | 13 +++++++------ tests/unit/out/refcount/va_arg_concat.rs | 5 +++-- tests/unit/out/refcount/va_arg_conditional.rs | 5 +++-- tests/unit/out/refcount/va_arg_copy.rs | 7 ++++--- tests/unit/out/refcount/va_arg_fn_ptr.rs | 10 ++++++---- tests/unit/out/refcount/va_arg_forward.rs | 9 +++++---- tests/unit/out/refcount/va_arg_mixed_int_ptr.rs | 5 +++-- tests/unit/out/refcount/va_arg_mixed_types.rs | 5 +++-- .../out/refcount/va_arg_non_primitive_ptrs.rs | 5 +++-- tests/unit/out/refcount/va_arg_null_int_ptr.rs | 5 +++-- tests/unit/out/refcount/va_arg_printf.rs | 14 ++++++++------ tests/unit/out/refcount/va_arg_promotion.rs | 5 +++-- tests/unit/out/refcount/va_arg_snprintf.rs | 5 +++-- tests/unit/out/refcount/va_arg_struct_ctx.rs | 10 ++++++---- tests/unit/out/refcount/va_arg_two_passes.rs | 7 ++++--- tests/unit/out/refcount/va_arg_void_ptr.rs | 5 +++-- tests/unit/out/refcount/va_list_field.rs | 16 +++++++++------- tests/unit/out/unsafe/va_arg_chain.rs | 8 ++++---- tests/unit/out/unsafe/va_arg_concat.rs | 4 ++-- tests/unit/out/unsafe/va_arg_conditional.rs | 4 ++-- tests/unit/out/unsafe/va_arg_copy.rs | 6 +++--- tests/unit/out/unsafe/va_arg_fn_ptr.rs | 8 ++++---- tests/unit/out/unsafe/va_arg_forward.rs | 6 +++--- tests/unit/out/unsafe/va_arg_mixed_int_ptr.rs | 4 ++-- tests/unit/out/unsafe/va_arg_mixed_types.rs | 4 ++-- .../unit/out/unsafe/va_arg_non_primitive_ptrs.rs | 4 ++-- tests/unit/out/unsafe/va_arg_null_int_ptr.rs | 4 ++-- tests/unit/out/unsafe/va_arg_printf.rs | 10 +++++----- tests/unit/out/unsafe/va_arg_promotion.rs | 4 ++-- tests/unit/out/unsafe/va_arg_snprintf.rs | 4 ++-- tests/unit/out/unsafe/va_arg_struct_ctx.rs | 8 ++++---- tests/unit/out/unsafe/va_arg_two_passes.rs | 6 +++--- tests/unit/out/unsafe/va_arg_void_ptr.rs | 4 ++-- tests/unit/out/unsafe/va_list_field.rs | 16 ++++++++-------- 35 files changed, 129 insertions(+), 109 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 6e3c8cb62c..adbfc3e784 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -1864,8 +1864,7 @@ void Converter::ConvertVariadicArg(clang::Expr *arg) { void Converter::ConvertVAArgCall(clang::CallExpr *expr) { if (IsBuiltinVaStart(expr)) { - StrCat(ToString(expr->getArg(0)->IgnoreImpCasts()), - "= __args.as_ptr()"); + StrCat(ToString(expr->getArg(0)->IgnoreImpCasts()), "= __args.as_ptr()"); return; } if (IsBuiltinVaEnd(expr)) { diff --git a/tests/unit/out/refcount/va_arg_chain.rs b/tests/unit/out/refcount/va_arg_chain.rs index 11a179bcf4..c6d7386948 100644 --- a/tests/unit/out/refcount/va_arg_chain.rs +++ b/tests/unit/out/refcount/va_arg_chain.rs @@ -6,8 +6,8 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn extract_nth_0(mut n: i32, ap: VaList) -> i32 { - let ap: Value = Rc::new(RefCell::new(ap)); +pub fn extract_nth_0(mut n: i32, ap: Ptr) -> i32 { + let ap: Value> = Rc::new(RefCell::new(ap)); let mut i: i32 = 0; 'loop_: while (((i < n) as i32) != 0) { (*ap.borrow_mut()).arg::(); @@ -15,14 +15,15 @@ pub fn extract_nth_0(mut n: i32, ap: VaList) -> i32 { } return (*ap.borrow_mut()).arg::(); } -pub fn middle_layer_1(mut n: i32, ap: VaList) -> i32 { - let ap: Value = Rc::new(RefCell::new(ap)); +pub fn middle_layer_1(mut n: i32, ap: Ptr) -> i32 { + let ap: Value> = Rc::new(RefCell::new(ap)); return ({ extract_nth_0(n, (*ap.borrow()).clone()) }); } pub fn top_level_2(n: i32, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let n: Value = Rc::new(RefCell::new(n)); - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); let mut result: i32 = ({ middle_layer_1((*n.borrow()), (*ap.borrow()).clone()) }); return result; } diff --git a/tests/unit/out/refcount/va_arg_concat.rs b/tests/unit/out/refcount/va_arg_concat.rs index e80ea00c74..02efefa8c4 100644 --- a/tests/unit/out/refcount/va_arg_concat.rs +++ b/tests/unit/out/refcount/va_arg_concat.rs @@ -7,10 +7,11 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn sum_ints_0(first: i32, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let first: Value = Rc::new(RefCell::new(first)); - let args: Value = Rc::new(RefCell::new(VaList::default())); + let args: Value> = Rc::new(RefCell::new(Ptr::::default())); let mut total: i32 = (*first.borrow()); - (*args.borrow_mut()) = VaList::new(__args); + (*args.borrow_mut()) = __args.as_pointer(); let mut val: i32 = 0_i32; 'loop_: while (((({ val = (*args.borrow_mut()).arg::(); diff --git a/tests/unit/out/refcount/va_arg_conditional.rs b/tests/unit/out/refcount/va_arg_conditional.rs index 3a7e44b2ea..d514efe147 100644 --- a/tests/unit/out/refcount/va_arg_conditional.rs +++ b/tests/unit/out/refcount/va_arg_conditional.rs @@ -7,10 +7,11 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn conditional_log_0(mut verbose: i32, fmt: Ptr, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let fmt: Value> = Rc::new(RefCell::new(fmt)); if (verbose != 0) { - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); let mut result: i32 = (*ap.borrow_mut()).arg::(); return result; } diff --git a/tests/unit/out/refcount/va_arg_copy.rs b/tests/unit/out/refcount/va_arg_copy.rs index dc26a093d2..2aabfaf044 100644 --- a/tests/unit/out/refcount/va_arg_copy.rs +++ b/tests/unit/out/refcount/va_arg_copy.rs @@ -7,10 +7,11 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn sum_with_copy_0(count: i32, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let count: Value = Rc::new(RefCell::new(count)); - let ap: Value = Rc::new(RefCell::new(VaList::default())); - let aq: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + let aq: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); (*aq.borrow_mut()) = (*ap.borrow_mut()).clone(); let mut sum1: i32 = 0; let mut i: i32 = 0; diff --git a/tests/unit/out/refcount/va_arg_fn_ptr.rs b/tests/unit/out/refcount/va_arg_fn_ptr.rs index 430bd22933..b5945c798e 100644 --- a/tests/unit/out/refcount/va_arg_fn_ptr.rs +++ b/tests/unit/out/refcount/va_arg_fn_ptr.rs @@ -16,17 +16,19 @@ pub fn add_2(mut a: i32, mut b: i32) -> i32 { return (a + b); } pub fn apply_unary_3(x: i32, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let x: Value = Rc::new(RefCell::new(x)); - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); let mut fn_: FnPtr i32> = (*ap.borrow_mut()).arg:: i32>>(); let mut result: i32 = ({ fn_.call((*x.borrow())) }); return result; } pub fn apply_binary_4(mut a: i32, b: i32, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let b: Value = Rc::new(RefCell::new(b)); - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); let mut fn_: FnPtr i32> = (*ap.borrow_mut()).arg:: i32>>(); let mut result: i32 = ({ fn_.call(a, (*b.borrow())) }); diff --git a/tests/unit/out/refcount/va_arg_forward.rs b/tests/unit/out/refcount/va_arg_forward.rs index 972f468571..26265a1082 100644 --- a/tests/unit/out/refcount/va_arg_forward.rs +++ b/tests/unit/out/refcount/va_arg_forward.rs @@ -6,8 +6,8 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn inner_0(mut count: i32, ap: VaList) -> i32 { - let ap: Value = Rc::new(RefCell::new(ap)); +pub fn inner_0(mut count: i32, ap: Ptr) -> i32 { + let ap: Value> = Rc::new(RefCell::new(ap)); let mut total: i32 = 0; let mut i: i32 = 0; 'loop_: while (((i < count) as i32) != 0) { @@ -17,9 +17,10 @@ pub fn inner_0(mut count: i32, ap: VaList) -> i32 { return total; } pub fn outer_1(count: i32, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let count: Value = Rc::new(RefCell::new(count)); - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); let mut result: i32 = ({ inner_0((*count.borrow()), (*ap.borrow()).clone()) }); return result; } diff --git a/tests/unit/out/refcount/va_arg_mixed_int_ptr.rs b/tests/unit/out/refcount/va_arg_mixed_int_ptr.rs index 553d9d4eab..e312c7d3c6 100644 --- a/tests/unit/out/refcount/va_arg_mixed_int_ptr.rs +++ b/tests/unit/out/refcount/va_arg_mixed_int_ptr.rs @@ -7,9 +7,10 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn mixed_args_0(count: i32, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let count: Value = Rc::new(RefCell::new(count)); - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); let mut total: i32 = 0; let mut i: i32 = 0; 'loop_: while (((i < (*count.borrow())) as i32) != 0) { diff --git a/tests/unit/out/refcount/va_arg_mixed_types.rs b/tests/unit/out/refcount/va_arg_mixed_types.rs index de68481b65..41142abdc8 100644 --- a/tests/unit/out/refcount/va_arg_mixed_types.rs +++ b/tests/unit/out/refcount/va_arg_mixed_types.rs @@ -15,9 +15,10 @@ pub struct pair { pub b: i32, } pub fn sum_mixed_0(count: i32, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let count: Value = Rc::new(RefCell::new(count)); - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); let mut total: i32 = 0; let mut i: i32 = 0; 'loop_: while (((i < (*count.borrow())) as i32) != 0) { diff --git a/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs b/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs index 6b90a28a41..8e8237ade2 100644 --- a/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs +++ b/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs @@ -21,9 +21,10 @@ pub const opt_OPT_FILE: opt = 1; pub const opt_OPT_NODE: opt = 2; pub const opt_OPT_NODE_OUT: opt = 3; pub fn dispatch_0(option: i32, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let option: Value = Rc::new(RefCell::new(option)); - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); let mut result: i32 = 0; 'switch: { match { (*option.borrow()) } { diff --git a/tests/unit/out/refcount/va_arg_null_int_ptr.rs b/tests/unit/out/refcount/va_arg_null_int_ptr.rs index 2716568635..0db9d3745c 100644 --- a/tests/unit/out/refcount/va_arg_null_int_ptr.rs +++ b/tests/unit/out/refcount/va_arg_null_int_ptr.rs @@ -7,9 +7,10 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn first_nonnull_0(count: i32, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let count: Value = Rc::new(RefCell::new(count)); - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); let mut result: i32 = -1_i32; let mut i: i32 = 0; 'loop_: while (((i < (*count.borrow())) as i32) != 0) { diff --git a/tests/unit/out/refcount/va_arg_printf.rs b/tests/unit/out/refcount/va_arg_printf.rs index 6f914b62e8..03c6ababbc 100644 --- a/tests/unit/out/refcount/va_arg_printf.rs +++ b/tests/unit/out/refcount/va_arg_printf.rs @@ -6,22 +6,24 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn logf_impl_0(mut fmt: Ptr, ap: VaList) -> i32 { - let ap: Value = Rc::new(RefCell::new(ap)); +pub fn logf_impl_0(mut fmt: Ptr, ap: Ptr) -> i32 { + let ap: Value> = Rc::new(RefCell::new(ap)); &(fmt); return ({ (*ap.borrow_mut()).arg::() } + { (*ap.borrow_mut()).arg::() }); } pub fn logf_1(fmt: Ptr, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let fmt: Value> = Rc::new(RefCell::new(fmt)); - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); let mut result: i32 = ({ logf_impl_0((*fmt.borrow()).clone(), (*ap.borrow()).clone()) }); return result; } pub fn lenf_2(fmt: Ptr, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let fmt: Value> = Rc::new(RefCell::new(fmt)); - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); let mut s: Ptr = (*ap.borrow_mut()).arg::>(); let mut result: i32 = (s.to_c_string_iterator().count() as i32); return result; diff --git a/tests/unit/out/refcount/va_arg_promotion.rs b/tests/unit/out/refcount/va_arg_promotion.rs index b645f3d809..2c6adf40bc 100644 --- a/tests/unit/out/refcount/va_arg_promotion.rs +++ b/tests/unit/out/refcount/va_arg_promotion.rs @@ -7,9 +7,10 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn test_promotions_0(count: i32, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let count: Value = Rc::new(RefCell::new(count)); - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); let mut a: i32 = (*ap.borrow_mut()).arg::(); let mut b: i32 = (*ap.borrow_mut()).arg::(); let mut c: f64 = (*ap.borrow_mut()).arg::(); diff --git a/tests/unit/out/refcount/va_arg_snprintf.rs b/tests/unit/out/refcount/va_arg_snprintf.rs index 48f15699a3..c9885c3753 100644 --- a/tests/unit/out/refcount/va_arg_snprintf.rs +++ b/tests/unit/out/refcount/va_arg_snprintf.rs @@ -7,9 +7,10 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn extract_first_0(mut buf: Ptr, mut size: i32, fmt: Ptr, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let fmt: Value> = Rc::new(RefCell::new(fmt)); - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); let mut n: i32 = (*ap.borrow_mut()).arg::(); elem!(buf, 0).write({ (n as i8) }); return n; diff --git a/tests/unit/out/refcount/va_arg_struct_ctx.rs b/tests/unit/out/refcount/va_arg_struct_ctx.rs index caa695fb42..410332747d 100644 --- a/tests/unit/out/refcount/va_arg_struct_ctx.rs +++ b/tests/unit/out/refcount/va_arg_struct_ctx.rs @@ -15,10 +15,11 @@ pub struct context { pub last_error: i32, } pub fn set_error_0(mut ctx: Ptr, fmt: Ptr, __args: &[VaArg]) { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let fmt: Value> = Rc::new(RefCell::new(fmt)); if (ctx.with(|__s| __s.verbose) != 0) { - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); let __rhs = (*ap.borrow_mut()).arg::(); field!(ctx, last_error).write(__rhs); } @@ -46,9 +47,10 @@ impl Default for value { } } pub fn pick_1(use_long: i32, __args: &[VaArg]) -> i64 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let use_long: Value = Rc::new(RefCell::new(use_long)); - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); let v: Value = Rc::new(RefCell::new((*ap.borrow_mut()).arg::())); if ((*use_long.borrow()) != 0) { return (value::l(v.as_pointer()).read()); diff --git a/tests/unit/out/refcount/va_arg_two_passes.rs b/tests/unit/out/refcount/va_arg_two_passes.rs index d6a4d6a47a..1e9f8e86f6 100644 --- a/tests/unit/out/refcount/va_arg_two_passes.rs +++ b/tests/unit/out/refcount/va_arg_two_passes.rs @@ -7,11 +7,12 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn sum_then_product_0(first: i32, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let first: Value = Rc::new(RefCell::new(first)); - let ap: Value = Rc::new(RefCell::new(VaList::default())); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); let mut sum: i32 = (*first.borrow()); let mut product: i32 = (*first.borrow()); - (*ap.borrow_mut()) = VaList::new(__args); + (*ap.borrow_mut()) = __args.as_pointer(); let mut val: i32 = 0_i32; 'loop_: while (((({ val = (*ap.borrow_mut()).arg::(); @@ -21,7 +22,7 @@ pub fn sum_then_product_0(first: i32, __args: &[VaArg]) -> i32 { { sum += val; } - (*ap.borrow_mut()) = VaList::new(__args); + (*ap.borrow_mut()) = __args.as_pointer(); 'loop_: while (((({ val = (*ap.borrow_mut()).arg::(); val diff --git a/tests/unit/out/refcount/va_arg_void_ptr.rs b/tests/unit/out/refcount/va_arg_void_ptr.rs index 17ea4b67a9..2f311d5523 100644 --- a/tests/unit/out/refcount/va_arg_void_ptr.rs +++ b/tests/unit/out/refcount/va_arg_void_ptr.rs @@ -19,10 +19,11 @@ pub type field = u32; pub const field_FIELD_SLOT: field = 0; pub const field_FIELD_LEVEL: field = 1; pub fn registry_update_0(mut r: Ptr, field: field, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let field: Value = Rc::new(RefCell::new(field)); let mut result: i32 = 0; - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); 'switch: { match { ((*field.borrow()) as u32) } { __v if __v == ((field_FIELD_SLOT as i32) as u32) => { diff --git a/tests/unit/out/refcount/va_list_field.rs b/tests/unit/out/refcount/va_list_field.rs index 45d671d6c9..1f7f1e5a47 100644 --- a/tests/unit/out/refcount/va_list_field.rs +++ b/tests/unit/out/refcount/va_list_field.rs @@ -7,9 +7,10 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn sum_0(n: i32, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let n: Value = Rc::new(RefCell::new(n)); - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); let guard: Value = Rc::new(RefCell::new(Guard_1::new({ ap.as_pointer() }))); let _dtor_guard = ScopedDestructor::new(&guard, |__p| __p.destructor()); let mut total: i32 = 0; @@ -25,12 +26,12 @@ pub fn sum_0(n: i32, __args: &[VaArg]) -> i32 { pub struct Guard_1 { #[offset(0)] #[byte_size(8)] - pub ap: Ptr, + pub ap: Ptr>, #[offset(8)] pub active: bool, } impl Guard_1 { - pub fn new(val: Ptr) -> Self { + pub fn new(val: Ptr>) -> Self { Self { ap: (val).clone(), active: true, @@ -38,9 +39,10 @@ impl Guard_1 { } } pub fn sum_ptr_2(n: i32, __args: &[VaArg]) -> i32 { + let __args: Value> = Rc::new(RefCell::new(__args.into())); let n: Value = Rc::new(RefCell::new(n)); - let ap: Value = Rc::new(RefCell::new(VaList::default())); - (*ap.borrow_mut()) = VaList::new(__args); + let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); + (*ap.borrow_mut()) = __args.as_pointer(); let mut cursor: Cursor_3 = Cursor_3 { ap: (ap.as_pointer()), }; @@ -57,7 +59,7 @@ pub fn sum_ptr_2(n: i32, __args: &[VaArg]) -> i32 { pub struct Cursor_3 { #[offset(0)] #[byte_size(8)] - pub ap: Ptr, + pub ap: Ptr>, } pub fn main() { __cpp2rust_init_globals(); diff --git a/tests/unit/out/unsafe/va_arg_chain.rs b/tests/unit/out/unsafe/va_arg_chain.rs index ac557ee287..0f1b373b1c 100644 --- a/tests/unit/out/unsafe/va_arg_chain.rs +++ b/tests/unit/out/unsafe/va_arg_chain.rs @@ -6,7 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn extract_nth_0(mut n: i32, mut ap: VaList) -> i32 { +pub unsafe fn extract_nth_0(mut n: i32, mut ap: *const VaArg) -> i32 { let mut i: i32 = 0; 'loop_: while ((((i) < (n)) as i32) != 0) { ap.arg::(); @@ -14,12 +14,12 @@ pub unsafe fn extract_nth_0(mut n: i32, mut ap: VaList) -> i32 { } return ap.arg::(); } -pub unsafe fn middle_layer_1(mut n: i32, mut ap: VaList) -> i32 { +pub unsafe fn middle_layer_1(mut n: i32, mut ap: *const VaArg) -> i32 { return (unsafe { extract_nth_0(n, ap) }); } pub unsafe fn top_level_2(mut n: i32, __args: &[VaArg]) -> i32 { - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); let mut result: i32 = (unsafe { middle_layer_1(n, ap) }); return result; } diff --git a/tests/unit/out/unsafe/va_arg_concat.rs b/tests/unit/out/unsafe/va_arg_concat.rs index f225947b05..41bba3cb57 100644 --- a/tests/unit/out/unsafe/va_arg_concat.rs +++ b/tests/unit/out/unsafe/va_arg_concat.rs @@ -7,9 +7,9 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn sum_ints_0(mut first: i32, __args: &[VaArg]) -> i32 { - let mut args: VaList = VaList::default(); + let mut args: *const VaArg = ::std::ptr::null(); let mut total: i32 = first; - args = VaList::new(__args); + args = __args.as_ptr(); let mut val: i32 = 0_i32; 'loop_: while (((({ val = args.arg::(); diff --git a/tests/unit/out/unsafe/va_arg_conditional.rs b/tests/unit/out/unsafe/va_arg_conditional.rs index bb3e4429b7..2baf70b2d8 100644 --- a/tests/unit/out/unsafe/va_arg_conditional.rs +++ b/tests/unit/out/unsafe/va_arg_conditional.rs @@ -12,8 +12,8 @@ pub unsafe fn conditional_log_0( __args: &[VaArg], ) -> i32 { if (verbose != 0) { - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); let mut result: i32 = ap.arg::(); return result; } diff --git a/tests/unit/out/unsafe/va_arg_copy.rs b/tests/unit/out/unsafe/va_arg_copy.rs index d3a4181126..5025b16294 100644 --- a/tests/unit/out/unsafe/va_arg_copy.rs +++ b/tests/unit/out/unsafe/va_arg_copy.rs @@ -7,9 +7,9 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn sum_with_copy_0(mut count: i32, __args: &[VaArg]) -> i32 { - let mut ap: VaList = VaList::default(); - let mut aq: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + let mut aq: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); aq = ap.clone(); let mut sum1: i32 = 0; let mut i: i32 = 0; diff --git a/tests/unit/out/unsafe/va_arg_fn_ptr.rs b/tests/unit/out/unsafe/va_arg_fn_ptr.rs index 67ae7edc15..7892635198 100644 --- a/tests/unit/out/unsafe/va_arg_fn_ptr.rs +++ b/tests/unit/out/unsafe/va_arg_fn_ptr.rs @@ -16,8 +16,8 @@ pub unsafe fn add_2(mut a: i32, mut b: i32) -> i32 { return ((a) + (b)); } pub unsafe fn apply_unary_3(mut x: i32, __args: &[VaArg]) -> i32 { - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); let mut fn_: Option i32> = std::mem::transmute::< *mut ::libc::c_void, Option i32>, @@ -26,8 +26,8 @@ pub unsafe fn apply_unary_3(mut x: i32, __args: &[VaArg]) -> i32 { return result; } pub unsafe fn apply_binary_4(mut a: i32, mut b: i32, __args: &[VaArg]) -> i32 { - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); let mut fn_: Option i32> = std::mem::transmute::< *mut ::libc::c_void, Option i32>, diff --git a/tests/unit/out/unsafe/va_arg_forward.rs b/tests/unit/out/unsafe/va_arg_forward.rs index 571764b8fa..bccf0d8fc9 100644 --- a/tests/unit/out/unsafe/va_arg_forward.rs +++ b/tests/unit/out/unsafe/va_arg_forward.rs @@ -6,7 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn inner_0(mut count: i32, mut ap: VaList) -> i32 { +pub unsafe fn inner_0(mut count: i32, mut ap: *const VaArg) -> i32 { let mut total: i32 = 0; let mut i: i32 = 0; 'loop_: while ((((i) < (count)) as i32) != 0) { @@ -16,8 +16,8 @@ pub unsafe fn inner_0(mut count: i32, mut ap: VaList) -> i32 { return total; } pub unsafe fn outer_1(mut count: i32, __args: &[VaArg]) -> i32 { - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); let mut result: i32 = (unsafe { inner_0(count, ap) }); return result; } diff --git a/tests/unit/out/unsafe/va_arg_mixed_int_ptr.rs b/tests/unit/out/unsafe/va_arg_mixed_int_ptr.rs index 97e92cffac..6508cd4806 100644 --- a/tests/unit/out/unsafe/va_arg_mixed_int_ptr.rs +++ b/tests/unit/out/unsafe/va_arg_mixed_int_ptr.rs @@ -7,8 +7,8 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn mixed_args_0(mut count: i32, __args: &[VaArg]) -> i32 { - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); let mut total: i32 = 0; let mut i: i32 = 0; 'loop_: while ((((i) < (count)) as i32) != 0) { diff --git a/tests/unit/out/unsafe/va_arg_mixed_types.rs b/tests/unit/out/unsafe/va_arg_mixed_types.rs index 0afe111dda..94cbe33923 100644 --- a/tests/unit/out/unsafe/va_arg_mixed_types.rs +++ b/tests/unit/out/unsafe/va_arg_mixed_types.rs @@ -13,8 +13,8 @@ pub struct pair { pub b: i32, } pub unsafe fn sum_mixed_0(mut count: i32, __args: &[VaArg]) -> i32 { - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); let mut total: i32 = 0; let mut i: i32 = 0; 'loop_: while ((((i) < (count)) as i32) != 0) { diff --git a/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs b/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs index 4989e5e387..7259516c69 100644 --- a/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs +++ b/tests/unit/out/unsafe/va_arg_non_primitive_ptrs.rs @@ -18,8 +18,8 @@ pub const opt_OPT_FILE: opt = 1; pub const opt_OPT_NODE: opt = 2; pub const opt_OPT_NODE_OUT: opt = 3; pub unsafe fn dispatch_0(mut option: i32, __args: &[VaArg]) -> i32 { - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); let mut result: i32 = 0; 'switch: { match { option } { diff --git a/tests/unit/out/unsafe/va_arg_null_int_ptr.rs b/tests/unit/out/unsafe/va_arg_null_int_ptr.rs index 9c8db2eff7..38eebb0e5d 100644 --- a/tests/unit/out/unsafe/va_arg_null_int_ptr.rs +++ b/tests/unit/out/unsafe/va_arg_null_int_ptr.rs @@ -7,8 +7,8 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn first_nonnull_0(mut count: i32, __args: &[VaArg]) -> i32 { - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); let mut result: i32 = -1_i32; let mut i: i32 = 0; 'loop_: while ((((i) < (count)) as i32) != 0) { diff --git a/tests/unit/out/unsafe/va_arg_printf.rs b/tests/unit/out/unsafe/va_arg_printf.rs index 052e4ae90e..a1a758f539 100644 --- a/tests/unit/out/unsafe/va_arg_printf.rs +++ b/tests/unit/out/unsafe/va_arg_printf.rs @@ -6,19 +6,19 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn logf_impl_0(mut fmt: *const libc::c_char, mut ap: VaList) -> i32 { +pub unsafe fn logf_impl_0(mut fmt: *const libc::c_char, mut ap: *const VaArg) -> i32 { &(fmt); return ((ap.arg::()) + (ap.arg::())); } pub unsafe fn logf_1(mut fmt: *const libc::c_char, __args: &[VaArg]) -> i32 { - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); let mut result: i32 = (unsafe { logf_impl_0(fmt, ap) }); return result; } pub unsafe fn lenf_2(mut fmt: *const libc::c_char, __args: &[VaArg]) -> i32 { - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); let mut s: *const libc::c_char = ap.arg::<*const libc::c_char>(); let mut result: i32 = (libc::strlen(s) as i32); return result; diff --git a/tests/unit/out/unsafe/va_arg_promotion.rs b/tests/unit/out/unsafe/va_arg_promotion.rs index 99ae774f74..d9c00b5d4e 100644 --- a/tests/unit/out/unsafe/va_arg_promotion.rs +++ b/tests/unit/out/unsafe/va_arg_promotion.rs @@ -7,8 +7,8 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn test_promotions_0(mut count: i32, __args: &[VaArg]) -> i32 { - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); let mut a: i32 = ap.arg::(); let mut b: i32 = ap.arg::(); let mut c: f64 = ap.arg::(); diff --git a/tests/unit/out/unsafe/va_arg_snprintf.rs b/tests/unit/out/unsafe/va_arg_snprintf.rs index 26b78730ab..ba6e5071b1 100644 --- a/tests/unit/out/unsafe/va_arg_snprintf.rs +++ b/tests/unit/out/unsafe/va_arg_snprintf.rs @@ -12,8 +12,8 @@ pub unsafe fn extract_first_0( mut fmt: *const libc::c_char, __args: &[VaArg], ) -> i32 { - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); let mut n: i32 = ap.arg::(); (*buf.offset((0) as isize)) = (n as libc::c_char); return n; diff --git a/tests/unit/out/unsafe/va_arg_struct_ctx.rs b/tests/unit/out/unsafe/va_arg_struct_ctx.rs index 064ebbdc81..6fddfea1ae 100644 --- a/tests/unit/out/unsafe/va_arg_struct_ctx.rs +++ b/tests/unit/out/unsafe/va_arg_struct_ctx.rs @@ -14,8 +14,8 @@ pub struct context { } pub unsafe fn set_error_0(mut ctx: *mut context, mut fmt: *const libc::c_char, __args: &[VaArg]) { if ((*ctx).verbose != 0) { - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); (*ctx).last_error = ap.arg::(); } } @@ -31,8 +31,8 @@ impl Default for value { } } pub unsafe fn pick_1(mut use_long: i32, __args: &[VaArg]) -> i64 { - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); let mut v: value = ap.arg::(); if (use_long != 0) { return v.l; diff --git a/tests/unit/out/unsafe/va_arg_two_passes.rs b/tests/unit/out/unsafe/va_arg_two_passes.rs index 0b91529961..93c040ab74 100644 --- a/tests/unit/out/unsafe/va_arg_two_passes.rs +++ b/tests/unit/out/unsafe/va_arg_two_passes.rs @@ -7,10 +7,10 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn sum_then_product_0(mut first: i32, __args: &[VaArg]) -> i32 { - let mut ap: VaList = VaList::default(); + let mut ap: *const VaArg = ::std::ptr::null(); let mut sum: i32 = first; let mut product: i32 = first; - ap = VaList::new(__args); + ap = __args.as_ptr(); let mut val: i32 = 0_i32; 'loop_: while (((({ val = ap.arg::(); @@ -20,7 +20,7 @@ pub unsafe fn sum_then_product_0(mut first: i32, __args: &[VaArg]) -> i32 { { sum += val; } - ap = VaList::new(__args); + ap = __args.as_ptr(); 'loop_: while (((({ val = ap.arg::(); val diff --git a/tests/unit/out/unsafe/va_arg_void_ptr.rs b/tests/unit/out/unsafe/va_arg_void_ptr.rs index ec5e1a1a6d..45f9a38a8f 100644 --- a/tests/unit/out/unsafe/va_arg_void_ptr.rs +++ b/tests/unit/out/unsafe/va_arg_void_ptr.rs @@ -17,8 +17,8 @@ pub const field_FIELD_SLOT: field = 0; pub const field_FIELD_LEVEL: field = 1; pub unsafe fn registry_update_0(mut r: *mut registry, mut field: field, __args: &[VaArg]) -> i32 { let mut result: i32 = 0; - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); 'switch: { match { (field as u32) } { __v if __v == ((field_FIELD_SLOT as i32) as u32) => { diff --git a/tests/unit/out/unsafe/va_list_field.rs b/tests/unit/out/unsafe/va_list_field.rs index 14948ff551..c01ce88316 100644 --- a/tests/unit/out/unsafe/va_list_field.rs +++ b/tests/unit/out/unsafe/va_list_field.rs @@ -7,8 +7,8 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn sum_0(mut n: i32, __args: &[VaArg]) -> i32 { - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); let mut guard: Guard_1 = Guard_1::new({ &mut ap }); let _dtor_guard = ScopedDestructorUnsafe::new(&raw mut guard, Guard_1::destructor); let mut total: i32 = 0; @@ -22,11 +22,11 @@ pub unsafe fn sum_0(mut n: i32, __args: &[VaArg]) -> i32 { #[repr(C)] #[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] pub struct Guard_1 { - pub ap: *mut VaList, + pub ap: *mut *const VaArg, pub active: bool, } impl Guard_1 { - pub unsafe fn new(val: *mut VaList) -> Self { + pub unsafe fn new(val: *mut *const VaArg) -> Self { let mut this = Self { ap: val, active: true, @@ -38,10 +38,10 @@ impl Guard_1 { } } pub unsafe fn sum_ptr_2(mut n: i32, __args: &[VaArg]) -> i32 { - let mut ap: VaList = VaList::default(); - ap = VaList::new(__args); + let mut ap: *const VaArg = ::std::ptr::null(); + ap = __args.as_ptr(); let mut cursor: Cursor_3 = Cursor_3 { - ap: (&mut ap as *mut VaList), + ap: (&mut ap as *mut *const VaArg), }; let mut total: i32 = 0; let mut i: i32 = 0; @@ -54,7 +54,7 @@ pub unsafe fn sum_ptr_2(mut n: i32, __args: &[VaArg]) -> i32 { #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] pub struct Cursor_3 { - pub ap: *mut VaList, + pub ap: *mut *const VaArg, } pub fn main() { unsafe { From e4300352b4deb3f935fc721e9888ee05cc254857 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sat, 10 Oct 2026 13:13:40 +0100 Subject: [PATCH 5/5] Implement VaArgs for both Ptr and raw ptr --- libcc2rs/src/va_args.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libcc2rs/src/va_args.rs b/libcc2rs/src/va_args.rs index 753fabdf55..b982d85021 100644 --- a/libcc2rs/src/va_args.rs +++ b/libcc2rs/src/va_args.rs @@ -56,20 +56,20 @@ impl From> for VaAr impl crate::reinterpret::ByteRepr for VaArg {} -impl Ptr { - pub fn arg(&mut self) -> T { +pub trait VaArgs { + fn arg(&mut self) -> T; +} + +impl VaArgs for Ptr { + fn arg(&mut self) -> T { let val = self.with(T::get); self.prefix_inc(); val } } -pub trait VaArgs { - unsafe fn arg(&mut self) -> T; -} - impl VaArgs for *const VaArg { - unsafe fn arg(&mut self) -> T { + fn arg(&mut self) -> T { unsafe { let val = T::get(&**self); *self = self.add(1);