Skip to content

Commit

Permalink
Auto merge of #2281 - RalfJung:rustup, r=RalfJung
Browse files Browse the repository at this point in the history
Rustup

Fix our stacktrace after rust-lang/rust#98549. Now we can control whether `caller_location` should be pruned!
  • Loading branch information
bors committed Jun 29, 2022
2 parents 29b1cc7 + 839c120 commit 63d6605
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 79 deletions.
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7f08d04d60d03e1a52dae61ce6aa50996898702b
493c960a3e6cdd2e2fbe8b6ea130fadea05f1ab0
7 changes: 7 additions & 0 deletions src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ fn prune_stacktrace<'mir, 'tcx>(
) -> (Vec<FrameInfo<'tcx>>, bool) {
match ecx.machine.backtrace_style {
BacktraceStyle::Off => {
// Remove all frames marked with `caller_location` -- that attribute indicates we
// usually want to point at the caller, not them.
stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*ecx.tcx));
// Retain one frame so that we can print a span for the error itself
stacktrace.truncate(1);
(stacktrace, false)
Expand All @@ -107,6 +110,10 @@ fn prune_stacktrace<'mir, 'tcx>(
// bug in the Rust runtime, we don't prune away every frame.
let has_local_frame = stacktrace.iter().any(|frame| ecx.machine.is_local(frame));
if has_local_frame {
// Remove all frames marked with `caller_location` -- that attribute indicates we
// usually want to point at the caller, not them.
stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*ecx.tcx));

// This is part of the logic that `std` uses to select the relevant part of a
// backtrace. But here, we only look for __rust_begin_short_backtrace, not
// __rust_end_short_backtrace because the end symbol comes from a call to the default
Expand Down
135 changes: 74 additions & 61 deletions src/shims/intrinsics.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/fail/data_race/atomic_read_na_write_race1.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ignore-windows: Concurrency on Windows is not supported yet.
#![feature(core_intrinsics)]

use std::intrinsics::atomic_load;
use std::intrinsics;
use std::sync::atomic::AtomicUsize;
use std::thread::spawn;

Expand All @@ -22,7 +22,7 @@ pub fn main() {

let j2 = spawn(move || {
//Equivalent to: (&*c.0).load(Ordering::SeqCst)
atomic_load(c.0 as *mut usize) //~ ERROR Data race detected between Atomic Load on Thread(id = 2) and Write on Thread(id = 1)
intrinsics::atomic_load_seqcst(c.0 as *mut usize) //~ ERROR Data race detected between Atomic Load on Thread(id = 2) and Write on Thread(id = 1)
});

j1.join().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions tests/fail/data_race/atomic_read_na_write_race1.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Undefined Behavior: Data race detected between Atomic Load on Thread(id = 2) and Write on Thread(id = 1) at ALLOC (current vector clock = VClock, conflicting timestamp = VClock)
--> $DIR/atomic_read_na_write_race1.rs:LL:CC
|
LL | atomic_load(c.0 as *mut usize)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between Atomic Load on Thread(id = 2) and Write on Thread(id = 1) at ALLOC (current vector clock = VClock, conflicting timestamp = VClock)
LL | intrinsics::atomic_load_seqcst(c.0 as *mut usize)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between Atomic Load on Thread(id = 2) and Write on Thread(id = 1) at ALLOC (current vector clock = VClock, conflicting timestamp = VClock)
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
Expand Down
1 change: 0 additions & 1 deletion tests/fail/panic/double_panic.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ LL | ABORT();
= note: inside `std::panicking::rust_panic_with_hook` at RUSTLIB/std/src/panicking.rs:LL:CC
= note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC
= note: inside `std::sys_common::backtrace::__rust_end_short_backtrace::<[closure@std::rt::begin_panic<&str>::{closure#0}], !>` at RUSTLIB/std/src/sys_common/backtrace.rs:LL:CC
= note: inside `std::rt::begin_panic::<&str>` at RUSTLIB/std/src/panicking.rs:LL:CC
note: inside `<Foo as std::ops::Drop>::drop` at RUSTLIB/std/src/panic.rs:LL:CC
--> $DIR/double_panic.rs:LL:CC
|
Expand Down
1 change: 0 additions & 1 deletion tests/fail/panic/panic_abort1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ LL | ABORT();
= note: inside `std::panicking::rust_panic_with_hook` at RUSTLIB/std/src/panicking.rs:LL:CC
= note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC
= note: inside `std::sys_common::backtrace::__rust_end_short_backtrace::<[closure@std::rt::begin_panic<&str>::{closure#0}], !>` at RUSTLIB/std/src/sys_common/backtrace.rs:LL:CC
= note: inside `std::rt::begin_panic::<&str>` at RUSTLIB/std/src/panicking.rs:LL:CC
note: inside `main` at RUSTLIB/std/src/panic.rs:LL:CC
--> $DIR/panic_abort1.rs:LL:CC
|
Expand Down
1 change: 0 additions & 1 deletion tests/fail/panic/panic_abort2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ LL | ABORT();
= note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC
= note: inside `std::sys_common::backtrace::__rust_end_short_backtrace::<[closure@std::panicking::begin_panic_handler::{closure#0}], !>` at RUSTLIB/std/src/sys_common/backtrace.rs:LL:CC
= note: inside `std::panicking::begin_panic_handler` at RUSTLIB/std/src/panicking.rs:LL:CC
= note: inside `std::rt::panic_fmt` at RUSTLIB/core/src/panicking.rs:LL:CC
note: inside `main` at RUSTLIB/std/src/panic.rs:LL:CC
--> $DIR/panic_abort2.rs:LL:CC
|
Expand Down
2 changes: 0 additions & 2 deletions tests/fail/panic/panic_abort3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ LL | ABORT();
= note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC
= note: inside `std::sys_common::backtrace::__rust_end_short_backtrace::<[closure@std::panicking::begin_panic_handler::{closure#0}], !>` at RUSTLIB/std/src/sys_common/backtrace.rs:LL:CC
= note: inside `std::panicking::begin_panic_handler` at RUSTLIB/std/src/panicking.rs:LL:CC
= note: inside `std::rt::panic_fmt` at RUSTLIB/core/src/panicking.rs:LL:CC
= note: inside `core::panicking::panic` at RUSTLIB/core/src/panicking.rs:LL:CC
note: inside `main` at RUSTLIB/core/src/panic.rs:LL:CC
--> $DIR/panic_abort3.rs:LL:CC
|
Expand Down
1 change: 0 additions & 1 deletion tests/fail/panic/panic_abort4.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ LL | ABORT();
= note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC
= note: inside `std::sys_common::backtrace::__rust_end_short_backtrace::<[closure@std::panicking::begin_panic_handler::{closure#0}], !>` at RUSTLIB/std/src/sys_common/backtrace.rs:LL:CC
= note: inside `std::panicking::begin_panic_handler` at RUSTLIB/std/src/panicking.rs:LL:CC
= note: inside `std::rt::panic_fmt` at RUSTLIB/core/src/panicking.rs:LL:CC
note: inside `main` at RUSTLIB/core/src/panic.rs:LL:CC
--> $DIR/panic_abort4.rs:LL:CC
|
Expand Down
2 changes: 1 addition & 1 deletion tests/fail/unaligned_pointers/atomic_unaligned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {
let z = [0u32; 2];
let zptr = &z as *const _ as *const u64;
unsafe {
::std::intrinsics::atomic_load(zptr);
::std::intrinsics::atomic_load_seqcst(zptr);
//~^ERROR accessing memory with alignment 4, but alignment 8 is required
}
}
4 changes: 2 additions & 2 deletions tests/fail/unaligned_pointers/atomic_unaligned.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
--> $DIR/atomic_unaligned.rs:LL:CC
|
LL | ::std::intrinsics::atomic_load(zptr);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
LL | ::std::intrinsics::atomic_load_seqcst(zptr);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
|
= help: this usually indicates that your program performed an invalid operation and caused Undefined Behavior
= help: but due to `-Zmiri-symbolic-alignment-check`, alignment errors can also be false positives
Expand Down
37 changes: 33 additions & 4 deletions tests/pass/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::atomic::{compiler_fence, fence, AtomicBool, AtomicIsize, AtomicU6

fn main() {
atomic_bool();
atomic_isize();
atomic_all_ops();
atomic_u64();
atomic_fences();
weak_sometimes_fails();
Expand All @@ -25,6 +25,7 @@ fn atomic_bool() {
assert_eq!(*ATOMIC.get_mut(), false);
}
}

// There isn't a trait to use to make this generic, so just use a macro
macro_rules! compare_exchange_weak_loop {
($atom:expr, $from:expr, $to:expr, $succ_order:expr, $fail_order:expr) => {
Expand All @@ -39,10 +40,39 @@ macro_rules! compare_exchange_weak_loop {
}
};
}
fn atomic_isize() {

/// Make sure we can handle all the intrinsics
fn atomic_all_ops() {
static ATOMIC: AtomicIsize = AtomicIsize::new(0);
static ATOMIC_UNSIGNED: AtomicU64 = AtomicU64::new(0);

// Make sure trans can emit all the intrinsics correctly
// loads
for o in [Relaxed, Acquire, SeqCst] {
ATOMIC.load(o);
}

// stores
for o in [Relaxed, Release, SeqCst] {
ATOMIC.store(1, o);
}

// most RMWs
for o in [Relaxed, Release, Acquire, AcqRel, SeqCst] {
ATOMIC.swap(0, o);
ATOMIC.fetch_or(0, o);
ATOMIC.fetch_xor(0, o);
ATOMIC.fetch_and(0, o);
ATOMIC.fetch_nand(0, o);
ATOMIC.fetch_add(0, o);
ATOMIC.fetch_sub(0, o);
ATOMIC.fetch_min(0, o);
ATOMIC.fetch_max(0, o);
ATOMIC_UNSIGNED.fetch_min(0, o);
ATOMIC_UNSIGNED.fetch_max(0, o);
}

// RMWs with deparate failure ordering
ATOMIC.store(0, SeqCst);
assert_eq!(ATOMIC.compare_exchange(0, 1, Relaxed, Relaxed), Ok(0));
assert_eq!(ATOMIC.compare_exchange(0, 2, Acquire, Relaxed), Err(1));
assert_eq!(ATOMIC.compare_exchange(0, 1, Release, Relaxed), Err(1));
Expand All @@ -59,7 +89,6 @@ fn atomic_isize() {
assert_eq!(ATOMIC.compare_exchange_weak(0, 1, Release, Relaxed), Err(1));
compare_exchange_weak_loop!(ATOMIC, 1, 0, AcqRel, Relaxed);
assert_eq!(ATOMIC.load(Relaxed), 0);
ATOMIC.compare_exchange_weak(0, 1, AcqRel, Relaxed).ok();
ATOMIC.compare_exchange_weak(0, 1, SeqCst, Relaxed).ok();
ATOMIC.compare_exchange_weak(0, 1, Acquire, Acquire).ok();
ATOMIC.compare_exchange_weak(0, 1, AcqRel, Acquire).ok();
Expand Down

0 comments on commit 63d6605

Please sign in to comment.