about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-08-03 17:29:08 +0200
committerGitHub <noreply@github.com>2023-08-03 17:29:08 +0200
commit00dcc7b97c6bd97743e8399e107b2f46d8425343 (patch)
tree0d17ace20a40b8e2e6fca3e094a58e83659945b8 /src
parent51d1dacdc20d83cc4573d4f6226f422a3e725672 (diff)
parent7767cbb3b0b332fd0a46e347ea7f68f20109d768 (diff)
downloadrust-00dcc7b97c6bd97743e8399e107b2f46d8425343.tar.gz
rust-00dcc7b97c6bd97743e8399e107b2f46d8425343.zip
Rollup merge of #114372 - RalfJung:const-pointer-as-int, r=oli-obk
const validation: point at where we found a pointer but expected an integer

Instead of validation just printing "unable to turn pointer into bytes", make this a regular validation error that says where in the value the bad pointer was found. Also distinguish "expected integer, got pointer" from "expected pointer, got partial pointer or mix of pointers".

To avoid duplicating things too much I refactored the diagnostics for validity a bit, so that "got uninit, expected X" and "got pointer, expected X" can share the "X" part. Also all the errors emitted for validation are now grouped under `const_eval_validation` so that they are in a single group in the ftl file.

r? `@oli-obk`
Diffstat (limited to 'src')
-rw-r--r--src/tools/miri/src/diagnostics.rs4
-rw-r--r--src/tools/miri/tests/fail/validity/uninit_float.stderr4
-rw-r--r--src/tools/miri/tests/fail/validity/uninit_integer.stderr4
3 files changed, 7 insertions, 5 deletions
diff --git a/src/tools/miri/src/diagnostics.rs b/src/tools/miri/src/diagnostics.rs
index 8d9901807ec..6bd4be91e51 100644
--- a/src/tools/miri/src/diagnostics.rs
+++ b/src/tools/miri/src/diagnostics.rs
@@ -273,6 +273,8 @@ pub fn report_error<'tcx, 'mir>(
     } else {
         #[rustfmt::skip]
         let title = match e.kind() {
+            UndefinedBehavior(UndefinedBehaviorInfo::ValidationError(e)) if matches!(e.kind, ValidationErrorKind::PointerAsInt { .. } | ValidationErrorKind::PartialPointer) =>
+                bug!("This validation error should be impossible in Miri: {:?}", e.kind),
             UndefinedBehavior(_) =>
                 "Undefined Behavior",
             ResourceExhaustion(_) =>
@@ -377,7 +379,7 @@ pub fn report_error<'tcx, 'mir>(
     if let Some((alloc_id, access)) = extra {
         eprintln!(
             "Uninitialized memory occurred at {alloc_id:?}{range:?}, in this allocation:",
-            range = access.uninit,
+            range = access.bad,
         );
         eprintln!("{:?}", ecx.dump_alloc(alloc_id));
     }
diff --git a/src/tools/miri/tests/fail/validity/uninit_float.stderr b/src/tools/miri/tests/fail/validity/uninit_float.stderr
index 677a0fc5570..e95e3b18128 100644
--- a/src/tools/miri/tests/fail/validity/uninit_float.stderr
+++ b/src/tools/miri/tests/fail/validity/uninit_float.stderr
@@ -1,8 +1,8 @@
-error: Undefined Behavior: constructing invalid value at .value[0]: encountered uninitialized bytes
+error: Undefined Behavior: constructing invalid value at .value[0]: encountered uninitialized memory, but expected a floating point number
   --> $DIR/uninit_float.rs:LL:CC
    |
 LL |     let _val: [f32; 1] = unsafe { std::mem::uninitialized() };
-   |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .value[0]: encountered uninitialized bytes
+   |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .value[0]: encountered uninitialized memory, but expected a floating point number
    |
    = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
    = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
diff --git a/src/tools/miri/tests/fail/validity/uninit_integer.stderr b/src/tools/miri/tests/fail/validity/uninit_integer.stderr
index a9ac2a6dc67..2156886cd71 100644
--- a/src/tools/miri/tests/fail/validity/uninit_integer.stderr
+++ b/src/tools/miri/tests/fail/validity/uninit_integer.stderr
@@ -1,8 +1,8 @@
-error: Undefined Behavior: constructing invalid value at .value[0]: encountered uninitialized bytes
+error: Undefined Behavior: constructing invalid value at .value[0]: encountered uninitialized memory, but expected an integer
   --> $DIR/uninit_integer.rs:LL:CC
    |
 LL |     let _val = unsafe { std::mem::MaybeUninit::<[usize; 1]>::uninit().assume_init() };
-   |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .value[0]: encountered uninitialized bytes
+   |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .value[0]: encountered uninitialized memory, but expected an integer
    |
    = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
    = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information