Skip to content

Commit a9761ca

Browse files
committed
Add array const init test
1 parent 8cdf97c commit a9761ca

3 files changed

Lines changed: 130 additions & 0 deletions

File tree

tests/unit/array_const_init.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <assert.h>
2+
3+
struct S {
4+
int head;
5+
int tail[3];
6+
char buf[4];
7+
};
8+
9+
struct S s = {5};
10+
11+
int main() {
12+
assert(s.head == 5);
13+
for (int i = 0; i < 3; i++) {
14+
assert(s.tail[i] == 0);
15+
}
16+
for (int i = 0; i < 4; i++) {
17+
assert(s.buf[i] == 0);
18+
}
19+
return 0;
20+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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()]
10+
pub struct S {
11+
pub head: Value<i32>,
12+
pub tail: Value<Box<[i32]>>,
13+
pub buf: Value<Box<[u8]>>,
14+
}
15+
impl Default for S {
16+
fn default() -> Self {
17+
S {
18+
head: <Value<i32>>::default(),
19+
tail: Rc::new(RefCell::new(
20+
(0..3).map(|_| <i32>::default()).collect::<Box<[i32]>>(),
21+
)),
22+
buf: Rc::new(RefCell::new(
23+
(0..4).map(|_| <u8>::default()).collect::<Box<[u8]>>(),
24+
)),
25+
}
26+
}
27+
}
28+
impl ByteRepr for S {}
29+
thread_local!(
30+
pub static s_0: Value<S> = Rc::new(RefCell::new(S {
31+
head: Rc::new(RefCell::new(5)),
32+
tail: Rc::new(RefCell::new(Box::new([0; 3]))),
33+
buf: Rc::new(RefCell::new(Box::new([0; 4]))),
34+
}));
35+
);
36+
pub fn main() {
37+
std::process::exit(main_0());
38+
}
39+
fn main_0() -> i32 {
40+
assert!(((((*(*s_0.with(Value::clone).borrow()).head.borrow()) == 5) as i32) != 0));
41+
let i: Value<i32> = Rc::new(RefCell::new(0));
42+
'loop_: while ((((*i.borrow()) < 3) as i32) != 0) {
43+
assert!(
44+
((((*(*s_0.with(Value::clone).borrow()).tail.borrow())[(*i.borrow()) as usize] == 0)
45+
as i32)
46+
!= 0)
47+
);
48+
(*i.borrow_mut()).postfix_inc();
49+
}
50+
let i: Value<i32> = Rc::new(RefCell::new(0));
51+
'loop_: while ((((*i.borrow()) < 4) as i32) != 0) {
52+
assert!(
53+
(((((*(*s_0.with(Value::clone).borrow()).buf.borrow())[(*i.borrow()) as usize] as i32)
54+
== 0) as i32)
55+
!= 0)
56+
);
57+
(*i.borrow_mut()).postfix_inc();
58+
}
59+
return 0;
60+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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)]
11+
pub struct S {
12+
pub head: i32,
13+
pub tail: [i32; 3],
14+
pub buf: [u8; 4],
15+
}
16+
impl Default for S {
17+
fn default() -> Self {
18+
S {
19+
head: 0_i32,
20+
tail: [0_i32; 3],
21+
buf: [0_u8; 4],
22+
}
23+
}
24+
}
25+
pub static mut s_0: S = unsafe {
26+
S {
27+
head: 5,
28+
tail: [0; 3],
29+
buf: [0; 4],
30+
}
31+
};
32+
pub fn main() {
33+
unsafe {
34+
std::process::exit(main_0() as i32);
35+
}
36+
}
37+
unsafe fn main_0() -> i32 {
38+
assert!(((((s_0.head) == (5)) as i32) != 0));
39+
let mut i: i32 = 0;
40+
'loop_: while ((((i) < (3)) as i32) != 0) {
41+
assert!(((((s_0.tail[(i) as usize]) == (0)) as i32) != 0));
42+
i.postfix_inc();
43+
}
44+
let mut i: i32 = 0;
45+
'loop_: while ((((i) < (4)) as i32) != 0) {
46+
assert!(((((s_0.buf[(i) as usize] as i32) == (0)) as i32) != 0));
47+
i.postfix_inc();
48+
}
49+
return 0;
50+
}

0 commit comments

Comments
 (0)