From 5b5e2402d897df5aa59e772a9d2aa811d3fa1ca7 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Tue, 7 Jul 2026 10:36:10 +0100 Subject: [PATCH 1/2] Add AddAssign impl for i64 --- libcc2rs/src/rc.rs | 2 +- tests/unit/out/refcount/pointer_add_assign.rs | 39 +++++++++++++ tests/unit/out/unsafe/pointer_add_assign.rs | 45 +++++++++++++++ tests/unit/pointer_add_assign.cpp | 55 +++++++++++++++++++ 4 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 tests/unit/out/refcount/pointer_add_assign.rs create mode 100644 tests/unit/out/unsafe/pointer_add_assign.rs create mode 100644 tests/unit/pointer_add_assign.cpp diff --git a/libcc2rs/src/rc.rs b/libcc2rs/src/rc.rs index f13be101..bd249cea 100644 --- a/libcc2rs/src/rc.rs +++ b/libcc2rs/src/rc.rs @@ -730,7 +730,7 @@ macro_rules! impl_ptr_add_sub_assign { } )+ } } -impl_ptr_add_sub_assign!(i32, u32, u64, isize, usize); +impl_ptr_add_sub_assign!(i32, u32, i64, u64, isize, usize); macro_rules! impl_ptr_add_sub { ($($rhs:ty),+) => { $( diff --git a/tests/unit/out/refcount/pointer_add_assign.rs b/tests/unit/out/refcount/pointer_add_assign.rs new file mode 100644 index 00000000..2cc43a67 --- /dev/null +++ b/tests/unit/out/refcount/pointer_add_assign.rs @@ -0,0 +1,39 @@ +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 main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let arr: Value> = Rc::new(RefCell::new(Box::new([1_u8, 2_u8, 3_u8]))); + let p: Value> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr).offset(0)))); + (*p.borrow_mut()) += (1_u8 as i32); + assert!(((((*p.borrow()).read()) as i32) == 2)); + let p: Value> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr).offset(0)))); + (*p.borrow_mut()) += (1_i8 as i32); + assert!(((((*p.borrow()).read()) as i32) == 2)); + let p: Value> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr).offset(0)))); + (*p.borrow_mut()) += (1_u16 as i32); + assert!(((((*p.borrow()).read()) as i32) == 2)); + let p: Value> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr).offset(0)))); + (*p.borrow_mut()) += (1_i16 as i32); + assert!(((((*p.borrow()).read()) as i32) == 2)); + let p: Value> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr).offset(0)))); + (*p.borrow_mut()) += 1_u32; + assert!(((((*p.borrow()).read()) as i32) == 2)); + let p: Value> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr).offset(0)))); + (*p.borrow_mut()) += (1 as i32); + assert!(((((*p.borrow()).read()) as i32) == 2)); + let p: Value> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr).offset(0)))); + (*p.borrow_mut()) += 1_u64; + assert!(((((*p.borrow()).read()) as i32) == 2)); + let p: Value> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr).offset(0)))); + (*p.borrow_mut()) += 1_i64; + assert!(((((*p.borrow()).read()) as i32) == 2)); + return 0; +} diff --git a/tests/unit/out/unsafe/pointer_add_assign.rs b/tests/unit/out/unsafe/pointer_add_assign.rs new file mode 100644 index 00000000..e99fdbd0 --- /dev/null +++ b/tests/unit/out/unsafe/pointer_add_assign.rs @@ -0,0 +1,45 @@ +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 fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut arr: [libc::c_char; 3] = [ + (1 as libc::c_char), + (2 as libc::c_char), + (3 as libc::c_char), + ]; + let mut p: *mut libc::c_char = (&mut arr[(0) as usize] as *mut libc::c_char); + p = (p).wrapping_add((1_u8 as i32) as usize); + assert!((((*p) as i32) == (2))); + let mut p: *mut libc::c_char = (&mut arr[(0) as usize] as *mut libc::c_char); + p = (p).wrapping_add((1_i8 as i32) as usize); + assert!((((*p) as i32) == (2))); + let mut p: *mut libc::c_char = (&mut arr[(0) as usize] as *mut libc::c_char); + p = (p).wrapping_add((1_u16 as i32) as usize); + assert!((((*p) as i32) == (2))); + let mut p: *mut libc::c_char = (&mut arr[(0) as usize] as *mut libc::c_char); + p = (p).wrapping_add((1_i16 as i32) as usize); + assert!((((*p) as i32) == (2))); + let mut p: *mut libc::c_char = (&mut arr[(0) as usize] as *mut libc::c_char); + p = (p).wrapping_add((1_u32 as u32) as usize); + assert!((((*p) as i32) == (2))); + let mut p: *mut libc::c_char = (&mut arr[(0) as usize] as *mut libc::c_char); + p = (p).wrapping_add(((1 as i32) as i32) as usize); + assert!((((*p) as i32) == (2))); + let mut p: *mut libc::c_char = (&mut arr[(0) as usize] as *mut libc::c_char); + p = (p).wrapping_add((1_u64 as u64) as usize); + assert!((((*p) as i32) == (2))); + let mut p: *mut libc::c_char = (&mut arr[(0) as usize] as *mut libc::c_char); + p = (p).wrapping_add((1_i64 as i64) as usize); + assert!((((*p) as i32) == (2))); + return 0; +} diff --git a/tests/unit/pointer_add_assign.cpp b/tests/unit/pointer_add_assign.cpp new file mode 100644 index 00000000..800f25da --- /dev/null +++ b/tests/unit/pointer_add_assign.cpp @@ -0,0 +1,55 @@ +#include +#include + +int main() { + char arr[] = {1, 2, 3}; + { + char *p = &arr[0]; + p += static_cast(1); + assert(*p == 2); + } + + { + char *p = &arr[0]; + p += static_cast(1); + assert(*p == 2); + } + + { + char *p = &arr[0]; + p += static_cast(1); + assert(*p == 2); + } + + { + char *p = &arr[0]; + p += static_cast(1); + assert(*p == 2); + } + + { + char *p = &arr[0]; + p += static_cast(1); + assert(*p == 2); + } + + { + char *p = &arr[0]; + p += static_cast(1); + assert(*p == 2); + } + + { + char *p = &arr[0]; + p += static_cast(1); + assert(*p == 2); + } + + { + char *p = &arr[0]; + p += static_cast(1); + assert(*p == 2); + } + + return 0; +} From 4f8a31c9cce9326d0d1bf734e8002c7d5ac33d3c Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Tue, 7 Jul 2026 11:00:23 +0100 Subject: [PATCH 2/2] clang format --- tests/unit/pointer_add_assign.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/pointer_add_assign.cpp b/tests/unit/pointer_add_assign.cpp index 800f25da..ce4a6b19 100644 --- a/tests/unit/pointer_add_assign.cpp +++ b/tests/unit/pointer_add_assign.cpp @@ -8,7 +8,7 @@ int main() { p += static_cast(1); assert(*p == 2); } - + { char *p = &arr[0]; p += static_cast(1); @@ -20,7 +20,7 @@ int main() { p += static_cast(1); assert(*p == 2); } - + { char *p = &arr[0]; p += static_cast(1); @@ -32,7 +32,7 @@ int main() { p += static_cast(1); assert(*p == 2); } - + { char *p = &arr[0]; p += static_cast(1); @@ -44,7 +44,7 @@ int main() { p += static_cast(1); assert(*p == 2); } - + { char *p = &arr[0]; p += static_cast(1);