Skip to content

Commit db1b393

Browse files
committed
Add global_without_initializer test
1 parent c9bac6e commit db1b393

3 files changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <assert.h>
2+
#include <stdio.h>
3+
4+
struct S {
5+
int a;
6+
};
7+
8+
S *s;
9+
FILE *file;
10+
size_t size;
11+
12+
int main() {
13+
assert(s == nullptr);
14+
assert(file == nullptr);
15+
assert(size == 0);
16+
return 0;
17+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 S {
11+
pub a: Value<i32>,
12+
}
13+
impl Clone for S {
14+
fn clone(&self) -> Self {
15+
let mut this = Self {
16+
a: Rc::new(RefCell::new((*self.a.borrow()))),
17+
};
18+
this
19+
}
20+
}
21+
impl ByteRepr for S {}
22+
thread_local!(
23+
pub static s: Value<Ptr<S>> = Rc::new(RefCell::new(Ptr::<S>::null()));
24+
);
25+
thread_local!(
26+
pub static file: Value<Ptr<::std::fs::File>> = Rc::new(RefCell::new(Ptr::<_IO_FILE>::null()));
27+
);
28+
thread_local!(
29+
pub static size: Value<u64> = <Value<u64>>::default();
30+
);
31+
pub fn main() {
32+
std::process::exit(main_0());
33+
}
34+
fn main_0() -> i32 {
35+
assert!((*s.with(Value::clone).borrow()).is_null());
36+
assert!((*file.with(Value::clone).borrow()).is_null());
37+
assert!(((*size.with(Value::clone).borrow()) == 0_u64));
38+
return 0;
39+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 S {
12+
pub a: i32,
13+
}
14+
pub static mut s: *mut S = std::ptr::null_mut();
15+
pub static mut file: *mut ::std::fs::File = std::ptr::null_mut();
16+
pub static mut size: u64 = 0_u64;
17+
pub fn main() {
18+
unsafe {
19+
std::process::exit(main_0() as i32);
20+
}
21+
}
22+
unsafe fn main_0() -> i32 {
23+
assert!((s).is_null());
24+
assert!((file).is_null());
25+
assert!(((size) == (0_u64)));
26+
return 0;
27+
}

0 commit comments

Comments
 (0)