From 821d23b32930c68e36a5a246e734fa3a655970d9 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 23 Apr 2024 13:32:30 +0000 Subject: Ensure miri only uses fallback bodies that have manually been vetted to preserve all UB that the native intrinsic would have --- src/tools/miri/tests/fail/intrinsic_fallback_checks_ub.rs | 14 ++++++++++++++ .../miri/tests/fail/intrinsic_fallback_checks_ub.stderr | 14 ++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/tools/miri/tests/fail/intrinsic_fallback_checks_ub.rs create mode 100644 src/tools/miri/tests/fail/intrinsic_fallback_checks_ub.stderr (limited to 'src/tools/miri/tests') diff --git a/src/tools/miri/tests/fail/intrinsic_fallback_checks_ub.rs b/src/tools/miri/tests/fail/intrinsic_fallback_checks_ub.rs new file mode 100644 index 00000000000..93c9d3d7814 --- /dev/null +++ b/src/tools/miri/tests/fail/intrinsic_fallback_checks_ub.rs @@ -0,0 +1,14 @@ +#![feature(rustc_attrs, effects)] + +#[rustc_intrinsic] +#[rustc_nounwind] +#[rustc_do_not_const_check] +#[inline] +pub const fn ptr_guaranteed_cmp(ptr: *const T, other: *const T) -> u8 { + (ptr == other) as u8 +} + +fn main() { + ptr_guaranteed_cmp::<()>(std::ptr::null(), std::ptr::null()); + //~^ ERROR: can only use intrinsic fallback bodies that check UB. +} diff --git a/src/tools/miri/tests/fail/intrinsic_fallback_checks_ub.stderr b/src/tools/miri/tests/fail/intrinsic_fallback_checks_ub.stderr new file mode 100644 index 00000000000..b37e05c62f9 --- /dev/null +++ b/src/tools/miri/tests/fail/intrinsic_fallback_checks_ub.stderr @@ -0,0 +1,14 @@ +error: unsupported operation: miri can only use intrinsic fallback bodies that check UB. After verifying that `ptr_guaranteed_cmp` does so, add the `#[miri::intrinsic_fallback_checks_ub]` attribute to it; also ping @rust-lang/miri when you do that + --> $DIR/intrinsic_fallback_checks_ub.rs:LL:CC + | +LL | ptr_guaranteed_cmp::<()>(std::ptr::null(), std::ptr::null()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ miri can only use intrinsic fallback bodies that check UB. After verifying that `ptr_guaranteed_cmp` does so, add the `#[miri::intrinsic_fallback_checks_ub]` attribute to it; also ping @rust-lang/miri when you do that + | + = 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: BACKTRACE: + = note: inside `main` at $DIR/intrinsic_fallback_checks_ub.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to 1 previous error + -- cgit 1.4.1-3-g733a5