Skip to content

Commit d3a39fd

Browse files
committed
Replace strchr with a function that the compiler won't replace with a builitn
1 parent 2a35dae commit d3a39fd

2 files changed

Lines changed: 20 additions & 17 deletions

File tree

tests/unit/out/refcount/user_defined_same_as_libc.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@ use std::io::prelude::*;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
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();
9+
pub fn fopen_0(path: Ptr<u8>, mode: Ptr<u8>) -> Ptr<::std::fs::File> {
10+
let path: Value<Ptr<u8>> = Rc::new(RefCell::new(path));
11+
let mode: Value<Ptr<u8>> = Rc::new(RefCell::new(mode));
12+
(*path.borrow()).clone();
13+
(*mode.borrow()).clone();
14+
return Ptr::null();
1315
}
1416
pub fn main() {
1517
std::process::exit(main_0());
1618
}
1719
fn main_0() -> i32 {
18-
let p: Value<Ptr<u8>> = Rc::new(RefCell::new(
20+
let fp: Value<Ptr<::std::fs::File>> = Rc::new(RefCell::new(
1921
({
20-
let _s: Ptr<u8> = Ptr::from_string_literal("hello");
21-
let _c: i32 = ('l' as i32);
22-
strchr_0(_s, _c)
22+
let _path: Ptr<u8> = Ptr::from_string_literal("/etc/passwd");
23+
let _mode: Ptr<u8> = Ptr::from_string_literal("r");
24+
fopen_0(_path, _mode)
2325
}),
2426
));
25-
assert!(((((*p.borrow()).is_null()) as i32) != 0));
27+
assert!(((((*fp.borrow()).is_null()) as i32) != 0));
2628
return 0;
2729
}

tests/unit/out/unsafe/user_defined_same_as_libc.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use std::collections::BTreeMap;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
88
use std::rc::Rc;
9-
pub unsafe fn strchr_0(mut s: *const u8, mut c: i32) -> *mut u8 {
9+
pub unsafe fn fopen_0(mut path: *const u8, mut mode: *const u8) -> *mut ::std::fs::File {
10+
&(path);
11+
&(mode);
1012
return std::ptr::null_mut();
1113
}
1214
pub fn main() {
@@ -15,12 +17,11 @@ pub fn main() {
1517
}
1618
}
1719
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));
20+
let mut fp: *mut ::std::fs::File = (unsafe {
21+
let _path: *const u8 = b"/etc/passwd\0".as_ptr().cast_mut().cast_const();
22+
let _mode: *const u8 = b"r\0".as_ptr().cast_mut().cast_const();
23+
fopen_0(_path, _mode)
24+
});
25+
assert!(((((fp).is_null()) as i32) != 0));
2526
return 0;
2627
}

0 commit comments

Comments
 (0)