Skip to content

Commit 20563e5

Browse files
committed
Add user_defined_same_as_libc test
1 parent 633db6f commit 20563e5

3 files changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
pub fn strchr_0(s: Ptr<u8>, c: i32) -> Ptr<u8> {
10+
let s: Value<Ptr<u8>> = Rc::new(RefCell::new(s));
11+
let c: Value<i32> = Rc::new(RefCell::new(c));
12+
return Ptr::<u8>::null();
13+
}
14+
pub fn main() {
15+
std::process::exit(main_0());
16+
}
17+
fn main_0() -> i32 {
18+
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(
19+
({
20+
let _s: Ptr<u8> = Ptr::from_string_literal("hello");
21+
let _c: i32 = ('l' as i32);
22+
strchr_0(_s, _c)
23+
}),
24+
));
25+
assert!(((((*p.borrow()).is_null()) as i32) != 0));
26+
return 0;
27+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 unsafe fn strchr_0(mut s: *const u8, mut c: i32) -> *mut u8 {
10+
return std::ptr::null_mut();
11+
}
12+
pub fn main() {
13+
unsafe {
14+
std::process::exit(main_0() as i32);
15+
}
16+
}
17+
unsafe fn main_0() -> i32 {
18+
let mut p: *const u8 = (unsafe {
19+
let _s: *const u8 = b"hello\0".as_ptr().cast_mut().cast_const();
20+
let _c: i32 = ('l' as i32);
21+
strchr_0(_s, _c)
22+
})
23+
.cast_const();
24+
assert!(((((p).is_null()) as i32) != 0));
25+
return 0;
26+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <assert.h>
2+
#include <stddef.h>
3+
4+
char *strchr(const char *s, int c) { return NULL; }
5+
6+
int main() {
7+
const char *p = strchr("hello", 'l');
8+
assert(p == NULL);
9+
return 0;
10+
}

0 commit comments

Comments
 (0)