Skip to content

Commit 798c406

Browse files
committed
Fix testsuite compilation
1 parent 0edd490 commit 798c406

4 files changed

Lines changed: 107 additions & 3 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2866,7 +2866,8 @@ bool Converter::IsReferenceType(const clang::Expr *expr) const {
28662866
GetReturnTypeOfFunction(call)->isReferenceType();
28672867
}
28682868
if (const auto *decl_ref = clang::dyn_cast<clang::DeclRefExpr>(e)) {
2869-
return decl_ref->getDecl()->getType()->isReferenceType();
2869+
return GetDeclRefType(curr_function_, decl_ref, decl_ref->getDecl())
2870+
->isReferenceType();
28702871
}
28712872
if (const auto *member = clang::dyn_cast<clang::MemberExpr>(e)) {
28722873
return member->getMemberDecl()->getType()->isReferenceType();

‎tests/unit/lambda_capture_ref.cpp‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// no-compile: refcount
21
#include <assert.h>
32
#include <stddef.h>
43
#include <stdint.h>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
10+
#[byte_size(8)]
11+
pub struct S {
12+
#[offset(0)]
13+
pub x: i32,
14+
#[offset(4)]
15+
pub y: i32,
16+
}
17+
pub fn main() {
18+
__cpp2rust_init_globals();
19+
std::process::exit(main_0());
20+
}
21+
fn main_0() -> i32 {
22+
let base: Value<i32> = Rc::new(RefCell::new(10));
23+
let add_base: Value<FnPtr<fn(i32) -> i32>> = Rc::new(RefCell::new(lambda!(
24+
{
25+
let base: Ptr<i32> = base.as_pointer();
26+
},
27+
|x: i32| -> i32 {
28+
let x: Value<i32> = Rc::new(RefCell::new(x));
29+
return ((*x.borrow()) + (base.read()));
30+
}
31+
)));
32+
assert!((({ (*add_base.borrow()).call(5,) }) == 15));
33+
(*base.borrow_mut()) = 100;
34+
assert!((({ (*add_base.borrow()).call(5,) }) == 105));
35+
let s: Value<S> = Rc::new(RefCell::new(S { x: 1, y: 2 }));
36+
let sum: Value<FnPtr<fn() -> i32>> = Rc::new(RefCell::new(lambda!(
37+
{
38+
let s: Ptr<S> = s.as_pointer();
39+
},
40+
|| -> i32 {
41+
return (s.with(|__s| __s.x) + s.with(|__s| __s.y));
42+
}
43+
)));
44+
assert!((({ (*sum.borrow()).call() }) == 3));
45+
(*s.borrow_mut()).x = 50;
46+
assert!((({ (*sum.borrow()).call() }) == 52));
47+
let counter: Value<i32> = Rc::new(RefCell::new(0));
48+
let bump: Value<FnPtr<fn()>> = Rc::new(RefCell::new(lambda!(
49+
{
50+
let counter: Ptr<i32> = counter.as_pointer();
51+
},
52+
|| {
53+
counter.with_mut(|__v| __v.postfix_inc());
54+
}
55+
)));
56+
({ (*bump.borrow()).call() });
57+
({ (*bump.borrow()).call() });
58+
assert!(((*counter.borrow()) == 2));
59+
let arr: Value<Box<[u16]>> = Rc::new(RefCell::new(Box::new([3_u16, 1_u16, 2_u16, 0_u16])));
60+
let swap: Value<FnPtr<fn(usize, usize)>> = Rc::new(RefCell::new(lambda!(
61+
{
62+
let arr: Ptr<u16> = arr.as_pointer();
63+
},
64+
|i: usize, j: usize| {
65+
let i: Value<usize> = Rc::new(RefCell::new(i));
66+
let j: Value<usize> = Rc::new(RefCell::new(j));
67+
let t: Value<u16> = Rc::new(RefCell::new((elem!((arr), (*j.borrow())).read())));
68+
elem!((arr), (*j.borrow())).write({ (elem!((arr), (*i.borrow())).read()) });
69+
elem!((arr), (*i.borrow())).write((*t.borrow()));
70+
}
71+
)));
72+
({ (*swap.borrow()).call(0_usize, 3_usize) });
73+
assert!((((*arr.borrow())[(0) as usize] as i32) == 0));
74+
assert!((((*arr.borrow())[(3) as usize] as i32) == 3));
75+
let total: Value<i32> = Rc::new(RefCell::new(0));
76+
let add: Value<FnPtr<fn(i32)>> = Rc::new(RefCell::new(lambda!(
77+
{
78+
let t: Ptr<i32> = total.as_pointer();
79+
},
80+
|x: i32| {
81+
let x: Value<i32> = Rc::new(RefCell::new(x));
82+
{
83+
let _ptr = t.clone();
84+
_ptr.write(_ptr.read() + { (*x.borrow()) })
85+
};
86+
}
87+
)));
88+
({ (*add.borrow()).call(2) });
89+
({ (*add.borrow()).call(3) });
90+
assert!(((*total.borrow()) == 5));
91+
let set_y: Value<FnPtr<fn(i32)>> = Rc::new(RefCell::new(lambda!(
92+
{
93+
let y: Ptr<i32> = field_ptr!(s.as_pointer(), y);
94+
},
95+
|v: i32| {
96+
let v: Value<i32> = Rc::new(RefCell::new(v));
97+
y.write({ (*v.borrow()) });
98+
}
99+
)));
100+
({ (*set_y.borrow()).call(9) });
101+
assert!(({ (*s.borrow()).y } == 9));
102+
return 0;
103+
}
104+
pub fn __cpp2rust_init_globals() {}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ unsafe fn main_0() -> i32 {
4848
|y: i32| -> i32 {
4949
let mut inner: FnPtr<fn(i32) -> i32> = lambda_unsafe!(
5050
{
51-
let x: *mut i32 = &mut (*x);
51+
let x: *mut i32 = x;
5252
let y: i32 = y;
5353
},
5454
|z: i32| -> i32 {

0 commit comments

Comments
 (0)