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
2 changes: 1 addition & 1 deletion libcc2rs/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),+) => { $(
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/out/refcount/pointer_add_assign.rs
Original file line number Diff line number Diff line change
@@ -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<Box<[u8]>> = Rc::new(RefCell::new(Box::new([1_u8, 2_u8, 3_u8])));
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr<u8>).offset(0))));
(*p.borrow_mut()) += (1_u8 as i32);
assert!(((((*p.borrow()).read()) as i32) == 2));
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr<u8>).offset(0))));
(*p.borrow_mut()) += (1_i8 as i32);
assert!(((((*p.borrow()).read()) as i32) == 2));
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr<u8>).offset(0))));
(*p.borrow_mut()) += (1_u16 as i32);
assert!(((((*p.borrow()).read()) as i32) == 2));
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr<u8>).offset(0))));
(*p.borrow_mut()) += (1_i16 as i32);
assert!(((((*p.borrow()).read()) as i32) == 2));
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr<u8>).offset(0))));
(*p.borrow_mut()) += 1_u32;
assert!(((((*p.borrow()).read()) as i32) == 2));
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr<u8>).offset(0))));
(*p.borrow_mut()) += (1 as i32);
assert!(((((*p.borrow()).read()) as i32) == 2));
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr<u8>).offset(0))));
(*p.borrow_mut()) += 1_u64;
assert!(((((*p.borrow()).read()) as i32) == 2));
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(((arr.as_pointer() as Ptr<u8>).offset(0))));
(*p.borrow_mut()) += 1_i64;
assert!(((((*p.borrow()).read()) as i32) == 2));
return 0;
}
45 changes: 45 additions & 0 deletions tests/unit/out/unsafe/pointer_add_assign.rs
Original file line number Diff line number Diff line change
@@ -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;
}
55 changes: 55 additions & 0 deletions tests/unit/pointer_add_assign.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <assert.h>
#include <stdint.h>

int main() {
char arr[] = {1, 2, 3};
{
char *p = &arr[0];
p += static_cast<uint8_t>(1);
assert(*p == 2);
}

{
char *p = &arr[0];
p += static_cast<int8_t>(1);
assert(*p == 2);
}

{
char *p = &arr[0];
p += static_cast<uint16_t>(1);
assert(*p == 2);
}

{
char *p = &arr[0];
p += static_cast<int16_t>(1);
assert(*p == 2);
}

{
char *p = &arr[0];
p += static_cast<uint32_t>(1);
assert(*p == 2);
}

{
char *p = &arr[0];
p += static_cast<int32_t>(1);
assert(*p == 2);
}

{
char *p = &arr[0];
p += static_cast<uint64_t>(1);
assert(*p == 2);
}

{
char *p = &arr[0];
p += static_cast<int64_t>(1);
assert(*p == 2);
}

return 0;
}
Loading