Skip to content

Commit b32ac65

Browse files
committed
Handle ops between i64 and isize
1 parent cb98d54 commit b32ac65

5 files changed

Lines changed: 78 additions & 7 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2235,7 +2235,7 @@ void Converter::ConvertBinaryOperator(clang::BinaryOperator *expr) {
22352235
auto op = opcode_as_string;
22362236
op.remove_suffix(1); // remove '=' from operator
22372237
StrCat(op);
2238-
Convert(rhs);
2238+
Convert(rhs, computation_result_type);
22392239
}
22402240
if (lhs_type->isBooleanType()) {
22412241
StrCat(token::kDiff, token::kZero);

tests/unit/out/refcount/size_t_ssize_t.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,14 @@ fn main_0() -> i32 {
211211
(((*sz.borrow()) as isize) - ((*ul.borrow()) as isize)),
212212
));
213213
assert!(((*delta.borrow()) == 11_isize));
214+
let a64: Value<i64> = Rc::new(RefCell::new(100_i64));
215+
let b: Value<isize> = Rc::new(RefCell::new(30_isize));
216+
(*a64.borrow_mut()) -= ((*b.borrow()) as i64);
217+
assert!(((*a64.borrow()) == 70_i64));
218+
(*a64.borrow_mut()) += ((*b.borrow()) as i64);
219+
assert!(((*a64.borrow()) == 100_i64));
220+
let c: Value<isize> = Rc::new(RefCell::new((-20_i32 as isize)));
221+
(*a64.borrow_mut()) -= ((*c.borrow()) as i64);
222+
assert!(((*a64.borrow()) == 120_i64));
214223
return (((*n.borrow()).wrapping_rem(7_usize)) as i32);
215224
}

tests/unit/out/unsafe/size_t_ssize_t.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,14 @@ unsafe fn main_0() -> i32 {
156156
assert!(((smax) == (15_isize)));
157157
let mut delta: isize = ((sz as isize) - (ul as isize));
158158
assert!(((delta) == (11_isize)));
159+
let mut a64: i64 = 100_i64;
160+
let mut b: isize = 30_isize;
161+
a64 -= (b as i64);
162+
assert!(((a64) == (70_i64)));
163+
a64 += (b as i64);
164+
assert!(((a64) == (100_i64)));
165+
let mut c: isize = (-20_i32 as isize);
166+
a64 -= (c as i64);
167+
assert!(((a64) == (120_i64)));
159168
return (((n).wrapping_rem(7_usize)) as i32);
160169
}

tests/unit/out/unsafe/unistd.rs

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,58 @@ pub unsafe fn test_ftruncate_5() {
219219
assert!(((((libc::fclose(fp)) == (0)) as i32) != 0));
220220
libc::unlink(path as *const i8);
221221
}
222-
pub unsafe fn test_isatty_6() {
222+
pub unsafe fn test_open_6() {
223+
let mut fd: i32 = (unsafe {
224+
libc::open(
225+
(b"/dev/null\0".as_ptr().cast_mut()).cast_const() as *const i8,
226+
0 as i32,
227+
(420),
228+
)
229+
});
230+
assert!(((((fd) >= (-1_i32)) as i32) != 0));
231+
if ((((fd) >= (0)) as i32) != 0) {
232+
libc::close(fd);
233+
}
234+
fd = (unsafe {
235+
libc::open(
236+
(b"/dev/null\0".as_ptr().cast_mut()).cast_const() as *const i8,
237+
0 as i32,
238+
)
239+
});
240+
assert!(((((fd) >= (-1_i32)) as i32) != 0));
241+
if ((((fd) >= (0)) as i32) != 0) {
242+
libc::close(fd);
243+
}
244+
}
245+
pub unsafe fn test_fcntl_7() {
246+
assert!(((((unsafe { libc::fcntl(0 as i32, 1 as i32,) }) >= (-1_i32)) as i32) != 0));
247+
let mut duped: i32 = (unsafe { libc::fcntl(0 as i32, 0 as i32, (100)) });
248+
assert!(((((duped) >= (-1_i32)) as i32) != 0));
249+
if ((((duped) >= (0)) as i32) != 0) {
250+
libc::close(duped);
251+
}
252+
}
253+
pub unsafe fn test_ioctl_8() {
254+
let mut arg: i32 = 0;
255+
assert!(
256+
((((unsafe { libc::ioctl(0 as i32, 0_u64 as u64, (&mut arg as *mut i32),) }) >= (-1_i32))
257+
as i32)
258+
!= 0)
259+
);
260+
}
261+
pub unsafe fn test_isatty_9() {
223262
printf(
224263
(b"%d\n\0".as_ptr().cast_mut()).cast_const() as *const i8,
225264
libc::isatty(0),
226265
);
227266
}
228-
pub unsafe fn test_geteuid_7() {
267+
pub unsafe fn test_geteuid_10() {
229268
printf(
230269
(b"%u\n\0".as_ptr().cast_mut()).cast_const() as *const i8,
231270
libc::geteuid(),
232271
);
233272
}
234-
pub unsafe fn test_gethostname_8() {
273+
pub unsafe fn test_gethostname_11() {
235274
let mut name: [u8; 256] = [0_u8; 256];
236275
assert!(
237276
((((libc::gethostname(
@@ -257,8 +296,11 @@ unsafe fn main_0() -> i32 {
257296
(unsafe { test_unlink_3() });
258297
(unsafe { test_pipe_4() });
259298
(unsafe { test_ftruncate_5() });
260-
(unsafe { test_isatty_6() });
261-
(unsafe { test_geteuid_7() });
262-
(unsafe { test_gethostname_8() });
299+
(unsafe { test_open_6() });
300+
(unsafe { test_fcntl_7() });
301+
(unsafe { test_ioctl_8() });
302+
(unsafe { test_isatty_9() });
303+
(unsafe { test_geteuid_10() });
304+
(unsafe { test_gethostname_11() });
263305
return 0;
264306
}

tests/unit/size_t_ssize_t.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,16 @@ int main() {
8585
ssize_t delta = (ssize_t)sz - (ssize_t)ul;
8686
assert(delta == 11);
8787

88+
typedef long long ll_t;
89+
ll_t a64 = 100;
90+
ssize_t b = 30;
91+
a64 -= b;
92+
assert(a64 == 70);
93+
a64 += b;
94+
assert(a64 == 100);
95+
ssize_t c = -20;
96+
a64 -= c;
97+
assert(a64 == 120);
98+
8899
return (int)(n % 7);
89100
}

0 commit comments

Comments
 (0)