Skip to content

Commit 08ea88f

Browse files
committed
Add lobal-initialization-using-global test
1 parent 01516c1 commit 08ea88f

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <assert.h>
2+
3+
int first;
4+
int second = first + 1;
5+
6+
int main() {
7+
assert(first == 0);
8+
assert(second == first + 1);
9+
return 0;
10+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
thread_local!(
10+
pub static first: Value<i32> = <Value<i32>>::default();
11+
);
12+
thread_local!(
13+
pub static second: Value<i32> =
14+
Rc::new(RefCell::new(((*first.with(Value::clone).borrow()) + 1)));
15+
);
16+
pub fn main() {
17+
std::process::exit(main_0());
18+
}
19+
fn main_0() -> i32 {
20+
assert!(((*first.with(Value::clone).borrow()) == 0));
21+
assert!(((*second.with(Value::clone).borrow()) == ((*first.with(Value::clone).borrow()) + 1)));
22+
return 0;
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
pub static mut first: i32 = unsafe { 0_i32 };
10+
pub static mut second: i32 = unsafe { ((first) + (1)) };
11+
pub fn main() {
12+
unsafe {
13+
std::process::exit(main_0() as i32);
14+
}
15+
}
16+
unsafe fn main_0() -> i32 {
17+
assert!(((first) == (0)));
18+
assert!(((second) == ((first) + (1))));
19+
return 0;
20+
}

0 commit comments

Comments
 (0)