You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #1480 - RalfJung:diagnostic-stacktrace-fix, r=oli-obk
fix non-fatal diagnostics stacktraces
Our non-fatal diagnostics are printed *after* completing the step that triggered them, which means the span and stacktrace used for them is that of the *next* MIR statement being executed. That's quite bad, obviously, as pointing to where in the source something happens is their entire point.
Here's an example:
```rust
use std::ptr;
static mut PTR: *mut u8 = ptr::null_mut();
fn get_ptr() -> *const u8 { unsafe { PTR }}
fn cause_ub() { unsafe {
let _x = &*get_ptr();
} }
fn main() { unsafe {
let mut l = 0;
PTR = &mut l;
let r = &mut *PTR;
cause_ub();
let _x = *r;
} }
```
This example is UB; if you track the pointer tag that is given in the final error, it points to the entire body of `cause_ub` as a span, instead of the `&*get_ptr();`.
I am not sure what the best way is to fix this. The cleanest way would be to capture a stack trace before the step and use it in case of a diagnostic, but that seems silly perf-wise. So instead I went with reconstructing the old stacktrace by going back one step in the MIR. This is however not possible if we were executing a `Terminator`... I think those cannot cause diagnostics but still, this is not great.
Any ideas?
r? @oli-obk
0 commit comments