Skip to content

Commit

Permalink
Fix ICE test
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Apr 16, 2024
1 parent d761b18 commit a3d987f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
17 changes: 0 additions & 17 deletions tests/crashes/122548.rs

This file was deleted.

21 changes: 21 additions & 0 deletions tests/ui/statics/mutable_memory_validation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//issue: rust-lang/rust#122548

// Strip out raw byte dumps to make comparison platform-independent:
//@ normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
//@ normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*A(LLOC)?[0-9]+(\+[a-z0-9]+)?(<imm>)?─*╼ )+ *│.*" -> "HEX_DUMP"

#![feature(const_mut_refs)]
#![feature(const_refs_to_static)]

use std::cell::UnsafeCell;

struct Meh {
x: &'static UnsafeCell<i32>,
}

const MUH: Meh = Meh { x: unsafe { &mut *(&READONLY as *const _ as *mut _) } };
//~^ ERROR: it is undefined behavior to use this value

static READONLY: i32 = 0;

pub fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/statics/mutable_memory_validation.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0080]: it is undefined behavior to use this value
--> $DIR/mutable_memory_validation.rs:16:1
|
LL | const MUH: Meh = Meh { x: unsafe { &mut *(&READONLY as *const _ as *mut _) } };
| ^^^^^^^^^^^^^^ constructing invalid value at .x.<deref>: encountered `UnsafeCell` in read-only memory
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
HEX_DUMP
}

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.

0 comments on commit a3d987f

Please sign in to comment.