Skip to content

Commit d01e5b5

Browse files
committed
Report the range of uninit bytes in CTFE errors
1 parent 014bd82 commit d01e5b5

File tree

46 files changed

+175
-56
lines changed

Some content is hidden

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

46 files changed

+175
-56
lines changed

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
394394
interp_ok(try_validation!(
395395
self.ecx.read_immediate(val),
396396
self.path,
397-
Ub(InvalidUninitBytes(None)) =>
397+
Ub(InvalidUninitBytes(_)) =>
398398
Uninit { expected },
399399
// The `Unsup` cases can only occur during CTFE
400400
Unsup(ReadPointerAsInt(_)) =>

compiler/rustc_middle/src/mir/interpret/allocation.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,11 @@ impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes>
702702
read_provenance: bool,
703703
) -> AllocResult<Scalar<Prov>> {
704704
// First and foremost, if anything is uninit, bail.
705-
if self.init_mask.is_range_initialized(range).is_err() {
706-
return Err(AllocError::InvalidUninitBytes(None));
705+
if let Err(bad) = self.init_mask.is_range_initialized(range) {
706+
return Err(AllocError::InvalidUninitBytes(Some(BadBytesAccess {
707+
access: range,
708+
bad,
709+
})));
707710
}
708711

709712
// Get the integer part of the result. We HAVE TO check provenance before returning this!

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ fn main() {
1515
libc::pthread_cond_destroy(cond.as_mut_ptr());
1616

1717
libc::pthread_cond_destroy(cond.as_mut_ptr());
18-
//~^ ERROR: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
18+
//~^ ERROR: /Undefined Behavior: reading memory .*, but memory is uninitialized/
1919
}
2020
}

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

Lines changed: 8 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[0x0..0x4], but memory is uninitialized at [0x0..0x4], 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,13 @@ 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[0x0..0x4], in this allocation:
13+
ALLOC (stack variable, size: 48, align: 8) {
14+
0x00 │ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ ░░░░░░░░░░░░░░░░
15+
0x10 │ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ ░░░░░░░░░░░░░░░░
16+
0x20 │ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ ░░░░░░░░░░░░░░░░
17+
}
18+
1219
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1320

1421
error: aborting due to 1 previous error

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ fn main() {
1313
libc::pthread_condattr_destroy(attr.as_mut_ptr());
1414

1515
libc::pthread_condattr_destroy(attr.as_mut_ptr());
16-
//~^ ERROR: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
16+
//~^ ERROR: /Undefined Behavior: reading memory .*, but memory is uninitialized/
1717
}
1818
}

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

Lines changed: 6 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[0x0..0x4], but memory is uninitialized at [0x0..0x4], 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,11 @@ 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[0x0..0x4], in this allocation:
13+
ALLOC (stack variable, size: 4, align: 4) {
14+
__ __ __ __ │ ░░░░
15+
}
16+
1217
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1318

1419
error: aborting due to 1 previous error

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ fn main() {
1616
libc::pthread_mutex_destroy(mutex.as_mut_ptr());
1717

1818
libc::pthread_mutex_destroy(mutex.as_mut_ptr());
19-
//~^ ERROR: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
19+
//~^ ERROR: /Undefined Behavior: reading memory .*, but memory is uninitialized/
2020
}
2121
}

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

Lines changed: 8 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[0x0..0x4], but memory is uninitialized at [0x0..0x4], 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,13 @@ 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[0x0..0x4], in this allocation:
13+
ALLOC (stack variable, size: 40, align: 8) {
14+
0x00 │ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ ░░░░░░░░░░░░░░░░
15+
0x10 │ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ ░░░░░░░░░░░░░░░░
16+
0x20 │ __ __ __ __ __ __ __ __ │ ░░░░░░░░
17+
}
18+
1219
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1320

1421
error: aborting due to 1 previous error

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ fn main() {
1212
libc::pthread_mutexattr_destroy(attr.as_mut_ptr());
1313

1414
libc::pthread_mutexattr_destroy(attr.as_mut_ptr());
15-
//~^ ERROR: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
15+
//~^ ERROR: /Undefined Behavior: reading memory .*, but memory is uninitialized/
1616
}
1717
}

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

Lines changed: 6 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[0x0..0x4], but memory is uninitialized at [0x0..0x4], 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,11 @@ 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[0x0..0x4], in this allocation:
13+
ALLOC (stack variable, size: 4, align: 4) {
14+
__ __ __ __ │ ░░░░
15+
}
16+
1217
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
1318

1419
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)