about summary refs log tree commit diff
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2025-01-22 01:00:59 -0800
committerScott McMurray <scottmcm@users.noreply.github.com>2025-01-31 22:29:09 -0800
commit61150a80f5d4fffea74ee9dabc991219813c744e (patch)
tree0990b8bdc65ae6c3f2c3217974240f7d49070dc3
parent4ee1602eab2cdc88172d4a98f927613ab64b4cf0 (diff)
downloadrust-61150a80f5d4fffea74ee9dabc991219813c744e.tar.gz
rust-61150a80f5d4fffea74ee9dabc991219813c744e.zip
PR feedback
-rw-r--r--library/core/src/intrinsics/fallback.rs12
-rw-r--r--library/core/src/intrinsics/mod.rs3
-rw-r--r--library/core/src/num/uint_macros.rs2
-rw-r--r--src/tools/miri/tests/fail/intrinsics/disjoint_bitor.rs5
-rw-r--r--src/tools/miri/tests/fail/intrinsics/disjoint_bitor.stderr15
5 files changed, 28 insertions, 9 deletions
diff --git a/library/core/src/intrinsics/fallback.rs b/library/core/src/intrinsics/fallback.rs
index dca211eba80..eec5c4d646d 100644
--- a/library/core/src/intrinsics/fallback.rs
+++ b/library/core/src/intrinsics/fallback.rs
@@ -114,13 +114,8 @@ impl const CarryingMulAdd for i128 {
 #[const_trait]
 #[rustc_const_unstable(feature = "core_intrinsics_fallbacks", issue = "none")]
 pub trait DisjointBitOr: Copy + 'static {
-    /// This is always just `assume((self & other) == 0); self | other`.
-    ///
-    /// It's essential that the assume is there so that this is sufficient to
-    /// specify the UB for MIRI, rather than it needing to re-implement it.
-    ///
-    /// # Safety
-    /// See [`super::disjoint_bitor`].
+    /// See [`super::disjoint_bitor`]; we just need the trait indirection to handle
+    /// different types since calling intrinsics with generics doesn't work.
     unsafe fn disjoint_bitor(self, other: Self) -> Self;
 }
 macro_rules! zero {
@@ -135,8 +130,11 @@ macro_rules! impl_disjoint_bitor {
     ($($t:ident,)+) => {$(
         #[rustc_const_unstable(feature = "core_intrinsics_fallbacks", issue = "none")]
         impl const DisjointBitOr for $t {
+            #[cfg_attr(miri, track_caller)]
             #[inline]
             unsafe fn disjoint_bitor(self, other: Self) -> Self {
+                // Note that the assume here is required for UB detection in Miri!
+
                 // SAFETY: our precondition is that there are no bits in common,
                 // so this is just telling that to the backend.
                 unsafe { super::assume((self & other) == zero!($t)) };
diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs
index 37d9b522314..c505eb95013 100644
--- a/library/core/src/intrinsics/mod.rs
+++ b/library/core/src/intrinsics/mod.rs
@@ -3257,7 +3257,8 @@ pub const fn three_way_compare<T: Copy>(_lhs: T, _rhss: T) -> crate::cmp::Orderi
 #[rustc_const_unstable(feature = "disjoint_bitor", issue = "135758")]
 #[rustc_nounwind]
 #[cfg_attr(not(bootstrap), rustc_intrinsic)]
-#[miri::intrinsic_fallback_is_spec] // the fallbacks all `assume` to tell MIRI
+#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
+#[miri::intrinsic_fallback_is_spec] // the fallbacks all `assume` to tell Miri
 pub const unsafe fn disjoint_bitor<T: ~const fallback::DisjointBitOr>(a: T, b: T) -> T {
     // SAFETY: same preconditions as this function.
     unsafe { fallback::DisjointBitOr::disjoint_bitor(a, b) }
diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs
index c909ab56ac8..f2d41fd93d5 100644
--- a/library/core/src/num/uint_macros.rs
+++ b/library/core/src/num/uint_macros.rs
@@ -1213,7 +1213,7 @@ macro_rules! uint_impl {
         ///
         /// # Safety
         ///
-        /// Requires that `(self | other) == 0`, otherwise it's immediate UB.
+        /// Requires that `(self & other) == 0`, otherwise it's immediate UB.
         ///
         /// Equivalently, requires that `(self | other) == (self + other)`.
         #[unstable(feature = "disjoint_bitor", issue = "135758")]
diff --git a/src/tools/miri/tests/fail/intrinsics/disjoint_bitor.rs b/src/tools/miri/tests/fail/intrinsics/disjoint_bitor.rs
new file mode 100644
index 00000000000..a7127143330
--- /dev/null
+++ b/src/tools/miri/tests/fail/intrinsics/disjoint_bitor.rs
@@ -0,0 +1,5 @@
+#![feature(core_intrinsics)]
+fn main() {
+    // one bit in common
+    unsafe { std::intrinsics::disjoint_bitor(0b01101001_u8, 0b10001110) }; //~ ERROR: Undefined Behavior
+}
diff --git a/src/tools/miri/tests/fail/intrinsics/disjoint_bitor.stderr b/src/tools/miri/tests/fail/intrinsics/disjoint_bitor.stderr
new file mode 100644
index 00000000000..82502953118
--- /dev/null
+++ b/src/tools/miri/tests/fail/intrinsics/disjoint_bitor.stderr
@@ -0,0 +1,15 @@
+error: Undefined Behavior: `assume` called with `false`
+  --> tests/fail/intrinsics/disjoint_bitor.rs:LL:CC
+   |
+LL |     unsafe { std::intrinsics::disjoint_bitor(0b01101001_u8, 0b10001110) };
+   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `assume` called with `false`
+   |
+   = 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
+   = note: BACKTRACE:
+   = note: inside `main` at tests/fail/intrinsics/disjoint_bitor.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
+