Skip to content

Commit 7ad0ec4

Browse files
committed
Pass Miri with -Zmiri-strict-provenance
1 parent 056cdf8 commit 7ad0ec4

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/capture.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::PrintFmt;
22
use crate::{resolve, resolve_frame, trace, BacktraceFmt, Symbol, SymbolName};
33
use std::ffi::c_void;
44
use std::fmt;
5+
use std::mem;
56
use std::path::{Path, PathBuf};
67
use std::prelude::v1::*;
78

@@ -334,7 +335,13 @@ impl BacktraceSymbol {
334335
/// This function requires the `std` feature of the `backtrace` crate to be
335336
/// enabled, and the `std` feature is enabled by default.
336337
pub fn addr(&self) -> Option<*mut c_void> {
337-
self.addr.map(|s| s as *mut c_void)
338+
// To be compatible with strict provenance, we can't cast here.
339+
// The most right thing to do is always store addr as a pointer,
340+
// but that runs into problems with !Send + !Sync.
341+
// In any case, we're never going to dereference this pointer, so
342+
// a hand-written version of ptr::invalid_mut suffices.
343+
self.addr
344+
.map(|s| unsafe { mem::transmute::<usize, *mut c_void>(s) })
338345
}
339346

340347
/// Same as `Symbol::filename`

tests/skip_inner_frames.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ fn backtrace_new_unresolved_should_start_with_call_site_trace() {
2323
assert!(!b.frames().is_empty());
2424

2525
let this_ip = backtrace_new_unresolved_should_start_with_call_site_trace as usize;
26-
println!("this_ip: {:?}", this_ip as *const usize);
2726
let frame_ip = b.frames().first().unwrap().symbol_address() as usize;
2827
assert_eq!(this_ip, frame_ip);
2928
}

tests/smoke.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ fn sp_smoke_test() {
290290
});
291291

292292
let sp = frame.sp() as usize;
293-
eprintln!("sp = {:p}", sp as *const u8);
294293
if sp == 0 {
295294
// If the SP is null, then we don't have an implementation for
296295
// getting the SP on this target. Just keep walking the stack,
@@ -306,7 +305,6 @@ fn sp_smoke_test() {
306305

307306
if is_recursive_stack_references {
308307
let r = refs.pop().unwrap();
309-
eprintln!("ref = {:p}", r as *const u8);
310308
if sp != 0 {
311309
assert!(r > sp);
312310
if let Some(child_ref) = child_ref {

0 commit comments

Comments
 (0)