Skip to content

Commit e890c69

Browse files
committed
Update tests
1 parent 7000af4 commit e890c69

3 files changed

Lines changed: 143 additions & 0 deletions

File tree

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

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,39 @@ fn main_0() -> i32 {
136136
assert!(
137137
(({ SImpl::apply_12(&s.as_pointer(), FnPtr::<fn(i32) -> i32>::new(twice_2), 3,) }) == 106)
138138
);
139+
let c: Value<i32> = Rc::new(RefCell::new(3));
140+
assert!(
141+
(({
142+
let _p: Value<(Value<i32>, Value<i64>)> = Rc::new(RefCell::new((
143+
Rc::new(RefCell::new(1.try_into().expect("failed conversion"))),
144+
Rc::new(RefCell::new(2_i64.try_into().expect("failed conversion"))),
145+
)));
146+
SImpl::combine_13(
147+
&s.as_pointer(),
148+
_p.as_pointer(),
149+
FnPtr::<fn(i32) -> i32>::new(twice_2),
150+
(c.as_pointer()),
151+
4_u64,
152+
)
153+
}) == 112)
154+
);
155+
let z: Value<i32> = Rc::new(RefCell::new(1));
156+
assert!(
157+
(({
158+
let _p: Value<(Value<i32>, Value<i32>)> = Rc::new(RefCell::new((
159+
Rc::new(RefCell::new(1.try_into().expect("failed conversion"))),
160+
Rc::new(RefCell::new(2.try_into().expect("failed conversion"))),
161+
)));
162+
SImpl::combine_14(
163+
&s.as_pointer(),
164+
_p.as_pointer(),
165+
FnPtr::<fn(Ptr<i32>, i32)>::new(add_1),
166+
(z.as_pointer()),
167+
5_u64,
168+
)
169+
}) == 107)
170+
);
171+
assert!(((*z.borrow()) == 6));
139172
let a: Value<Access_S_> = Rc::new(RefCell::new(<Access_S_>::default()));
140173
let cs: Value<Ptr<S>> = Rc::new(RefCell::new((s.as_pointer())));
141174
let cr: Ptr<S> = s.as_pointer();
@@ -186,6 +219,20 @@ pub trait SImpl {
186219
fn apply_10(&self, f: FnPtr<fn(Ptr<i32>)>, x: i32) -> i32;
187220
fn apply_11(&self, f: FnPtr<fn(Ptr<i32>, i32)>, x: i32) -> i32;
188221
fn apply_12(&self, f: FnPtr<fn(i32) -> i32>, x: i32) -> i32;
222+
fn combine_13(
223+
&self,
224+
p: Ptr<(Value<i32>, Value<i64>)>,
225+
f: FnPtr<fn(i32) -> i32>,
226+
q: Ptr<i32>,
227+
n: u64,
228+
) -> i32;
229+
fn combine_14(
230+
&self,
231+
p: Ptr<(Value<i32>, Value<i32>)>,
232+
f: FnPtr<fn(Ptr<i32>, i32)>,
233+
q: Ptr<i32>,
234+
n: u64,
235+
) -> i32;
189236
fn width_1_char(&self, x: i32) -> i32;
190237
fn width_1_int(&self, x: i32) -> i32;
191238
fn scale_2_2(&self, x: i32) -> i32;
@@ -243,6 +290,50 @@ impl SImpl for Ptr<S> {
243290
_lhs + ({ (*f.borrow()).call((*x.borrow())) })
244291
};
245292
}
293+
fn combine_13(
294+
&self,
295+
p: Ptr<(Value<i32>, Value<i64>)>,
296+
f: FnPtr<fn(i32) -> i32>,
297+
q: Ptr<i32>,
298+
n: u64,
299+
) -> i32 {
300+
let f: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(f));
301+
let q: Value<Ptr<i32>> = Rc::new(RefCell::new(q));
302+
let n: Value<u64> = Rc::new(RefCell::new(n));
303+
return {
304+
let _lhs = {
305+
let _lhs = {
306+
let _lhs = (*(*(*self).upgrade().deref()).base.borrow());
307+
_lhs + ((*(*p.upgrade().deref()).1.borrow()) as i32)
308+
};
309+
_lhs + ({ (*f.borrow()).call(((*q.borrow()).read())) })
310+
};
311+
_lhs + ((*n.borrow()) as i32)
312+
};
313+
}
314+
fn combine_14(
315+
&self,
316+
p: Ptr<(Value<i32>, Value<i32>)>,
317+
f: FnPtr<fn(Ptr<i32>, i32)>,
318+
q: Ptr<i32>,
319+
n: u64,
320+
) -> i32 {
321+
let f: Value<FnPtr<fn(Ptr<i32>, i32)>> = Rc::new(RefCell::new(f));
322+
let q: Value<Ptr<i32>> = Rc::new(RefCell::new(q));
323+
let n: Value<u64> = Rc::new(RefCell::new(n));
324+
({
325+
let _arg0: Ptr<i32> = (*q.borrow()).clone();
326+
let _arg1: i32 = ((*n.borrow()) as i32);
327+
(*f.borrow()).call(_arg0, _arg1)
328+
});
329+
return {
330+
let _lhs = {
331+
let _lhs = (*(*(*self).upgrade().deref()).base.borrow());
332+
_lhs + (*(*p.upgrade().deref()).0.borrow())
333+
};
334+
_lhs + ((*q.borrow()).read())
335+
};
336+
}
246337
fn width_1_char(&self, x: i32) -> i32 {
247338
let x: Value<i32> = Rc::new(RefCell::new(x));
248339
return ((*(*(*self).upgrade().deref()).base.borrow())

‎tests/unit/out/unsafe/overload_mangling.rs‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,29 @@ impl S {
6767
pub unsafe fn apply_12(&self, mut f: Option<unsafe fn(i32) -> i32>, mut x: i32) -> i32 {
6868
return ((self.base) + (unsafe { (f).unwrap()(x) }));
6969
}
70+
pub unsafe fn combine_13(
71+
&self,
72+
p: *const (i32, i64),
73+
mut f: Option<unsafe fn(i32) -> i32>,
74+
mut q: *const i32,
75+
mut n: u64,
76+
) -> i32 {
77+
return ((((self.base) + ((*p).1 as i32)) + (unsafe { (f).unwrap()((*q)) })) + (n as i32));
78+
}
79+
pub unsafe fn combine_14(
80+
&self,
81+
p: *const (i32, i32),
82+
mut f: Option<unsafe fn(*mut i32, i32)>,
83+
mut q: *mut i32,
84+
mut n: u64,
85+
) -> i32 {
86+
(unsafe {
87+
let _arg0: *mut i32 = q;
88+
let _arg1: i32 = (n as i32);
89+
(f).unwrap()(_arg0, _arg1)
90+
});
91+
return (((self.base) + ((*p).0)) + (*q));
92+
}
7093
pub unsafe fn width_1_char(&self, mut x: i32) -> i32 {
7194
return ((self.base) + ((x) * (::std::mem::size_of::<libc::c_char>() as i32)));
7295
}
@@ -120,6 +143,21 @@ unsafe fn main_0() -> i32 {
120143
assert!(((unsafe { S::apply_10(&s, Some(inc_0), 1,) }) == (102)));
121144
assert!(((unsafe { S::apply_11(&s, Some(add_1), 1,) }) == (111)));
122145
assert!(((unsafe { S::apply_12(&s, Some(twice_2), 3,) }) == (106)));
146+
let c: i32 = 3;
147+
assert!(
148+
((unsafe {
149+
let mut _p: (i32, i64) = (1.into(), 2_i64.into());
150+
S::combine_13(&s, &mut _p, Some(twice_2), (&c as *const i32), 4_u64)
151+
}) == (112))
152+
);
153+
let mut z: i32 = 1;
154+
assert!(
155+
((unsafe {
156+
let mut _p: (i32, i32) = (1.into(), 2.into());
157+
S::combine_14(&s, &mut _p, Some(add_1), (&mut z as *mut i32), 5_u64)
158+
}) == (107))
159+
);
160+
assert!(((z) == (6)));
123161
let mut a: Access_S_ = <Access_S_>::default();
124162
let mut cs: *const S = (&mut s as *mut S).cast_const();
125163
let cr: *const S = &s;

‎tests/unit/overload_mangling.cpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ struct S {
3636
return base + x;
3737
}
3838
int apply(int (*f)(int), int x) const { return base + f(x); }
39+
int combine(const std::pair<int, long> &p, int (*f)(int), const int *q,
40+
unsigned long n) const {
41+
return base + (int)p.second + f(*q) + (int)n;
42+
}
43+
int combine(const std::pair<int, int> &p, void (*f)(int *, int), int *q,
44+
unsigned long n) const {
45+
f(q, (int)n);
46+
return base + p.first + *q;
47+
}
3948
};
4049

4150
struct Box {
@@ -60,6 +69,11 @@ int main() {
6069
assert(s.apply(inc, 1) == 102);
6170
assert(s.apply(add, 1) == 111);
6271
assert(s.apply(twice, 3) == 106);
72+
const int c = 3;
73+
assert(s.combine(std::pair<int, long>(1, 2L), twice, &c, 4UL) == 112);
74+
int z = 1;
75+
assert(s.combine(std::pair<int, int>(1, 2), add, &z, 5UL) == 107);
76+
assert(z == 6);
6377
Access<S> a;
6478
const S *cs = &s;
6579
const S &cr = s;

0 commit comments

Comments
 (0)