Skip to content

Commit cd2b649

Browse files
committed
Add redundant copy in conversion test
1 parent dc1b1ff commit cd2b649

3 files changed

Lines changed: 122 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
extern crate libcc2rs;
2+
use libcc2rs::*;
3+
use std::cell::RefCell;
4+
use std::collections::BTreeMap;
5+
use std::io::prelude::*;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::AsFd;
8+
use std::rc::{Rc, Weak};
9+
#[derive(Default)]
10+
pub struct iter {
11+
pub p: Value<Ptr<i32>>,
12+
}
13+
impl Clone for iter {
14+
fn clone(&self) -> Self {
15+
let mut this = Self {
16+
p: Rc::new(RefCell::new((*self.p.borrow()).clone())),
17+
};
18+
this
19+
}
20+
}
21+
impl ByteRepr for iter {}
22+
#[derive(Default)]
23+
pub struct const_iter {
24+
pub p: Value<Ptr<i32>>,
25+
}
26+
impl const_iter {
27+
pub fn const_iter(o: Ptr<iter>) -> Self {
28+
let mut this = Self {
29+
p: Rc::new(RefCell::new((*(*o.upgrade().deref()).p.borrow()).clone())),
30+
};
31+
this
32+
}
33+
}
34+
impl Clone for const_iter {
35+
fn clone(&self) -> Self {
36+
let mut this = Self {
37+
p: Rc::new(RefCell::new(Ptr::<i32>::null())),
38+
};
39+
this
40+
}
41+
}
42+
impl ByteRepr for const_iter {}
43+
pub fn sink_0(i: const_iter) {
44+
let i: Value<const_iter> = Rc::new(RefCell::new(i));
45+
}
46+
pub fn main() {
47+
std::process::exit(main_0());
48+
}
49+
fn main_0() -> i32 {
50+
let buf: Value<Box<[i32]>> = Rc::new(RefCell::new(Box::new([0, 0])));
51+
let it: Value<iter> = Rc::new(RefCell::new(iter {
52+
p: Rc::new(RefCell::new((buf.as_pointer() as Ptr<i32>))),
53+
}));
54+
({
55+
let _i: const_iter = const_iter::const_iter(it.as_pointer());
56+
sink_0(_i)
57+
});
58+
return 0;
59+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
extern crate libc;
2+
use libc::*;
3+
extern crate libcc2rs;
4+
use libcc2rs::*;
5+
use std::collections::BTreeMap;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
8+
use std::rc::Rc;
9+
#[repr(C)]
10+
#[derive(Copy, Clone, Default)]
11+
pub struct iter {
12+
pub p: *mut i32,
13+
}
14+
#[repr(C)]
15+
#[derive(Copy, Clone, Default)]
16+
pub struct const_iter {
17+
pub p: *const i32,
18+
}
19+
impl const_iter {
20+
pub unsafe fn const_iter(o: *const iter) -> Self {
21+
let mut this = Self {
22+
p: (*o).p.cast_const(),
23+
};
24+
this
25+
}
26+
}
27+
pub unsafe fn sink_0(mut i: const_iter) {}
28+
pub fn main() {
29+
unsafe {
30+
std::process::exit(main_0() as i32);
31+
}
32+
}
33+
unsafe fn main_0() -> i32 {
34+
let mut buf: [i32; 2] = [0, 0];
35+
let mut it: iter = iter {
36+
p: buf.as_mut_ptr(),
37+
};
38+
(unsafe {
39+
let _i: const_iter = const_iter::const_iter(&it as *const iter);
40+
sink_0(_i)
41+
});
42+
return 0;
43+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
struct iter {
2+
using iterator_category = int;
3+
int *p;
4+
};
5+
6+
struct const_iter {
7+
using iterator_category = int;
8+
const int *p;
9+
const_iter(const iter &o) : p(o.p) {}
10+
const_iter(const const_iter &) = default;
11+
};
12+
13+
static void sink(const_iter i) {}
14+
15+
int main() {
16+
int buf[2] = {0, 0};
17+
iter it{buf};
18+
sink(it);
19+
return 0;
20+
}

0 commit comments

Comments
 (0)