Commit 357bd4a
authored
Rollup merge of rust-lang#96162 - RalfJung:mark-uninit, r=oli-obk
interpret: Fix writing uninit to an allocation
When calling `mark_init`, we need to also be mindful of what happens with the relocations! Specifically, when we de-init memory, we need to clear relocations in that range as well or else strange things will happen (and printing will not show the de-init, since relocations take precedence there).
Fixes rust-lang/miri#2068.
Here's the Miri testcase that this fixes (requires `-Zmiri-disable-validation`):
```rust
use std::mem::MaybeUninit;
fn main() { unsafe {
let mut x = MaybeUninit::<i64>::uninit();
// Put in a ptr.
x.as_mut_ptr().cast::<&i32>().write_unaligned(&0);
// Overwrite parts of that pointer with 'uninit' through a Scalar.
let ptr = x.as_mut_ptr().cast::<i32>();
*ptr = MaybeUninit::uninit().assume_init();
// Reading this back should hence work fine.
let _c = *ptr;
} }
```
Previously this failed with
```
error: unsupported operation: unable to turn pointer into raw bytes
--> ../miri/uninit.rs:11:14
|
11 | let _c = *ptr;
| ^^^^ unable to turn pointer into raw bytes
|
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
= note: inside `main` at ../miri/uninit.rs:11:14
```File tree
4 files changed
+38
-13
lines changed- compiler
- rustc_const_eval/src/interpret
- rustc_middle/src/mir
- interpret
4 files changed
+38
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
892 | 892 | | |
893 | 893 | | |
894 | 894 | | |
895 | | - | |
896 | | - | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
897 | 900 | | |
898 | 901 | | |
899 | 902 | | |
| |||
1053 | 1056 | | |
1054 | 1057 | | |
1055 | 1058 | | |
1056 | | - | |
1057 | | - | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
1058 | 1063 | | |
1059 | 1064 | | |
1060 | 1065 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
823 | 823 | | |
824 | 824 | | |
825 | 825 | | |
826 | | - | |
| 826 | + | |
827 | 827 | | |
828 | 828 | | |
829 | 829 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
272 | | - | |
| 272 | + | |
273 | 273 | | |
274 | 274 | | |
275 | 275 | | |
| |||
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
432 | | - | |
433 | | - | |
| 432 | + | |
434 | 433 | | |
435 | 434 | | |
436 | 435 | | |
| |||
455 | 454 | | |
456 | 455 | | |
457 | 456 | | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
458 | 464 | | |
459 | 465 | | |
460 | 466 | | |
| |||
561 | 567 | | |
562 | 568 | | |
563 | 569 | | |
| 570 | + | |
| 571 | + | |
564 | 572 | | |
565 | | - | |
| 573 | + | |
566 | 574 | | |
567 | 575 | | |
568 | 576 | | |
| |||
575 | 583 | | |
576 | 584 | | |
577 | 585 | | |
578 | | - | |
| 586 | + | |
579 | 587 | | |
580 | 588 | | |
581 | 589 | | |
582 | 590 | | |
583 | 591 | | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
584 | 597 | | |
585 | 598 | | |
586 | 599 | | |
| |||
593 | 606 | | |
594 | 607 | | |
595 | 608 | | |
596 | | - | |
| 609 | + | |
597 | 610 | | |
598 | 611 | | |
599 | 612 | | |
600 | 613 | | |
601 | 614 | | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
602 | 618 | | |
603 | | - | |
| 619 | + | |
604 | 620 | | |
605 | 621 | | |
606 | 622 | | |
| |||
1056 | 1072 | | |
1057 | 1073 | | |
1058 | 1074 | | |
1059 | | - | |
| 1075 | + | |
1060 | 1076 | | |
1061 | 1077 | | |
1062 | 1078 | | |
| |||
1118 | 1134 | | |
1119 | 1135 | | |
1120 | 1136 | | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
1121 | 1140 | | |
1122 | 1141 | | |
1123 | 1142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
851 | 851 | | |
852 | 852 | | |
853 | 853 | | |
| 854 | + | |
854 | 855 | | |
855 | 856 | | |
856 | 857 | | |
| |||
0 commit comments