Skip to content

Commit be3bc86

Browse files
committed
Auto merge of #122565 - Zoxc:atomic-panic-msg, r=the8472
Try to write the panic message with a single `write_all` call This writes the panic message to a buffer before writing to stderr. This allows it to be printed with a single `write_all` call, preventing it from being interleaved with other outputs. It also adds newlines before and after the message ensuring that only the panic message will have its own lines. Before: ``` thread 'thread 'thread 'thread 'thread '<unnamed>thread 'thread 'thread 'thread '<unnamed><unnamed>thread '<unnamed>' panicked at ' panicked at <unnamed><unnamed><unnamed><unnamed><unnamed>' panicked at <unnamed>' panicked at src\heap.rssrc\heap.rs' panicked at ' panicked at ' panicked at ' panicked at ' panicked at src\heap.rs' panicked at src\heap.rs::src\heap.rssrc\heap.rssrc\heap.rssrc\heap.rssrc\heap.rs:src\heap.rs:455455:::::455:455::455455455455455:455:99:::::9:9: : 999: 999: assertion failed: size <= (*queue).block_size: : assertion failed: size <= (*queue).block_size: assertion failed: size <= (*queue).block_size: : : assertion failed: size <= (*queue).block_sizeassertion failed: size <= (*queue).block_sizeassertion failed: size <= (*queue).block_size assertion failed: size <= (*queue).block_size assertion failed: size <= (*queue).block_sizeassertion failed: size <= (*queue).block_sizeerror: process didn't exit successfully: `target\debug\direct_test.exe` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN) ``` After: ``` thread '<unnamed>' panicked at src\heap.rs:455:9: assertion failed: size <= (*queue).block_size thread '<unnamed>' panicked at src\heap.rs:455:9: assertion failed: size <= (*queue).block_size thread '<unnamed>' panicked at src\heap.rs:455:9: assertion failed: size <= (*queue).block_size error: process didn't exit successfully: `target\debug\direct_test.exe` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN) ``` --- try-jobs: x86_64-gnu-llvm-18
2 parents 9c11929 + ccfedcf commit be3bc86

36 files changed

+58
-0
lines changed

tests/fail/function_calls/exported_symbol_bad_unwind1.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/fail/function_calls/exported_symbol_bad_unwind1.rs:LL:CC:
23
explicit panic
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/fail/function_calls/exported_symbol_bad_unwind2.both.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
12
thread 'main' panicked at tests/fail/function_calls/exported_symbol_bad_unwind2.rs:LL:CC:
23
explicit panic
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
45
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
6+
57
thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
68
panic in a function that cannot unwind
79
stack backtrace:

tests/fail/function_calls/exported_symbol_bad_unwind2.definition.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
12
thread 'main' panicked at tests/fail/function_calls/exported_symbol_bad_unwind2.rs:LL:CC:
23
explicit panic
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
45
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
6+
57
thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
68
panic in a function that cannot unwind
79
stack backtrace:

tests/fail/function_calls/exported_symbol_bad_unwind2.extern_block.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/fail/function_calls/exported_symbol_bad_unwind2.rs:LL:CC:
23
explicit panic
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/fail/function_calls/return_pointer_on_unwind.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/fail/function_calls/return_pointer_on_unwind.rs:LL:CC:
23
explicit panic
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/fail/intrinsics/uninit_uninhabited_type.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
23
aborted execution: attempted to instantiate uninhabited type `!`
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/fail/intrinsics/zero_fn_ptr.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
23
aborted execution: attempted to zero-initialize type `fn()`, which is invalid
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/fail/panic/abort_unwind.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
12
thread 'main' panicked at tests/fail/panic/abort_unwind.rs:LL:CC:
23
PANIC!!!
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
45
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
6+
57
thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
68
panic in a function that cannot unwind
79
stack backtrace:

tests/fail/panic/bad_unwind.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/fail/panic/bad_unwind.rs:LL:CC:
23
explicit panic
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/fail/panic/double_panic.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
12
thread 'main' panicked at tests/fail/panic/double_panic.rs:LL:CC:
23
first
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
45
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
6+
57
thread 'main' panicked at tests/fail/panic/double_panic.rs:LL:CC:
68
second
79
stack backtrace:
10+
811
thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
912
panic in a destructor during cleanup
1013
thread caused non-unwinding panic. aborting.

tests/fail/panic/panic_abort1.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/fail/panic/panic_abort1.rs:LL:CC:
23
panicking from libstd
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/fail/panic/panic_abort2.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/fail/panic/panic_abort2.rs:LL:CC:
23
42-panicking from libstd
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/fail/panic/panic_abort3.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/fail/panic/panic_abort3.rs:LL:CC:
23
panicking from libcore
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/fail/panic/panic_abort4.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/fail/panic/panic_abort4.rs:LL:CC:
23
42-panicking from libcore
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/fail/panic/tls_macro_const_drop_panic.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread $NAME panicked at tests/fail/panic/tls_macro_const_drop_panic.rs:LL:CC:
23
ow
34
fatal runtime error: thread local panicked on drop

tests/fail/panic/tls_macro_drop_panic.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread $NAME panicked at tests/fail/panic/tls_macro_drop_panic.rs:LL:CC:
23
ow
34
fatal runtime error: thread local panicked on drop

tests/fail/terminate-terminator.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
warning: You have explicitly enabled MIR optimizations, overriding Miri's default which is to completely disable them. Any optimizations may hide UB that Miri would otherwise detect, and it is not necessarily possible to predict what kind of UB will be missed. If you are enabling optimizations to make Miri run faster, we advise using cfg(miri) to shrink your workload instead. The performance benefit of enabling MIR optimizations is usually marginal at best.
22

3+
34
thread 'main' panicked at tests/fail/terminate-terminator.rs:LL:CC:
45
explicit panic
56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
67
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
8+
79
thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
810
panic in a function that cannot unwind
911
stack backtrace:

tests/fail/unwind-action-terminate.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
12
thread 'main' panicked at tests/fail/unwind-action-terminate.rs:LL:CC:
23
explicit panic
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
45
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
6+
57
thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC:
68
panic in a function that cannot unwind
79
stack backtrace:

tests/panic/alloc_error_handler_hook.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/panic/alloc_error_handler_hook.rs:LL:CC:
23
alloc error hook called
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/panic/alloc_error_handler_panic.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at RUSTLIB/std/src/alloc.rs:LL:CC:
23
memory allocation of 4 bytes failed
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/panic/div-by-zero-2.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/panic/div-by-zero-2.rs:LL:CC:
23
attempt to divide by zero
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
12
thread 'main' panicked at tests/panic/function_calls/exported_symbol_good_unwind.rs:LL:CC:
23
explicit panic
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
45
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
6+
57
thread 'main' panicked at tests/panic/function_calls/exported_symbol_good_unwind.rs:LL:CC:
68
explicit panic
9+
710
thread 'main' panicked at tests/panic/function_calls/exported_symbol_good_unwind.rs:LL:CC:
811
explicit panic

tests/panic/mir-validation.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'rustc' panicked at compiler/rustc_mir_transform/src/validate.rs:LL:CC:
23
broken MIR in Item(DefId) (after phase change to runtime-optimized) at bb0[1]:
34
place (*(_2.0: *mut i32)) has deref as a later projection (it is only permitted as the first projection)

tests/panic/oob_subslice.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/panic/oob_subslice.rs:LL:CC:
23
range end index 5 out of range for slice of length 4
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/panic/overflowing-lsh-neg.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/panic/overflowing-lsh-neg.rs:LL:CC:
23
attempt to shift left with overflow
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/panic/overflowing-rsh-1.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/panic/overflowing-rsh-1.rs:LL:CC:
23
attempt to shift right with overflow
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/panic/overflowing-rsh-2.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/panic/overflowing-rsh-2.rs:LL:CC:
23
attempt to shift right with overflow
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/panic/panic1.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/panic/panic1.rs:LL:CC:
23
panicking from libstd
34
stack backtrace:

tests/panic/panic2.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/panic/panic2.rs:LL:CC:
23
42-panicking from libstd
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/panic/panic3.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/panic/panic3.rs:LL:CC:
23
panicking from libcore
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/panic/panic4.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/panic/panic4.rs:LL:CC:
23
42-panicking from libcore
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/panic/transmute_fat2.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
thread 'main' panicked at tests/panic/transmute_fat2.rs:LL:CC:
23
index out of bounds: the len is 0 but the index is 0
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

tests/pass/panic/catch_panic.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,46 @@
1+
12
thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
23
Hello from std::panic
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
45
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
56
Caught panic message (&str): Hello from std::panic
7+
68
thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
79
Hello from std::panic: 1
810
Caught panic message (String): Hello from std::panic: 1
11+
912
thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
1013
Hello from std::panic_any: 2
1114
Caught panic message (String): Hello from std::panic_any: 2
15+
1216
thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
1317
Box<dyn Any>
1418
Failed to get caught panic message.
19+
1520
thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
1621
Hello from core::panic
1722
Caught panic message (&str): Hello from core::panic
23+
1824
thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
1925
Hello from core::panic: 5
2026
Caught panic message (String): Hello from core::panic: 5
27+
2128
thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
2229
index out of bounds: the len is 3 but the index is 4
2330
Caught panic message (String): index out of bounds: the len is 3 but the index is 4
31+
2432
thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
2533
attempt to divide by zero
2634
Caught panic message (&str): attempt to divide by zero
35+
2736
thread 'main' panicked at RUSTLIB/core/src/ptr/const_ptr.rs:LL:CC:
2837
align_offset: align is not a power-of-two
2938
Caught panic message (&str): align_offset: align is not a power-of-two
39+
3040
thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
3141
assertion failed: false
3242
Caught panic message (&str): assertion failed: false
43+
3344
thread 'main' panicked at tests/pass/panic/catch_panic.rs:LL:CC:
3445
assertion failed: false
3546
Caught panic message (&str): assertion failed: false

tests/pass/panic/concurrent-panic.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
Thread 1 starting, will block on mutex
22
Thread 1 reported it has started
3+
34
thread '<unnamed>' panicked at tests/pass/panic/concurrent-panic.rs:LL:CC:
45
panic in thread 2
56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
67
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
78
Thread 2 blocking on thread 1
89
Thread 2 reported it has started
910
Unlocking mutex
11+
1012
thread '<unnamed>' panicked at tests/pass/panic/concurrent-panic.rs:LL:CC:
1113
panic in thread 1
1214
Thread 1 has exited
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
12
thread 'main' panicked at tests/pass/panic/nested_panic_caught.rs:LL:CC:
23
once
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
45
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
6+
57
thread 'main' panicked at tests/pass/panic/nested_panic_caught.rs:LL:CC:
68
twice
79
stack backtrace:

tests/pass/panic/thread_panic.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
12
thread '<unnamed>' panicked at tests/pass/panic/thread_panic.rs:LL:CC:
23
Hello!
34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
45
note: in Miri, you may have to set `MIRIFLAGS=-Zmiri-env-forward=RUST_BACKTRACE` for the environment variable to have an effect
6+
57
thread 'childthread' panicked at tests/pass/panic/thread_panic.rs:LL:CC:
68
Hello, world!

0 commit comments

Comments
 (0)