Skip to content

Commit 4238463

Browse files
committed
Extend RustSizeDivergesFromC
1 parent 3a089f3 commit 4238463

37 files changed

Lines changed: 321 additions & 259 deletions

‎cpp2rust/converter/converter_lib.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ bool RustSizeDivergesFromC(clang::QualType qt) {
339339
if (auto *arr = qt->getAsArrayTypeUnsafe()) {
340340
return RustSizeDivergesFromC(arr->getElementType());
341341
}
342+
if (qt->isPointerType()) {
343+
return true;
344+
}
342345
return false;
343346
}
344347

‎tests/ub/out/refcount/fd_use_after_close.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ fn main_0() -> i32 {
3636
((buf.as_pointer() as Ptr<i8>) as Ptr<i8>)
3737
.to_any()
3838
.reinterpret_cast::<u8>()
39-
.with_slice_mut(4usize, |__buf| nix::unistd::read(__fd, __buf))
39+
.with_slice_mut(::std::mem::size_of::<[i8; 4]>(), |__buf| {
40+
nix::unistd::read(__fd, __buf)
41+
})
4042
}) {
4143
Ok(__n) => __n as isize,
4244
Err(__e) => {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn main_0() -> i32 {
3737
{
3838
((array_field_ptr!(s, mask) as Ptr<u8>) as Ptr<u8>)
3939
.to_any()
40-
.memset((5) as u8, 4usize as usize);
40+
.memset((5) as u8, ::std::mem::size_of::<[u8; 4]>() as usize);
4141
((array_field_ptr!(s, mask) as Ptr<u8>) as Ptr<u8>).to_any()
4242
};
4343
field!(s, after).write(2);
@@ -46,7 +46,7 @@ fn main_0() -> i32 {
4646
{
4747
((out.as_pointer() as Ptr<u8>) as Ptr<u8>).to_any().memcpy(
4848
&((array_field_ptr!(s, mask)) as Ptr<u8>).to_any(),
49-
4usize as usize,
49+
::std::mem::size_of::<[u8; 4]>() as usize,
5050
);
5151
((out.as_pointer() as Ptr<u8>) as Ptr<u8>).to_any()
5252
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn main_0() -> i32 {
2424
let mut __found = AnyPtr::default();
2525
while __lo <= __hi && __found.is_null() {
2626
let __mid = __lo + (__hi - __lo) / 2;
27-
let __elem = __base.offset(__mid as usize * 4usize);
27+
let __elem = __base.offset(__mid as usize * ::std::mem::size_of::<i32>());
2828
let __r = int_cmp_0(
2929
(((a1.as_pointer() as Ptr<i32>).offset(0)) as Ptr<i32>)
3030
.to_any()

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
99
const _: () = assert!(true, "Small<int>");
10-
const _: () = assert!((4usize == 4_usize), "sizeof(int) == 4");
10+
const _: () = assert!(
11+
(::std::mem::size_of::<i32>() == 4_usize),
12+
"sizeof(int) == 4"
13+
);
1114
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
1215
#[byte_size(1)]
1316
pub struct Sized {}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ impl Templated_char_Impl for Ptr<Templated_char_> {
273273
fn destructor(&self) {
274274
global_0.with(|rc| {
275275
*rc.borrow_mut() = {
276-
((global_0.with(|rc| *rc.borrow()) as usize).wrapping_add((1usize as usize))) as i32
276+
((global_0.with(|rc| *rc.borrow()) as usize)
277+
.wrapping_add((::std::mem::size_of::<i8>() as usize))) as i32
277278
}
278279
});
279280
}
@@ -285,7 +286,8 @@ impl Templated_int_Impl for Ptr<Templated_int_> {
285286
fn destructor(&self) {
286287
global_0.with(|rc| {
287288
*rc.borrow_mut() = {
288-
((global_0.with(|rc| *rc.borrow()) as usize).wrapping_add((4usize as usize))) as i32
289+
((global_0.with(|rc| *rc.borrow()) as usize)
290+
.wrapping_add((::std::mem::size_of::<i32>() as usize))) as i32
289291
}
290292
});
291293
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ fn main_0() -> i32 {
3838
assert!(((b as i32) == (false as i32)));
3939
let mut s: Small = Small_SMALL_MAX;
4040
assert!(((s as i32) == 255));
41-
assert!((1usize == 1_usize));
41+
assert!((::std::mem::size_of::<Small>() == 1_usize));
4242
s = Small_SMALL_ZERO;
4343
assert!((((s as i32) + 1) == 1));
4444
let mut sg: Signed = Signed_SIGNED_MIN;
4545
assert!(((sg as i32) == -128_i32));
4646
assert!(((sg as i32) < (Signed_SIGNED_ONE as i32)));
4747
let mut w: Wide = Wide_WIDE_BIG;
4848
assert!(((w as i64) == (1_i64 << 40)));
49-
assert!((8usize == 8_usize));
49+
assert!((::std::mem::size_of::<Wide>() == 8_usize));
5050
assert!(((Wide_WIDE_NEG as i64) < 0_i64));
5151
let mut z: Sized = Sized_SIZED_B;
5252
assert!(((z as i32) == 65535));
53-
assert!((2usize == 2_usize));
53+
assert!((::std::mem::size_of::<Sized>() == 2_usize));
5454
assert!((((Sized_SIZED_A as i32) + 1) == 2));
5555
let mut sc: Scoped = Scoped_NEG;
5656
assert!(((sc as i32) == -2_i32));

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,17 @@ fn main_0() -> i32 {
7070
{
7171
((buf.as_pointer() as Ptr<i8>) as Ptr<i8>)
7272
.to_any()
73-
.memset((0) as u8, 16usize as usize);
73+
.memset((0) as u8, ::std::mem::size_of::<[i8; 16]>() as usize);
7474
((buf.as_pointer() as Ptr<i8>) as Ptr<i8>).to_any()
7575
};
7676
assert!(
7777
(((match FdRegistry::with_fd(fd, |__fd| {
7878
((buf.as_pointer() as Ptr<i8>) as Ptr<i8>)
7979
.to_any()
8080
.reinterpret_cast::<u8>()
81-
.with_slice_mut(16usize, |__buf| nix::unistd::read(__fd, __buf))
81+
.with_slice_mut(::std::mem::size_of::<[i8; 16]>(), |__buf| {
82+
nix::unistd::read(__fd, __buf)
83+
})
8284
}) {
8385
Ok(__n) => __n as isize,
8486
Err(__e) => {
@@ -110,7 +112,9 @@ fn main_0() -> i32 {
110112
((buf.as_pointer() as Ptr<i8>) as Ptr<i8>)
111113
.to_any()
112114
.reinterpret_cast::<u8>()
113-
.with_slice_mut(16usize, |__buf| nix::unistd::read(__fd, __buf))
115+
.with_slice_mut(::std::mem::size_of::<[i8; 16]>(), |__buf| {
116+
nix::unistd::read(__fd, __buf)
117+
})
114118
}) {
115119
Ok(__n) => __n as isize,
116120
Err(__e) => {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn main_0() -> i32 {
171171
a
172172
)) as Ptr<i32>)
173173
.to_any(),
174-
4usize as usize,
174+
::std::mem::size_of::<i32>() as usize,
175175
);
176176
((field_ptr!(
177177
(array_field_ptr!(o.as_pointer(), items) as Ptr<Inner>).offset((2) as isize),
@@ -186,7 +186,7 @@ fn main_0() -> i32 {
186186
a
187187
)) as Ptr<i32>)
188188
.to_any(),
189-
4usize as usize,
189+
::std::mem::size_of::<i32>() as usize,
190190
);
191191
((y.as_pointer()) as Ptr<i32>).to_any()
192192
};

0 commit comments

Comments
 (0)