Skip to content

Commit bc6ba8e

Browse files
fix sus provenance in tests/smoke.rs for miri
1 parent db9f528 commit bc6ba8e

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

tests/smoke.rs

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use backtrace::Frame;
2+
use core::ffi::c_void;
23
use std::ptr;
34
use std::thread;
45

5-
fn get_actual_fn_pointer(fp: usize) -> usize {
6+
fn get_actual_fn_pointer(fp: *mut c_void) -> *mut c_void {
67
// On AIX, the function name references a function descriptor.
78
// A function descriptor consists of (See https://reviews.llvm.org/D62532)
89
// * The address of the entry point of the function.
@@ -15,17 +16,18 @@ fn get_actual_fn_pointer(fp: usize) -> usize {
1516
// https://www.ibm.com/docs/en/aix/7.2?topic=program-understanding-programming-toc
1617
if cfg!(target_os = "aix") {
1718
unsafe {
18-
let actual_fn_entry = *(fp as *const usize);
19+
let actual_fn_entry = *(fp as *const *mut c_void);
1920
actual_fn_entry
2021
}
2122
} else {
22-
fp
23+
fp as *mut c_void
2324
}
2425
}
2526

2627
#[test]
2728
// FIXME: shouldn't ignore this test on i686-msvc, unsure why it's failing
2829
#[cfg_attr(all(target_arch = "x86", target_env = "msvc"), ignore)]
30+
#[inline(never)]
2931
#[rustfmt::skip] // we care about line numbers here
3032
fn smoke_test_frames() {
3133
frame_1(line!());
@@ -42,10 +44,10 @@ fn smoke_test_frames() {
4244
// Various platforms have various bits of weirdness about their
4345
// backtraces. To find a good starting spot let's search through the
4446
// frames
45-
let target = get_actual_fn_pointer(frame_4 as usize);
47+
let target = get_actual_fn_pointer(frame_4 as *mut c_void);
4648
let offset = v
4749
.iter()
48-
.map(|frame| frame.symbol_address() as usize)
50+
.map(|frame| frame.symbol_address())
4951
.enumerate()
5052
.filter_map(|(i, sym)| {
5153
if sym >= target {
@@ -61,39 +63,39 @@ fn smoke_test_frames() {
6163

6264
assert_frame(
6365
frames.next().unwrap(),
64-
get_actual_fn_pointer(frame_4 as usize),
66+
get_actual_fn_pointer(frame_4 as *mut c_void) as usize,
6567
"frame_4",
6668
"tests/smoke.rs",
6769
start_line + 6,
6870
9,
6971
);
7072
assert_frame(
7173
frames.next().unwrap(),
72-
get_actual_fn_pointer(frame_3 as usize),
74+
get_actual_fn_pointer(frame_3 as *mut c_void) as usize,
7375
"frame_3",
7476
"tests/smoke.rs",
7577
start_line + 3,
7678
52,
7779
);
7880
assert_frame(
7981
frames.next().unwrap(),
80-
get_actual_fn_pointer(frame_2 as usize),
82+
get_actual_fn_pointer(frame_2 as *mut c_void) as usize,
8183
"frame_2",
8284
"tests/smoke.rs",
8385
start_line + 2,
8486
52,
8587
);
8688
assert_frame(
8789
frames.next().unwrap(),
88-
get_actual_fn_pointer(frame_1 as usize),
90+
get_actual_fn_pointer(frame_1 as *mut c_void) as usize,
8991
"frame_1",
9092
"tests/smoke.rs",
9193
start_line + 1,
9294
52,
9395
);
9496
assert_frame(
9597
frames.next().unwrap(),
96-
get_actual_fn_pointer(smoke_test_frames as usize),
98+
get_actual_fn_pointer(smoke_test_frames as *mut c_void) as usize,
9799
"smoke_test_frames",
98100
"",
99101
0,
@@ -249,11 +251,11 @@ fn sp_smoke_test() {
249251
return;
250252

251253
#[inline(never)]
252-
fn recursive_stack_references(refs: &mut Vec<usize>) {
254+
fn recursive_stack_references(refs: &mut Vec<*mut c_void>) {
253255
assert!(refs.len() < 5);
254256

255-
let x = refs.len();
256-
refs.push(ptr::addr_of!(x) as usize);
257+
let mut x = refs.len();
258+
refs.push(ptr::addr_of_mut!(x).cast());
257259

258260
if refs.len() < 5 {
259261
recursive_stack_references(refs);
@@ -271,7 +273,7 @@ fn sp_smoke_test() {
271273
// mangled names.
272274

273275
fn make_trace_closure<'a>(
274-
refs: &'a mut Vec<usize>,
276+
refs: &'a mut Vec<*mut c_void>,
275277
) -> impl FnMut(&backtrace::Frame) -> bool + 'a {
276278
let mut child_sp = None;
277279
let mut child_ref = None;
@@ -289,9 +291,9 @@ fn sp_smoke_test() {
289291
})
290292
});
291293

292-
let sp = frame.sp() as usize;
293-
eprintln!("sp = {:p}", sp as *const u8);
294-
if sp == 0 {
294+
let sp = frame.sp();
295+
eprintln!("sp = {sp:p}");
296+
if sp as usize == 0 {
295297
// If the SP is null, then we don't have an implementation for
296298
// getting the SP on this target. Just keep walking the stack,
297299
// but don't make our assertions about the on-stack pointers and
@@ -306,8 +308,8 @@ fn sp_smoke_test() {
306308

307309
if is_recursive_stack_references {
308310
let r = refs.pop().unwrap();
309-
eprintln!("ref = {:p}", r as *const u8);
310-
if sp != 0 {
311+
eprintln!("ref = {:p}", r);
312+
if sp as usize != 0 {
311313
assert!(r > sp);
312314
if let Some(child_ref) = child_ref {
313315
assert!(sp >= child_ref);

0 commit comments

Comments
 (0)