forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#87248 - RalfJung:ctfe-partial-overwrite, r=ol…
…i-obk CTFE: throw unsupported error when partially overwriting a pointer Currently, during CTFE, when a write to memory would overwrite parts of a pointer, we make the remaining parts of that pointer "uninitialized". This is probably not what users expect, so if this ever happens they will be quite confused about why some of the data just vanishes for seemingly no good reason. So I propose we change this to abort CTFE when that happens, to at last avoid silently doing the wrong thing. Cc rust-lang#87184 Our CTFE test suite still seems to pass. However, we should probably crater this, and I want to do some tests with Miri as well.
- Loading branch information
Showing
6 changed files
with
104 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Test for the behavior described in <https://github.com/rust-lang/rust/issues/87184>. | ||
#![feature(const_mut_refs, const_raw_ptr_deref)] | ||
|
||
const PARTIAL_OVERWRITE: () = { | ||
let mut p = &42; | ||
unsafe { | ||
let ptr: *mut _ = &mut p; | ||
*(ptr as *mut u8) = 123; //~ ERROR any use of this value | ||
//~| unable to overwrite parts of a pointer | ||
//~| WARN previously accepted | ||
} | ||
let x = *p; | ||
}; | ||
|
||
fn main() {} |
20 changes: 20 additions & 0 deletions
20
src/test/ui/consts/const-eval/partial_ptr_overwrite.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: any use of this value will cause an error | ||
--> $DIR/partial_ptr_overwrite.rs:8:9 | ||
| | ||
LL | / const PARTIAL_OVERWRITE: () = { | ||
LL | | let mut p = &42; | ||
LL | | unsafe { | ||
LL | | let ptr: *mut _ = &mut p; | ||
LL | | *(ptr as *mut u8) = 123; | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^ unable to overwrite parts of a pointer in memory at alloc4 | ||
... | | ||
LL | | let x = *p; | ||
LL | | }; | ||
| |__- | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800> | ||
|
||
error: aborting due to previous error | ||
|