Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cpp2rust/converter/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,6 @@ std::optional<std::string> Converter::TryPluginConvert(clang::CallExpr *call) {

void Converter::ConvertVariadicArg(clang::Expr *arg) {
if (arg->getType()->isFunctionPointerType()) {
PushParen p(*this);
Convert(arg);
StrCat(".map_or(::std::ptr::null_mut(), |f| f as *mut ::libc::c_void)");
return;
Expand Down Expand Up @@ -1706,7 +1705,10 @@ void Converter::ConvertGenericCallExpr(clang::CallExpr *expr) {
StrCat("& [");
for (unsigned i = num_named_params; i < num_args; ++i) {
auto *arg = expr->getArg(i + arg_begin);
ConvertVariadicArg(arg);
{
PushParen p(*this);
ConvertVariadicArg(arg);
}
StrCat(".into()", token::kComma);
}
StrCat(']');
Expand Down
4 changes: 4 additions & 0 deletions rules/cstring/tgt_refcount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ fn f4(a0: AnyPtr, a1: AnyPtr, a2: usize) -> AnyPtr {
a0.memcpy(&a1, a2 as usize);
a0.clone()
}

unsafe fn f7(a0: Ptr<u8>) -> u64 {
a0.to_string_iterator().count() as u64
}
9 changes: 6 additions & 3 deletions tests/unit/out/refcount/va_arg_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,24 @@ fn main_0() -> i32 {
assert!(
(((({
let _n: i32 = 2;
top_level_2(_n, &[100.into(), 200.into(), 300.into(), 400.into()])
top_level_2(
_n,
&[(100).into(), (200).into(), (300).into(), (400).into()],
)
}) == 300) as i32)
!= 0)
);
assert!(
(((({
let _n: i32 = 0;
top_level_2(_n, &[42.into(), 99.into()])
top_level_2(_n, &[(42).into(), (99).into()])
}) == 42) as i32)
!= 0)
);
assert!(
(((({
let _n: i32 = 3;
top_level_2(_n, &[1.into(), 2.into(), 3.into(), 4.into()])
top_level_2(_n, &[(1).into(), (2).into(), (3).into(), (4).into()])
}) == 4) as i32)
!= 0)
);
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/out/refcount/va_arg_concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,24 @@ fn main_0() -> i32 {
assert!(
(((({
let _first: i32 = 1;
sum_ints_0(_first, &[2.into(), 3.into(), 4.into(), 0.into()])
sum_ints_0(_first, &[(2).into(), (3).into(), (4).into(), (0).into()])
}) == 10) as i32)
!= 0)
);
assert!(
(((({
let _first: i32 = 100;
sum_ints_0(_first, &[0.into()])
sum_ints_0(_first, &[(0).into()])
}) == 100) as i32)
!= 0)
);
assert!(
(((({
let _first: i32 = 5;
sum_ints_0(_first, &[5.into(), 5.into(), 5.into(), 5.into(), 0.into()])
sum_ints_0(
_first,
&[(5).into(), (5).into(), (5).into(), (5).into(), (0).into()],
)
}) == 25) as i32)
!= 0)
);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/out/refcount/va_arg_conditional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ fn main_0() -> i32 {
(((({
let _verbose: i32 = 1;
let _fmt: Ptr<u8> = Ptr::from_string_literal(b"%d");
conditional_log_0(_verbose, _fmt, &[42.into()])
conditional_log_0(_verbose, _fmt, &[(42).into()])
}) == 42) as i32)
!= 0)
);
assert!(
(((({
let _verbose: i32 = 0;
let _fmt: Ptr<u8> = Ptr::from_string_literal(b"%d");
conditional_log_0(_verbose, _fmt, &[99.into()])
conditional_log_0(_verbose, _fmt, &[(99).into()])
}) == -1_i32) as i32)
!= 0)
);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/refcount/va_arg_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn main_0() -> i32 {
assert!(
(((({
let _count: i32 = 3;
sum_with_copy_0(_count, &[10.into(), 20.into(), 30.into()])
sum_with_copy_0(_count, &[(10).into(), (20).into(), (30).into()])
}) == 120) as i32)
!= 0)
);
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/out/refcount/va_arg_fn_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ fn main_0() -> i32 {
assert!(
(((({
let _x: i32 = 5;
apply_unary_3(_x, &[FnPtr::<fn(i32) -> i32>::new(square_0).into()])
apply_unary_3(_x, &[(FnPtr::<fn(i32) -> i32>::new(square_0)).into()])
}) == 25) as i32)
!= 0)
);
assert!(
(((({
let _x: i32 = 7;
apply_unary_3(_x, &[FnPtr::<fn(i32) -> i32>::new(negate_1).into()])
apply_unary_3(_x, &[(FnPtr::<fn(i32) -> i32>::new(negate_1)).into()])
}) == -7_i32) as i32)
!= 0)
);
assert!(
(((({
let _a: i32 = 3;
let _b: i32 = 4;
apply_binary_4(_a, _b, &[FnPtr::<fn(i32, i32) -> i32>::new(add_2).into()])
apply_binary_4(_a, _b, &[(FnPtr::<fn(i32, i32) -> i32>::new(add_2)).into()])
}) == 7) as i32)
!= 0)
);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/out/refcount/va_arg_forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ fn main_0() -> i32 {
assert!(
(((({
let _count: i32 = 3;
outer_1(_count, &[10.into(), 20.into(), 30.into()])
outer_1(_count, &[(10).into(), (20).into(), (30).into()])
}) == 60) as i32)
!= 0)
);
assert!(
(((({
let _count: i32 = 1;
outer_1(_count, &[42.into()])
outer_1(_count, &[(42).into()])
}) == 42) as i32)
!= 0)
);
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/out/refcount/va_arg_mixed_int_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ fn main_0() -> i32 {
mixed_args_0(
_count,
&[
0.into(),
10.into(),
1.into(),
(0).into(),
(10).into(),
(1).into(),
(x.as_pointer()).into(),
0.into(),
20.into(),
(0).into(),
(20).into(),
],
)
}) == 130) as i32)
Expand All @@ -52,14 +52,14 @@ fn main_0() -> i32 {
assert!(
(((({
let _count: i32 = 1;
mixed_args_0(_count, &[1.into(), (y.as_pointer()).into()])
mixed_args_0(_count, &[(1).into(), (y.as_pointer()).into()])
}) == 50) as i32)
!= 0)
);
assert!(
(((({
let _count: i32 = 2;
mixed_args_0(_count, &[0.into(), 5.into(), 0.into(), 3.into()])
mixed_args_0(_count, &[(0).into(), (5).into(), (0).into(), (3).into()])
}) == 8) as i32)
!= 0)
);
Expand Down
19 changes: 11 additions & 8 deletions tests/unit/out/refcount/va_arg_mixed_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ fn main_0() -> i32 {
sum_mixed_0(
_count,
&[
0.into(),
10.into(),
1.into(),
2.05E+1.into(),
2.into(),
30_i64.into(),
(0).into(),
(10).into(),
(1).into(),
(2.05E+1).into(),
(2).into(),
(30_i64).into(),
],
)
}) == 60) as i32)
Expand All @@ -50,14 +50,17 @@ fn main_0() -> i32 {
assert!(
(((({
let _count: i32 = 1;
sum_mixed_0(_count, &[0.into(), 42.into()])
sum_mixed_0(_count, &[(0).into(), (42).into()])
}) == 42) as i32)
!= 0)
);
assert!(
(((({
let _count: i32 = 2;
sum_mixed_0(_count, &[1.into(), 3.7E+0.into(), 2.into(), 100_i64.into()])
sum_mixed_0(
_count,
&[(1).into(), (3.7E+0).into(), (2).into(), (100_i64).into()],
)
}) == 103) as i32)
!= 0)
);
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn main_0() -> i32 {
assert!(
(((({
let _option: i32 = (opt::OPT_FILE as i32);
dispatch_0(_option, &[libcc2rs::cout().into()])
dispatch_0(_option, &[(libcc2rs::cout()).into()])
}) == 1) as i32)
!= 0)
);
Expand All @@ -100,10 +100,10 @@ fn main_0() -> i32 {
let _option: i32 = (opt::OPT_FILE as i32);
dispatch_0(
_option,
&[(AnyPtr::default())
&[((AnyPtr::default())
.cast::<::std::fs::File>()
.expect("ub:wrong type")
.into()],
.expect("ub:wrong type"))
.into()],
)
}) == 0) as i32)
!= 0)
Expand Down
13 changes: 10 additions & 3 deletions tests/unit/out/refcount/va_arg_printf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,24 @@ pub fn main() {
std::process::exit(main_0());
}
fn main_0() -> i32 {
let dummy: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal(b"dummy")));
assert!(
(((({
let _fmt: Ptr<u8> = Ptr::from_string_literal(b"hello %d %d");
logf_1(_fmt, &[10.into(), 32.into()])
}) == 42) as i32)
logf_1(
_fmt,
&[
(10).into(),
((*dummy.borrow()).to_string_iterator().count() as u64).into(),
],
)
}) == 15) as i32)
!= 0)
);
assert!(
(((({
let _fmt: Ptr<u8> = Ptr::from_string_literal(b"x %d %d");
logf_1(_fmt, &[1.into(), 2.into()])
logf_1(_fmt, &[(1).into(), (2).into()])
}) == 3) as i32)
!= 0)
);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/out/refcount/va_arg_snprintf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main_0() -> i32 {
let _buf: Ptr<u8> = (buf.as_pointer() as Ptr<u8>);
let _size: i32 = 1;
let _fmt: Ptr<u8> = Ptr::from_string_literal(b"%d");
extract_first_0(_buf, _size, _fmt, &[42.into()])
extract_first_0(_buf, _size, _fmt, &[(42).into()])
}) == 42) as i32)
!= 0)
);
Expand All @@ -39,7 +39,7 @@ fn main_0() -> i32 {
let _buf: Ptr<u8> = (buf.as_pointer() as Ptr<u8>);
let _size: i32 = 1;
let _fmt: Ptr<u8> = Ptr::from_string_literal(b"%d");
extract_first_0(_buf, _size, _fmt, &[65.into()])
extract_first_0(_buf, _size, _fmt, &[(65).into()])
}) == 65) as i32)
!= 0)
);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/out/refcount/va_arg_struct_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ fn main_0() -> i32 {
({
let _ctx: Ptr<context> = (ctx.as_pointer());
let _fmt: Ptr<u8> = Ptr::from_string_literal(b"error %d");
set_error_0(_ctx, _fmt, &[42.into()])
set_error_0(_ctx, _fmt, &[(42).into()])
});
assert!(((((*(*ctx.borrow()).last_error.borrow()) == 42) as i32) != 0));
(*(*ctx.borrow()).verbose.borrow_mut()) = 0;
({
let _ctx: Ptr<context> = (ctx.as_pointer());
let _fmt: Ptr<u8> = Ptr::from_string_literal(b"error %d");
set_error_0(_ctx, _fmt, &[99.into()])
set_error_0(_ctx, _fmt, &[(99).into()])
});
assert!(((((*(*ctx.borrow()).last_error.borrow()) == 42) as i32) != 0));
return 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/refcount/va_arg_two_passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn main_0() -> i32 {
assert!(
(((({
let _first: i32 = 2;
sum_then_product_0(_first, &[3.into(), 4.into(), 0.into()])
sum_then_product_0(_first, &[(3).into(), (4).into(), (0).into()])
}) == 33) as i32)
!= 0)
);
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/out/unsafe/va_arg_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,24 @@ unsafe fn main_0() -> i32 {
assert!(
((((unsafe {
let _n: i32 = 2;
top_level_2(_n, &[100.into(), 200.into(), 300.into(), 400.into()])
top_level_2(
_n,
&[(100).into(), (200).into(), (300).into(), (400).into()],
)
}) == (300)) as i32)
!= 0)
);
assert!(
((((unsafe {
let _n: i32 = 0;
top_level_2(_n, &[42.into(), 99.into()])
top_level_2(_n, &[(42).into(), (99).into()])
}) == (42)) as i32)
!= 0)
);
assert!(
((((unsafe {
let _n: i32 = 3;
top_level_2(_n, &[1.into(), 2.into(), 3.into(), 4.into()])
top_level_2(_n, &[(1).into(), (2).into(), (3).into(), (4).into()])
}) == (4)) as i32)
!= 0)
);
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/out/unsafe/va_arg_concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,24 @@ unsafe fn main_0() -> i32 {
assert!(
((((unsafe {
let _first: i32 = 1;
sum_ints_0(_first, &[2.into(), 3.into(), 4.into(), 0.into()])
sum_ints_0(_first, &[(2).into(), (3).into(), (4).into(), (0).into()])
}) == (10)) as i32)
!= 0)
);
assert!(
((((unsafe {
let _first: i32 = 100;
sum_ints_0(_first, &[0.into()])
sum_ints_0(_first, &[(0).into()])
}) == (100)) as i32)
!= 0)
);
assert!(
((((unsafe {
let _first: i32 = 5;
sum_ints_0(_first, &[5.into(), 5.into(), 5.into(), 5.into(), 0.into()])
sum_ints_0(
_first,
&[(5).into(), (5).into(), (5).into(), (5).into(), (0).into()],
)
}) == (25)) as i32)
!= 0)
);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/out/unsafe/va_arg_conditional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ unsafe fn main_0() -> i32 {
((((unsafe {
let _verbose: i32 = 1;
let _fmt: *const u8 = (b"%d\0".as_ptr().cast_mut()).cast_const();
conditional_log_0(_verbose, _fmt, &[42.into()])
conditional_log_0(_verbose, _fmt, &[(42).into()])
}) == (42)) as i32)
!= 0)
);
assert!(
((((unsafe {
let _verbose: i32 = 0;
let _fmt: *const u8 = (b"%d\0".as_ptr().cast_mut()).cast_const();
conditional_log_0(_verbose, _fmt, &[99.into()])
conditional_log_0(_verbose, _fmt, &[(99).into()])
}) == (-1_i32)) as i32)
!= 0)
);
Expand Down
Loading
Loading