Skip to content

Commit 73e1d12

Browse files
committed
Revert extra casts
1 parent 6c73486 commit 73e1d12

27 files changed

Lines changed: 81 additions & 88 deletions

‎cpp2rust/converter/converter.cpp‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4236,7 +4236,7 @@ std::string Converter::ConvertPlaceholder(clang::Expr *expr, clang::Expr *arg,
42364236
}
42374237
}
42384238

4239-
if (ph_ctx.needs_pointer_receiver() || ph_ctx.needs_ptr_wrap()) {
4239+
if (ph_ctx.needs_pointer_receiver()) {
42404240
return std::format("({} as {})", ConvertFreshObject(arg),
42414241
ph_ctx.param_type);
42424242
}
@@ -4253,6 +4253,10 @@ std::string Converter::ConvertPlaceholder(clang::Expr *expr, clang::Expr *arg,
42534253
return std::move(buf).str();
42544254
}
42554255

4256+
if (ph_ctx.needs_ptr_wrap()) {
4257+
return ConvertFreshObject(arg);
4258+
}
4259+
42564260
if (ph_ctx.needs_lvalue()) {
42574261
return ConvertLValue(arg);
42584262
}

‎tests/unit/out/refcount/max.rs‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,34 @@ fn main_0() -> i32 {
1717
let p1: Value<Ptr<i32>> = Rc::new(RefCell::new((x1.as_pointer())));
1818
let p2: Value<Ptr<i32>> = Rc::new(RefCell::new((x2.as_pointer())));
1919
let r1: Value<i32> = Rc::new(RefCell::new(
20-
(if (x1.as_pointer() as Ptr<i32>).read() >= (x2.as_pointer() as Ptr<i32>).read() {
21-
(x1.as_pointer() as Ptr<i32>)
20+
(if x1.as_pointer().read() >= x2.as_pointer().read() {
21+
x1.as_pointer()
2222
} else {
23-
(x2.as_pointer() as Ptr<i32>)
23+
x2.as_pointer()
2424
}
2525
.read()),
2626
));
2727
let r2: Value<i32> = Rc::new(RefCell::new(
28-
(if (x3.as_pointer() as Ptr<i32>).read() <= (x4.as_pointer() as Ptr<i32>).read() {
29-
(x3.as_pointer() as Ptr<i32>)
28+
(if x3.as_pointer().read() <= x4.as_pointer().read() {
29+
x3.as_pointer()
3030
} else {
31-
(x4.as_pointer() as Ptr<i32>)
31+
x4.as_pointer()
3232
}
3333
.read()),
3434
));
3535
let r3: Value<i32> = Rc::new(RefCell::new(
36-
(if ((*p1.borrow()).clone() as Ptr<i32>).read() >= (x2.as_pointer() as Ptr<i32>).read() {
37-
((*p1.borrow()).clone() as Ptr<i32>)
36+
(if (*p1.borrow()).clone().read() >= x2.as_pointer().read() {
37+
(*p1.borrow()).clone()
3838
} else {
39-
(x2.as_pointer() as Ptr<i32>)
39+
x2.as_pointer()
4040
}
4141
.read()),
4242
));
4343
let r4: Value<i32> = Rc::new(RefCell::new(
44-
(if ((*p2.borrow()).clone() as Ptr<i32>).read() <= (x3.as_pointer() as Ptr<i32>).read() {
45-
((*p2.borrow()).clone() as Ptr<i32>)
44+
(if (*p2.borrow()).clone().read() <= x3.as_pointer().read() {
45+
(*p2.borrow()).clone()
4646
} else {
47-
(x3.as_pointer() as Ptr<i32>)
47+
x3.as_pointer()
4848
}
4949
.read()),
5050
));

‎tests/unit/out/refcount/min_max_ptr2ptr.rs‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,18 @@ fn main_0() -> i32 {
1717
let ppa: Value<Ptr<Ptr<i32>>> = Rc::new(RefCell::new((pa.as_pointer())));
1818
let ppb: Value<Ptr<Ptr<i32>>> = Rc::new(RefCell::new((pb.as_pointer())));
1919
let r1: Value<i32> = Rc::new(RefCell::new(
20-
(if (((*ppa.borrow()).read()).clone() as Ptr<i32>).read()
21-
>= (((*ppb.borrow()).read()).clone() as Ptr<i32>).read()
22-
{
23-
(((*ppa.borrow()).read()).clone() as Ptr<i32>)
20+
(if ((*ppa.borrow()).read()).clone().read() >= ((*ppb.borrow()).read()).clone().read() {
21+
((*ppa.borrow()).read()).clone()
2422
} else {
25-
(((*ppb.borrow()).read()).clone() as Ptr<i32>)
23+
((*ppb.borrow()).read()).clone()
2624
}
2725
.read()),
2826
));
2927
let r2: Value<i32> = Rc::new(RefCell::new(
30-
(if (((*ppa.borrow()).read()).clone() as Ptr<i32>).read()
31-
<= (((*ppb.borrow()).read()).clone() as Ptr<i32>).read()
32-
{
33-
(((*ppa.borrow()).read()).clone() as Ptr<i32>)
28+
(if ((*ppa.borrow()).read()).clone().read() <= ((*ppb.borrow()).read()).clone().read() {
29+
((*ppa.borrow()).read()).clone()
3430
} else {
35-
(((*ppb.borrow()).read()).clone() as Ptr<i32>)
31+
((*ppb.borrow()).read()).clone()
3632
}
3733
.read()),
3834
));

‎tests/unit/out/refcount/reference_wrapper.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn main() {
5050
}
5151
fn main_0() -> i32 {
5252
let i1: Value<i32> = Rc::new(RefCell::new(10));
53-
let ref_1: Value<Ptr<i32>> = Rc::new(RefCell::new((i1.as_pointer() as Ptr<i32>)));
53+
let ref_1: Value<Ptr<i32>> = Rc::new(RefCell::new(i1.as_pointer()));
5454
(*ref_1.borrow()).clone().write(20);
5555
let i2: Ptr<i32> = (*ref_1.borrow()).clone();
5656
{
@@ -60,8 +60,8 @@ fn main_0() -> i32 {
6060
write!(libcc2rs::cout(), "{:}\n", (*i1.borrow()),);
6161
let i3: Value<i32> = Rc::new(RefCell::new(1));
6262
let i4: Value<i32> = Rc::new(RefCell::new(2));
63-
let ref_3: Value<Ptr<i32>> = Rc::new(RefCell::new((i3.as_pointer() as Ptr<i32>)));
64-
let ref_4: Value<Ptr<i32>> = Rc::new(RefCell::new((i4.as_pointer() as Ptr<i32>)));
63+
let ref_3: Value<Ptr<i32>> = Rc::new(RefCell::new(i3.as_pointer()));
64+
let ref_4: Value<Ptr<i32>> = Rc::new(RefCell::new(i4.as_pointer()));
6565
let __rhs = ((*ref_4.borrow()).clone().read());
6666
(*ref_3.borrow()).clone().write(__rhs);
6767
write!(
@@ -81,7 +81,7 @@ fn main_0() -> i32 {
8181
x: Rc::new(RefCell::new(3)),
8282
y: Rc::new(RefCell::new(4)),
8383
}));
84-
let point_ref: Value<Ptr<Point>> = Rc::new(RefCell::new((point.as_pointer() as Ptr<Point>)));
84+
let point_ref: Value<Ptr<Point>> = Rc::new(RefCell::new(point.as_pointer()));
8585
(*(*(*point_ref.borrow()).clone().upgrade().deref())
8686
.x
8787
.borrow_mut()) = 30;

‎tests/unit/out/refcount/size_t_ssize_t.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ fn main_0() -> i32 {
103103
let __tmp_0: Value<u64> = Rc::new(RefCell::new(
104104
(::std::mem::size_of::<i32>() as u64).wrapping_add(((*sz.borrow()) as u64)),
105105
));
106-
(if __tmp_0.as_pointer().read() >= (ul.as_pointer() as Ptr<u64>).read() {
106+
(if __tmp_0.as_pointer().read() >= ul.as_pointer().read() {
107107
__tmp_0.as_pointer()
108108
} else {
109-
(ul.as_pointer() as Ptr<u64>)
109+
ul.as_pointer()
110110
}
111111
.read())
112112
} as usize),

‎tests/unit/out/refcount/socket_transparent_union.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ fn main_0() -> i32 {
1919
Ok(__ss) => {
2020
Sockaddr::encode(
2121
&__ss,
22-
&((ssloc.as_pointer()).reinterpret_cast::<libcc2rs::Sockaddr>()
23-
as Ptr<Sockaddr>),
22+
&(ssloc.as_pointer()).reinterpret_cast::<libcc2rs::Sockaddr>(),
2423
&(slen.as_pointer()),
2524
);
2625
0
@@ -40,7 +39,7 @@ fn main_0() -> i32 {
4039
Ok(__ss) => {
4140
Sockaddr::encode(
4241
&__ss,
43-
&((sin.as_pointer()).reinterpret_cast::<libcc2rs::Sockaddr>() as Ptr<Sockaddr>),
42+
&(sin.as_pointer()).reinterpret_cast::<libcc2rs::Sockaddr>(),
4443
&(inlen.as_pointer()),
4544
);
4645
0

‎tests/unit/out/refcount/stdmin_fpoint.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ pub fn main() {
1212
fn main_0() -> i32 {
1313
let a0: Value<f64> = Rc::new(RefCell::new(3.14E+0));
1414
let a1: Value<f64> = Rc::new(RefCell::new(2.71E+0));
15-
if (a0.as_pointer() as Ptr<f64>).read() <= (a1.as_pointer() as Ptr<f64>).read() {
16-
(a0.as_pointer() as Ptr<f64>)
15+
if a0.as_pointer().read() <= a1.as_pointer().read() {
16+
a0.as_pointer()
1717
} else {
18-
(a1.as_pointer() as Ptr<f64>)
18+
a1.as_pointer()
1919
};
2020
return 0;
2121
}

‎tests/unit/out/unsafe/cstring.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub unsafe fn test_memset_1() {
4343
let mut r: *mut ::libc::c_void = {
4444
let byte_0 = (buf.as_mut_ptr() as *mut libc::c_char as *mut ::libc::c_void) as *mut u8;
4545
for offset in 0..4_usize {
46-
*byte_0.offset(offset as isize) = ((('x' as libc::c_char) as i32) as *const u8) as u8;
46+
*byte_0.offset(offset as isize) = (('x' as libc::c_char) as i32) as u8;
4747
}
4848
(buf.as_mut_ptr() as *mut libc::c_char as *mut ::libc::c_void)
4949
};

‎tests/unit/out/unsafe/fd_io.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ unsafe fn main_0() -> i32 {
3737
{
3838
let byte_0 = (buf.as_mut_ptr() as *mut libc::c_char as *mut ::libc::c_void) as *mut u8;
3939
for offset in 0..::std::mem::size_of::<[libc::c_char; 16]>() {
40-
*byte_0.offset(offset as isize) = (0 as *const u8) as u8;
40+
*byte_0.offset(offset as isize) = 0 as u8;
4141
}
4242
(buf.as_mut_ptr() as *mut libc::c_char as *mut ::libc::c_void)
4343
};

‎tests/unit/out/unsafe/fn_ptr_stdlib_compare.rs‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ unsafe fn main_0() -> i32 {
6262
{
6363
let byte_0 = (buf.as_mut_ptr() as *mut libc::c_char as *mut ::libc::c_void) as *mut u8;
6464
for offset in 0..::std::mem::size_of::<[libc::c_char; 16]>() {
65-
*byte_0.offset(offset as isize) =
66-
((('X' as libc::c_char) as i32) as *const u8) as u8;
65+
*byte_0.offset(offset as isize) = (('X' as libc::c_char) as i32) as u8;
6766
}
6867
(buf.as_mut_ptr() as *mut libc::c_char as *mut ::libc::c_void)
6968
};
@@ -95,8 +94,7 @@ unsafe fn main_0() -> i32 {
9594
{
9695
let byte_0 = (buf.as_mut_ptr() as *mut libc::c_char as *mut ::libc::c_void) as *mut u8;
9796
for offset in 0..::std::mem::size_of::<[libc::c_char; 16]>() {
98-
*byte_0.offset(offset as isize) =
99-
((('X' as libc::c_char) as i32) as *const u8) as u8;
97+
*byte_0.offset(offset as isize) = (('X' as libc::c_char) as i32) as u8;
10098
}
10199
(buf.as_mut_ptr() as *mut libc::c_char as *mut ::libc::c_void)
102100
};
@@ -157,8 +155,7 @@ unsafe fn main_0() -> i32 {
157155
{
158156
let byte_0 = (buf.as_mut_ptr() as *mut libc::c_char as *mut ::libc::c_void) as *mut u8;
159157
for offset in 0..::std::mem::size_of::<[libc::c_char; 10]>() {
160-
*byte_0.offset(offset as isize) =
161-
((('Y' as libc::c_char) as i32) as *const u8) as u8;
158+
*byte_0.offset(offset as isize) = (('Y' as libc::c_char) as i32) as u8;
162159
}
163160
(buf.as_mut_ptr() as *mut libc::c_char as *mut ::libc::c_void)
164161
};
@@ -180,8 +177,7 @@ unsafe fn main_0() -> i32 {
180177
{
181178
let byte_0 = (buf.as_mut_ptr() as *mut libc::c_char as *mut ::libc::c_void) as *mut u8;
182179
for offset in 0..::std::mem::size_of::<[libc::c_char; 10]>() {
183-
*byte_0.offset(offset as isize) =
184-
((('Y' as libc::c_char) as i32) as *const u8) as u8;
180+
*byte_0.offset(offset as isize) = (('Y' as libc::c_char) as i32) as u8;
185181
}
186182
(buf.as_mut_ptr() as *mut libc::c_char as *mut ::libc::c_void)
187183
};

0 commit comments

Comments
 (0)