summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-06-14 12:23:38 +0200
committerGitHub <noreply@github.com>2024-06-14 12:23:38 +0200
commitaebd794d15cfea87a1c7abd711a8b3f7dc3d0a35 (patch)
tree8bfba41f510851ef680dd6b23d5f2f6dd1549457 /tests
parentb7dcdf684c93a9691bc6ce1a7f5a71b56cd04374 (diff)
parenta6907100de23e51ba979ead543fcd5975d62d248 (diff)
Rollup merge of #126426 - RalfJung:dangling-zst-ice, r=oli-obk
const validation: fix ICE on dangling ZST reference Fixes https://github.com/rust-lang/rust/issues/126393 I'm not super happy with this fix but I can't think of a better one. r? `@oli-obk`
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/consts/dangling-alloc-id-ice.rs2
-rw-r--r--tests/ui/consts/dangling-alloc-id-ice.stderr10
-rw-r--r--tests/ui/consts/dangling-zst-ice-issue-126393.rs15
-rw-r--r--tests/ui/consts/dangling-zst-ice-issue-126393.stderr14
4 files changed, 38 insertions, 3 deletions
diff --git a/tests/ui/consts/dangling-alloc-id-ice.rs b/tests/ui/consts/dangling-alloc-id-ice.rs
index 6b07b8b3cc8..76d6f33baf3 100644
--- a/tests/ui/consts/dangling-alloc-id-ice.rs
+++ b/tests/ui/consts/dangling-alloc-id-ice.rs
@@ -10,7 +10,7 @@ union Foo<'a> {
}
const FOO: &() = {
- //~^ ERROR encountered dangling pointer
+ //~^ ERROR it is undefined behavior to use this value
let y = ();
unsafe { Foo { y: &y }.long_live_the_unit }
};
diff --git a/tests/ui/consts/dangling-alloc-id-ice.stderr b/tests/ui/consts/dangling-alloc-id-ice.stderr
index de31acf9fa4..881c0b162ed 100644
--- a/tests/ui/consts/dangling-alloc-id-ice.stderr
+++ b/tests/ui/consts/dangling-alloc-id-ice.stderr
@@ -1,8 +1,14 @@
-error: encountered dangling pointer in final value of constant
+error[E0080]: it is undefined behavior to use this value
--> $DIR/dangling-alloc-id-ice.rs:12:1
|
LL | const FOO: &() = {
- | ^^^^^^^^^^^^^^
+ | ^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (use-after-free)
+ |
+ = 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`.
diff --git a/tests/ui/consts/dangling-zst-ice-issue-126393.rs b/tests/ui/consts/dangling-zst-ice-issue-126393.rs
new file mode 100644
index 00000000000..917aa0572fc
--- /dev/null
+++ b/tests/ui/consts/dangling-zst-ice-issue-126393.rs
@@ -0,0 +1,15 @@
+// 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"
+//@ normalize-stderr-test "HEX_DUMP\s*\n\s*HEX_DUMP" -> "HEX_DUMP"
+
+pub struct Wrapper;
+pub static MAGIC_FFI_REF: &'static Wrapper = unsafe {
+//~^ERROR: it is undefined behavior to use this value
+ std::mem::transmute(&{
+ let y = 42;
+ y
+ })
+};
+
+fn main() {}
diff --git a/tests/ui/consts/dangling-zst-ice-issue-126393.stderr b/tests/ui/consts/dangling-zst-ice-issue-126393.stderr
new file mode 100644
index 00000000000..d32b427f14e
--- /dev/null
+++ b/tests/ui/consts/dangling-zst-ice-issue-126393.stderr
@@ -0,0 +1,14 @@
+error[E0080]: it is undefined behavior to use this value
+ --> $DIR/dangling-zst-ice-issue-126393.rs:7:1
+ |
+LL | pub static MAGIC_FFI_REF: &'static Wrapper = unsafe {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (use-after-free)
+ |
+ = 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`.