Skip to content

Commit

Permalink
fix sus provenance in tests/smoke.rs for miri
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Jul 27, 2024
1 parent db9f528 commit b64e37f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions tests/smoke.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use backtrace::Frame;
use core::ffi::c_void;
use std::ptr;
use std::thread;

Expand Down Expand Up @@ -249,11 +250,11 @@ fn sp_smoke_test() {
return;

#[inline(never)]
fn recursive_stack_references(refs: &mut Vec<usize>) {
fn recursive_stack_references(refs: &mut Vec<*mut c_void>) {
assert!(refs.len() < 5);

let x = refs.len();
refs.push(ptr::addr_of!(x) as usize);
let mut x = refs.len();
refs.push(ptr::addr_of_mut!(x).cast());

if refs.len() < 5 {
recursive_stack_references(refs);
Expand All @@ -271,7 +272,7 @@ fn sp_smoke_test() {
// mangled names.

fn make_trace_closure<'a>(
refs: &'a mut Vec<usize>,
refs: &'a mut Vec<*mut c_void>,
) -> impl FnMut(&backtrace::Frame) -> bool + 'a {
let mut child_sp = None;
let mut child_ref = None;
Expand All @@ -289,9 +290,9 @@ fn sp_smoke_test() {
})
});

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

if is_recursive_stack_references {
let r = refs.pop().unwrap();
eprintln!("ref = {:p}", r as *const u8);
if sp != 0 {
eprintln!("ref = {:p}", r);
if sp as usize != 0 {
assert!(r > sp);
if let Some(child_ref) = child_ref {
assert!(sp >= child_ref);
Expand Down

0 comments on commit b64e37f

Please sign in to comment.