Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 63d6605

Browse files
committedJun 29, 2022
Auto merge of rust-lang#2281 - RalfJung:rustup, r=RalfJung
Rustup Fix our stacktrace after rust-lang#98549. Now we can control whether `caller_location` should be pruned!
2 parents 29b1cc7 + 839c120 commit 63d6605

13 files changed

+122
-79
lines changed
 

‎rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7f08d04d60d03e1a52dae61ce6aa50996898702b
1+
493c960a3e6cdd2e2fbe8b6ea130fadea05f1ab0

‎src/diagnostics.rs

+7
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ fn prune_stacktrace<'mir, 'tcx>(
9696
) -> (Vec<FrameInfo<'tcx>>, bool) {
9797
match ecx.machine.backtrace_style {
9898
BacktraceStyle::Off => {
99+
// Remove all frames marked with `caller_location` -- that attribute indicates we
100+
// usually want to point at the caller, not them.
101+
stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*ecx.tcx));
99102
// Retain one frame so that we can print a span for the error itself
100103
stacktrace.truncate(1);
101104
(stacktrace, false)
@@ -107,6 +110,10 @@ fn prune_stacktrace<'mir, 'tcx>(
107110
// bug in the Rust runtime, we don't prune away every frame.
108111
let has_local_frame = stacktrace.iter().any(|frame| ecx.machine.is_local(frame));
109112
if has_local_frame {
113+
// Remove all frames marked with `caller_location` -- that attribute indicates we
114+
// usually want to point at the caller, not them.
115+
stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*ecx.tcx));
116+
110117
// This is part of the logic that `std` uses to select the relevant part of a
111118
// backtrace. But here, we only look for __rust_begin_short_backtrace, not
112119
// __rust_end_short_backtrace because the end symbol comes from a call to the default

‎src/shims/intrinsics.rs

+74-61
Large diffs are not rendered by default.

‎tests/fail/data_race/atomic_read_na_write_race1.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
22
#![feature(core_intrinsics)]
33

4-
use std::intrinsics::atomic_load;
4+
use std::intrinsics;
55
use std::sync::atomic::AtomicUsize;
66
use std::thread::spawn;
77

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

2323
let j2 = spawn(move || {
2424
//Equivalent to: (&*c.0).load(Ordering::SeqCst)
25-
atomic_load(c.0 as *mut usize) //~ ERROR Data race detected between Atomic Load on Thread(id = 2) and Write on Thread(id = 1)
25+
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)
2626
});
2727

2828
j1.join().unwrap();

‎tests/fail/data_race/atomic_read_na_write_race1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
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)
22
--> $DIR/atomic_read_na_write_race1.rs:LL:CC
33
|
4-
LL | atomic_load(c.0 as *mut usize)
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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)
4+
LL | intrinsics::atomic_load_seqcst(c.0 as *mut usize)
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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)
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

‎tests/fail/panic/double_panic.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ LL | ABORT();
7575
= note: inside `std::panicking::rust_panic_with_hook` at RUSTLIB/std/src/panicking.rs:LL:CC
7676
= note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC
7777
= 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
78-
= note: inside `std::rt::begin_panic::<&str>` at RUSTLIB/std/src/panicking.rs:LL:CC
7978
note: inside `<Foo as std::ops::Drop>::drop` at RUSTLIB/std/src/panic.rs:LL:CC
8079
--> $DIR/double_panic.rs:LL:CC
8180
|

‎tests/fail/panic/panic_abort1.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ LL | ABORT();
1212
= note: inside `std::panicking::rust_panic_with_hook` at RUSTLIB/std/src/panicking.rs:LL:CC
1313
= note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC
1414
= 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
15-
= note: inside `std::rt::begin_panic::<&str>` at RUSTLIB/std/src/panicking.rs:LL:CC
1615
note: inside `main` at RUSTLIB/std/src/panic.rs:LL:CC
1716
--> $DIR/panic_abort1.rs:LL:CC
1817
|

‎tests/fail/panic/panic_abort2.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ LL | ABORT();
1313
= note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC
1414
= 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
1515
= note: inside `std::panicking::begin_panic_handler` at RUSTLIB/std/src/panicking.rs:LL:CC
16-
= note: inside `std::rt::panic_fmt` at RUSTLIB/core/src/panicking.rs:LL:CC
1716
note: inside `main` at RUSTLIB/std/src/panic.rs:LL:CC
1817
--> $DIR/panic_abort2.rs:LL:CC
1918
|

‎tests/fail/panic/panic_abort3.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ LL | ABORT();
1313
= note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC
1414
= 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
1515
= note: inside `std::panicking::begin_panic_handler` at RUSTLIB/std/src/panicking.rs:LL:CC
16-
= note: inside `std::rt::panic_fmt` at RUSTLIB/core/src/panicking.rs:LL:CC
17-
= note: inside `core::panicking::panic` at RUSTLIB/core/src/panicking.rs:LL:CC
1816
note: inside `main` at RUSTLIB/core/src/panic.rs:LL:CC
1917
--> $DIR/panic_abort3.rs:LL:CC
2018
|

‎tests/fail/panic/panic_abort4.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ LL | ABORT();
1313
= note: inside closure at RUSTLIB/std/src/panicking.rs:LL:CC
1414
= 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
1515
= note: inside `std::panicking::begin_panic_handler` at RUSTLIB/std/src/panicking.rs:LL:CC
16-
= note: inside `std::rt::panic_fmt` at RUSTLIB/core/src/panicking.rs:LL:CC
1716
note: inside `main` at RUSTLIB/core/src/panic.rs:LL:CC
1817
--> $DIR/panic_abort4.rs:LL:CC
1918
|

‎tests/fail/unaligned_pointers/atomic_unaligned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() {
77
let z = [0u32; 2];
88
let zptr = &z as *const _ as *const u64;
99
unsafe {
10-
::std::intrinsics::atomic_load(zptr);
10+
::std::intrinsics::atomic_load_seqcst(zptr);
1111
//~^ERROR accessing memory with alignment 4, but alignment 8 is required
1212
}
1313
}

‎tests/fail/unaligned_pointers/atomic_unaligned.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
22
--> $DIR/atomic_unaligned.rs:LL:CC
33
|
4-
LL | ::std::intrinsics::atomic_load(zptr);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
4+
LL | ::std::intrinsics::atomic_load_seqcst(zptr);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
66
|
77
= help: this usually indicates that your program performed an invalid operation and caused Undefined Behavior
88
= help: but due to `-Zmiri-symbolic-alignment-check`, alignment errors can also be false positives

‎tests/pass/atomic.rs

+33-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::atomic::{compiler_fence, fence, AtomicBool, AtomicIsize, AtomicU6
22

33
fn main() {
44
atomic_bool();
5-
atomic_isize();
5+
atomic_all_ops();
66
atomic_u64();
77
atomic_fences();
88
weak_sometimes_fails();
@@ -25,6 +25,7 @@ fn atomic_bool() {
2525
assert_eq!(*ATOMIC.get_mut(), false);
2626
}
2727
}
28+
2829
// There isn't a trait to use to make this generic, so just use a macro
2930
macro_rules! compare_exchange_weak_loop {
3031
($atom:expr, $from:expr, $to:expr, $succ_order:expr, $fail_order:expr) => {
@@ -39,10 +40,39 @@ macro_rules! compare_exchange_weak_loop {
3940
}
4041
};
4142
}
42-
fn atomic_isize() {
43+
44+
/// Make sure we can handle all the intrinsics
45+
fn atomic_all_ops() {
4346
static ATOMIC: AtomicIsize = AtomicIsize::new(0);
47+
static ATOMIC_UNSIGNED: AtomicU64 = AtomicU64::new(0);
4448

45-
// Make sure trans can emit all the intrinsics correctly
49+
// loads
50+
for o in [Relaxed, Acquire, SeqCst] {
51+
ATOMIC.load(o);
52+
}
53+
54+
// stores
55+
for o in [Relaxed, Release, SeqCst] {
56+
ATOMIC.store(1, o);
57+
}
58+
59+
// most RMWs
60+
for o in [Relaxed, Release, Acquire, AcqRel, SeqCst] {
61+
ATOMIC.swap(0, o);
62+
ATOMIC.fetch_or(0, o);
63+
ATOMIC.fetch_xor(0, o);
64+
ATOMIC.fetch_and(0, o);
65+
ATOMIC.fetch_nand(0, o);
66+
ATOMIC.fetch_add(0, o);
67+
ATOMIC.fetch_sub(0, o);
68+
ATOMIC.fetch_min(0, o);
69+
ATOMIC.fetch_max(0, o);
70+
ATOMIC_UNSIGNED.fetch_min(0, o);
71+
ATOMIC_UNSIGNED.fetch_max(0, o);
72+
}
73+
74+
// RMWs with deparate failure ordering
75+
ATOMIC.store(0, SeqCst);
4676
assert_eq!(ATOMIC.compare_exchange(0, 1, Relaxed, Relaxed), Ok(0));
4777
assert_eq!(ATOMIC.compare_exchange(0, 2, Acquire, Relaxed), Err(1));
4878
assert_eq!(ATOMIC.compare_exchange(0, 1, Release, Relaxed), Err(1));
@@ -59,7 +89,6 @@ fn atomic_isize() {
5989
assert_eq!(ATOMIC.compare_exchange_weak(0, 1, Release, Relaxed), Err(1));
6090
compare_exchange_weak_loop!(ATOMIC, 1, 0, AcqRel, Relaxed);
6191
assert_eq!(ATOMIC.load(Relaxed), 0);
62-
ATOMIC.compare_exchange_weak(0, 1, AcqRel, Relaxed).ok();
6392
ATOMIC.compare_exchange_weak(0, 1, SeqCst, Relaxed).ok();
6493
ATOMIC.compare_exchange_weak(0, 1, Acquire, Acquire).ok();
6594
ATOMIC.compare_exchange_weak(0, 1, AcqRel, Acquire).ok();

0 commit comments

Comments
 (0)
Failed to load comments.