Skip to content

Commit 9e70fad

Browse files
committed
Show the memory of uninit reads
1 parent f81fba1 commit 9e70fad

File tree

50 files changed

+350
-126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+350
-126
lines changed

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ use std::mem;
22

33
use rustc_errors::{Diag, DiagArgName, DiagArgValue, DiagMessage, IntoDiagArg};
44
use rustc_middle::mir::AssertKind;
5-
use rustc_middle::mir::interpret::{Provenance, ReportedErrorInfo};
5+
use rustc_middle::mir::interpret::{Provenance, ReportedErrorInfo, UndefinedBehaviorInfo};
66
use rustc_middle::query::TyCtxtAt;
7+
use rustc_middle::ty::ConstInt;
78
use rustc_middle::ty::layout::LayoutError;
8-
use rustc_middle::ty::{ConstInt, TyCtxt};
99
use rustc_span::{Span, Symbol};
1010

1111
use super::CompileTimeMachine;
1212
use crate::errors::{self, FrameNote, ReportErrorExt};
1313
use crate::interpret::{
14-
ErrorHandled, Frame, InterpErrorInfo, InterpErrorKind, MachineStopType, err_inval,
14+
ErrorHandled, Frame, InterpCx, InterpErrorInfo, InterpErrorKind, MachineStopType, err_inval,
1515
err_machine_stop,
1616
};
1717

@@ -135,7 +135,7 @@ pub fn get_span_and_frames<'tcx>(
135135
/// You can use it to add a stacktrace of current execution according to
136136
/// `get_span_and_frames` or just give context on where the const eval error happened.
137137
pub(super) fn report<'tcx, C, F>(
138-
tcx: TyCtxt<'tcx>,
138+
ecx: &InterpCx<'tcx, CompileTimeMachine<'tcx>>,
139139
error: InterpErrorKind<'tcx>,
140140
span: Span,
141141
get_span_and_frames: C,
@@ -145,6 +145,7 @@ where
145145
C: FnOnce() -> (Span, Vec<FrameNote>),
146146
F: FnOnce(&mut Diag<'_>, Span, Vec<FrameNote>),
147147
{
148+
let tcx = ecx.tcx.tcx;
148149
// Special handling for certain errors
149150
match error {
150151
// Don't emit a new diagnostic for these errors, they are already reported elsewhere or
@@ -170,9 +171,24 @@ where
170171
InterpErrorKind::ResourceExhaustion(_) | InterpErrorKind::InvalidProgram(_)
171172
);
172173

174+
if let InterpErrorKind::UndefinedBehavior(UndefinedBehaviorInfo::InvalidUninitBytes(
175+
Some((alloc_id, _access)),
176+
)) = error
177+
{
178+
let bytes = ecx.print_alloc_bytes_for_diagnostics(alloc_id);
179+
let info = ecx.get_alloc_info(alloc_id);
180+
let raw_bytes = errors::RawBytesNote {
181+
size: info.size.bytes(),
182+
align: info.align.bytes(),
183+
bytes,
184+
};
185+
err.subdiagnostic(raw_bytes);
186+
}
187+
173188
error.add_args(&mut err);
174189

175190
mk(&mut err, span, frames);
191+
176192
let g = err.emit();
177193
let reported = if allowed_in_infallible {
178194
ReportedErrorInfo::allowed_in_infallible(g)

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ fn report_eval_error<'tcx>(
406406
let instance = with_no_trimmed_paths!(cid.instance.to_string());
407407

408408
super::report(
409-
*ecx.tcx,
409+
ecx,
410410
error,
411411
DUMMY_SP,
412412
|| super::get_span_and_frames(ecx.tcx, ecx.stack()),
@@ -446,7 +446,7 @@ fn report_validation_error<'tcx>(
446446
errors::RawBytesNote { size: info.size.bytes(), align: info.align.bytes(), bytes };
447447

448448
crate::const_eval::report(
449-
*ecx.tcx,
449+
ecx,
450450
error,
451451
DUMMY_SP,
452452
|| crate::const_eval::get_span_and_frames(ecx.tcx, ecx.stack()),

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_cond_double_destroy.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
//@ignore-target: windows # No pthreads on Windows
2+
//@ normalize-stderr-test: ".*│.*\n" -> ""
3+
//@ normalize-stderr-test: "size: [0-9]+" -> "size: SIZE"
4+
//@ normalize-stderr-test: "align: [0-9]+" -> "align: ALIGN"
5+
//@ normalize-stderr-test: "\[0x[0-9a-z]..0x[0-9a-z]\]" -> "[0xX..0xY]"
26

37
/// Test that destroying a pthread_cond twice fails, even without a check for number validity
48
@@ -15,6 +19,6 @@ fn main() {
1519
libc::pthread_cond_destroy(cond.as_mut_ptr());
1620

1721
libc::pthread_cond_destroy(cond.as_mut_ptr());
18-
//~^ ERROR: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
22+
//~^ ERROR: /Undefined Behavior: .* but memory is uninitialized/
1923
}
2024
}

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_cond_double_destroy.stderr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
1+
error: Undefined Behavior: reading memory at ALLOC[0xX..0xY], but memory is uninitialized at [0xX..0xY], and this operation requires initialized memory
22
--> tests/fail-dep/concurrency/libc_pthread_cond_double_destroy.rs:LL:CC
33
|
44
LL | libc::pthread_cond_destroy(cond.as_mut_ptr());
@@ -9,6 +9,10 @@ LL | libc::pthread_cond_destroy(cond.as_mut_ptr());
99
= note: BACKTRACE:
1010
= note: inside `main` at tests/fail-dep/concurrency/libc_pthread_cond_double_destroy.rs:LL:CC
1111

12+
Uninitialized memory occurred at ALLOC[0xX..0xY], in this allocation:
13+
ALLOC (stack variable, size: SIZE, align: ALIGN) {
14+
}
15+
1216
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1317

1418
error: aborting due to 1 previous error

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_condattr_double_destroy.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
//@ignore-target: windows # No pthreads on Windows
22
//@ignore-target: apple # Our macOS condattr don't have any fields so we do not notice this.
3+
//@ normalize-stderr-test: ".*│.*\n" -> ""
4+
//@ normalize-stderr-test: "size: [0-9]+" -> "size: SIZE"
5+
//@ normalize-stderr-test: "align: [0-9]+" -> "align: ALIGN"
6+
//@ normalize-stderr-test: "\[0x[0-9a-z]..0x[0-9a-z]\]" -> "[0xX..0xY]"
37

48
/// Test that destroying a pthread_condattr twice fails, even without a check for number validity
59
@@ -13,6 +17,6 @@ fn main() {
1317
libc::pthread_condattr_destroy(attr.as_mut_ptr());
1418

1519
libc::pthread_condattr_destroy(attr.as_mut_ptr());
16-
//~^ ERROR: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
20+
//~^ ERROR: /Undefined Behavior: .* but memory is uninitialized/
1721
}
1822
}

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_condattr_double_destroy.stderr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
1+
error: Undefined Behavior: reading memory at ALLOC[0xX..0xY], but memory is uninitialized at [0xX..0xY], and this operation requires initialized memory
22
--> tests/fail-dep/concurrency/libc_pthread_condattr_double_destroy.rs:LL:CC
33
|
44
LL | libc::pthread_condattr_destroy(attr.as_mut_ptr());
@@ -9,6 +9,10 @@ LL | libc::pthread_condattr_destroy(attr.as_mut_ptr());
99
= note: BACKTRACE:
1010
= note: inside `main` at tests/fail-dep/concurrency/libc_pthread_condattr_double_destroy.rs:LL:CC
1111

12+
Uninitialized memory occurred at ALLOC[0xX..0xY], in this allocation:
13+
ALLOC (stack variable, size: SIZE, align: ALIGN) {
14+
}
15+
1216
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1317

1418
error: aborting due to 1 previous error

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_mutex_double_destroy.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
//@ignore-target: windows # No pthreads on Windows
2+
//@ normalize-stderr-test: ".*│.*\n" -> ""
3+
//@ normalize-stderr-test: "size: [0-9]+" -> "size: SIZE"
4+
//@ normalize-stderr-test: "align: [0-9]+" -> "align: ALIGN"
5+
//@ normalize-stderr-test: "\[0x[0-9a-z]..0x[0-9a-z]\]" -> "[0xX..0xY]"
26

37
/// Test that destroying a pthread_mutex twice fails, even without a check for number validity
48
@@ -16,6 +20,6 @@ fn main() {
1620
libc::pthread_mutex_destroy(mutex.as_mut_ptr());
1721

1822
libc::pthread_mutex_destroy(mutex.as_mut_ptr());
19-
//~^ ERROR: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
23+
//~^ ERROR: /Undefined Behavior: .* but memory is uninitialized/
2024
}
2125
}

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_mutex_double_destroy.stderr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
1+
error: Undefined Behavior: reading memory at ALLOC[0xX..0xY], but memory is uninitialized at [0xX..0xY], and this operation requires initialized memory
22
--> tests/fail-dep/concurrency/libc_pthread_mutex_double_destroy.rs:LL:CC
33
|
44
LL | libc::pthread_mutex_destroy(mutex.as_mut_ptr());
@@ -9,6 +9,10 @@ LL | libc::pthread_mutex_destroy(mutex.as_mut_ptr());
99
= note: BACKTRACE:
1010
= note: inside `main` at tests/fail-dep/concurrency/libc_pthread_mutex_double_destroy.rs:LL:CC
1111

12+
Uninitialized memory occurred at ALLOC[0xX..0xY], in this allocation:
13+
ALLOC (stack variable, size: SIZE, align: ALIGN) {
14+
}
15+
1216
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1317

1418
error: aborting due to 1 previous error

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_mutexattr_double_destroy.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
//@ignore-target: windows # No pthreads on Windows
2+
//@ normalize-stderr-test: ".*│.*\n" -> ""
3+
//@ normalize-stderr-test: "size: [0-9]+" -> "size: SIZE"
4+
//@ normalize-stderr-test: "align: [0-9]+" -> "align: ALIGN"
5+
//@ normalize-stderr-test: "\[0x[0-9a-z]..0x[0-9a-z]\]" -> "[0xX..0xY]"
26

37
/// Test that destroying a pthread_mutexattr twice fails, even without a check for number validity
48
@@ -12,6 +16,6 @@ fn main() {
1216
libc::pthread_mutexattr_destroy(attr.as_mut_ptr());
1317

1418
libc::pthread_mutexattr_destroy(attr.as_mut_ptr());
15-
//~^ ERROR: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
19+
//~^ ERROR: /Undefined Behavior: .* but memory is uninitialized/
1620
}
1721
}

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_mutexattr_double_destroy.stderr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
1+
error: Undefined Behavior: reading memory at ALLOC[0xX..0xY], but memory is uninitialized at [0xX..0xY], and this operation requires initialized memory
22
--> tests/fail-dep/concurrency/libc_pthread_mutexattr_double_destroy.rs:LL:CC
33
|
44
LL | libc::pthread_mutexattr_destroy(attr.as_mut_ptr());
@@ -9,6 +9,10 @@ LL | libc::pthread_mutexattr_destroy(attr.as_mut_ptr());
99
= note: BACKTRACE:
1010
= note: inside `main` at tests/fail-dep/concurrency/libc_pthread_mutexattr_double_destroy.rs:LL:CC
1111

12+
Uninitialized memory occurred at ALLOC[0xX..0xY], in this allocation:
13+
ALLOC (stack variable, size: SIZE, align: ALIGN) {
14+
}
15+
1216
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1317

1418
error: aborting due to 1 previous error

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_rwlock_double_destroy.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
//@ignore-target: windows # No pthreads on Windows
2+
//@ normalize-stderr-test: ".*│.*\n" -> ""
3+
//@ normalize-stderr-test: "size: [0-9]+" -> "size: SIZE"
4+
//@ normalize-stderr-test: "align: [0-9]+" -> "align: ALIGN"
5+
//@ normalize-stderr-test: "\[0x[0-9a-z]..0x[0-9a-z]\]" -> "[0xX..0xY]"
26

37
/// Test that destroying a pthread_rwlock twice fails, even without a check for number validity
48
@@ -9,6 +13,6 @@ fn main() {
913
libc::pthread_rwlock_destroy(&mut lock);
1014

1115
libc::pthread_rwlock_destroy(&mut lock);
12-
//~^ ERROR: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
16+
//~^ ERROR: /Undefined Behavior: .* but memory is uninitialized/
1317
}
1418
}

src/tools/miri/tests/fail-dep/concurrency/libc_pthread_rwlock_double_destroy.stderr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
1+
error: Undefined Behavior: reading memory at ALLOC[0xX..0xY], but memory is uninitialized at [0xX..0xY], and this operation requires initialized memory
22
--> tests/fail-dep/concurrency/libc_pthread_rwlock_double_destroy.rs:LL:CC
33
|
44
LL | libc::pthread_rwlock_destroy(&mut lock);
@@ -9,6 +9,10 @@ LL | libc::pthread_rwlock_destroy(&mut lock);
99
= note: BACKTRACE:
1010
= note: inside `main` at tests/fail-dep/concurrency/libc_pthread_rwlock_double_destroy.rs:LL:CC
1111

12+
Uninitialized memory occurred at ALLOC[0xX..0xY], in this allocation:
13+
ALLOC (stack variable, size: SIZE, align: ALIGN) {
14+
}
15+
1216
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1317

1418
error: aborting due to 1 previous error

src/tools/miri/tests/fail/intrinsics/ptr_metadata_uninit_slice_data.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
//@compile-flags: -Zmiri-disable-validation
2+
//@ normalize-stderr-test: ".*│.*\n" -> ""
3+
//@ normalize-stderr-test: "size: [0-9]+" -> "size: SIZE"
4+
//@ normalize-stderr-test: "align: [0-9]+" -> "align: ALIGN"
5+
//@ normalize-stderr-test: "\[0x[0-9a-z]..0x[0-9a-z]\]" -> "[0xX..0xY]"
6+
27
#![feature(core_intrinsics, custom_mir)]
38
use std::intrinsics::mir::*;
49

@@ -9,7 +14,7 @@ use std::intrinsics::mir::*;
914
pub unsafe fn deref_meta(p: *const *const [i32]) -> usize {
1015
mir! {
1116
{
12-
RET = PtrMetadata(*p); //~ ERROR: /Undefined Behavior: .*, but memory is uninitialized/
17+
RET = PtrMetadata(*p); //~ ERROR: /Undefined Behavior: .* but memory is uninitialized/
1318
Return()
1419
}
1520
}

src/tools/miri/tests/fail/intrinsics/ptr_metadata_uninit_slice_data.stderr

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: Undefined Behavior: reading memory at ALLOC[0x0..0x8], but memory is uninitialized at [0x0..0x8], and this operation requires initialized memory
1+
error: Undefined Behavior: reading memory at ALLOC[0xX..0xY], but memory is uninitialized at [0xX..0xY], and this operation requires initialized memory
22
--> tests/fail/intrinsics/ptr_metadata_uninit_slice_data.rs:LL:CC
33
|
44
LL | RET = PtrMetadata(*p);
@@ -14,9 +14,8 @@ note: inside `main`
1414
LL | let _meta = deref_meta(p.as_ptr().cast());
1515
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1616

17-
Uninitialized memory occurred at ALLOC[0x0..0x8], in this allocation:
18-
ALLOC (stack variable, size: 16, align: 8) {
19-
__ __ __ __ __ __ __ __ 04 00 00 00 00 00 00 00 │ ░░░░░░░░........
17+
Uninitialized memory occurred at ALLOC[0xX..0xY], in this allocation:
18+
ALLOC (stack variable, size: SIZE, align: ALIGN) {
2019
}
2120

2221
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

src/tools/miri/tests/fail/intrinsics/ptr_metadata_uninit_slice_len.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
//@compile-flags: -Zmiri-disable-validation
2+
//@ normalize-stderr-test: ".*│.*\n" -> ""
3+
//@ normalize-stderr-test: "size: [0-9]+" -> "size: SIZE"
4+
//@ normalize-stderr-test: "align: [0-9]+" -> "align: ALIGN"
5+
//@ normalize-stderr-test: "\[0x[0-9a-z]+..0x[0-9a-z]+\]" -> "[0xX..0xY]"
6+
27
#![feature(core_intrinsics, custom_mir)]
38
use std::intrinsics::mir::*;
49

@@ -9,7 +14,7 @@ use std::intrinsics::mir::*;
914
pub unsafe fn deref_meta(p: *const *const [i32]) -> usize {
1015
mir! {
1116
{
12-
RET = PtrMetadata(*p); //~ ERROR: /Undefined Behavior: .*, but memory is uninitialized/
17+
RET = PtrMetadata(*p); //~ ERROR: /Undefined Behavior: .* but memory is uninitialized/
1318
Return()
1419
}
1520
}

src/tools/miri/tests/fail/intrinsics/ptr_metadata_uninit_slice_len.stderr

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | (*p.as_mut_ptr().cast::<[*const i32; 2]>())[0] = 4 as *const i32;
1212
= note: BACKTRACE:
1313
= note: inside `main` at tests/fail/intrinsics/ptr_metadata_uninit_slice_len.rs:LL:CC
1414

15-
error: Undefined Behavior: reading memory at ALLOC[0x8..0x10], but memory is uninitialized at [0x8..0x10], and this operation requires initialized memory
15+
error: Undefined Behavior: reading memory at ALLOC[0xX..0xY], but memory is uninitialized at [0xX..0xY], and this operation requires initialized memory
1616
--> tests/fail/intrinsics/ptr_metadata_uninit_slice_len.rs:LL:CC
1717
|
1818
LL | RET = PtrMetadata(*p);
@@ -28,9 +28,8 @@ note: inside `main`
2828
LL | let _meta = deref_meta(p.as_ptr().cast());
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3030

31-
Uninitialized memory occurred at ALLOC[0x8..0x10], in this allocation:
32-
ALLOC (stack variable, size: 16, align: 8) {
33-
╾────0x4[wildcard]────╼ __ __ __ __ __ __ __ __ │ ╾──────╼░░░░░░░░
31+
Uninitialized memory occurred at ALLOC[0xX..0xY], in this allocation:
32+
ALLOC (stack variable, size: SIZE, align: ALIGN) {
3433
}
3534

3635
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

src/tools/miri/tests/fail/intrinsics/ptr_metadata_uninit_thin.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
//@compile-flags: -Zmiri-disable-validation
2+
//@ normalize-stderr-test: ".*│.*\n" -> ""
3+
//@ normalize-stderr-test: "size: [0-9]+" -> "size: SIZE"
4+
//@ normalize-stderr-test: "align: [0-9]+" -> "align: ALIGN"
5+
//@ normalize-stderr-test: "\[0x[0-9a-z]..0x[0-9a-z]\]" -> "[0xX..0xY]"
6+
27
#![feature(core_intrinsics, custom_mir)]
38
use std::intrinsics::mir::*;
49

src/tools/miri/tests/fail/intrinsics/ptr_metadata_uninit_thin.stderr

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: Undefined Behavior: reading memory at ALLOC[0x0..0x8], but memory is uninitialized at [0x0..0x8], and this operation requires initialized memory
1+
error: Undefined Behavior: reading memory at ALLOC[0xX..0xY], but memory is uninitialized at [0xX..0xY], and this operation requires initialized memory
22
--> tests/fail/intrinsics/ptr_metadata_uninit_thin.rs:LL:CC
33
|
44
LL | RET = PtrMetadata(*p);
@@ -14,9 +14,8 @@ note: inside `main`
1414
LL | let _meta = deref_meta(p.as_ptr());
1515
| ^^^^^^^^^^^^^^^^^^^^^^
1616

17-
Uninitialized memory occurred at ALLOC[0x0..0x8], in this allocation:
18-
ALLOC (stack variable, size: 8, align: 8) {
19-
__ __ __ __ __ __ __ __ │ ░░░░░░░░
17+
Uninitialized memory occurred at ALLOC[0xX..0xY], in this allocation:
18+
ALLOC (stack variable, size: SIZE, align: ALIGN) {
2019
}
2120

2221
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: Undefined Behavior: reading memory at ALLOC[0x0..0x4], but memory is uninitialized at [0x0..0x4], and this operation requires initialized memory
2+
--> tests/fail/read_from_trivial_switch.rs:LL:CC
3+
|
4+
LL | let &(0 | _) = bad_ref;
5+
| ^^^^^^^^ Undefined Behavior occurred here
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `main` at tests/fail/read_from_trivial_switch.rs:LL:CC
11+
12+
Uninitialized memory occurred at ALLOC[0x0..0x4], in this allocation:
13+
ALLOC (stack variable, size: 4, align: 4) {
14+
__ __ __ __ │ ░░░░
15+
}
16+
17+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
18+
19+
error: aborting due to 1 previous error
20+

src/tools/miri/tests/fail/read_from_trivial_switch.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//
55
// See <https://github.com/rust-lang/miri/issues/4237>.
66

7+
//@ stderr-per-bitwidth
8+
79
use std::mem::MaybeUninit;
810

911
fn main() {

src/tools/miri/tests/fail/uninit/padding-enum.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
//@ normalize-stderr-test: ".*│.*\n" -> ""
2+
//@ normalize-stderr-test: "size: [0-9]+" -> "size: SIZE"
3+
//@ normalize-stderr-test: "align: [0-9]+" -> "align: ALIGN"
4+
//@ normalize-stderr-test: "\[0x[0-9a-z]..0x[0-9a-z]\]" -> "[0xX..0xY]"
5+
16
use std::mem;
27

38
// We have three fields to avoid the ScalarPair optimization.

0 commit comments

Comments
 (0)