Skip to content

Commit ae46ade

Browse files
committed
PR feedback
1 parent 68e4c3c commit ae46ade

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

library/core/src/intrinsics/fallback.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,8 @@ impl const CarryingMulAdd for i128 {
114114
#[const_trait]
115115
#[rustc_const_unstable(feature = "core_intrinsics_fallbacks", issue = "none")]
116116
pub trait DisjointBitOr: Copy + 'static {
117-
/// This is always just `assume((self & other) == 0); self | other`.
118-
///
119-
/// It's essential that the assume is there so that this is sufficient to
120-
/// specify the UB for MIRI, rather than it needing to re-implement it.
121-
///
122-
/// # Safety
123-
/// See [`super::disjoint_bitor`].
117+
/// See [`super::disjoint_bitor`]; we just need the trait indirection to handle
118+
/// different types since calling intrinsics with generics doesn't work.
124119
unsafe fn disjoint_bitor(self, other: Self) -> Self;
125120
}
126121
macro_rules! zero {
@@ -135,8 +130,11 @@ macro_rules! impl_disjoint_bitor {
135130
($($t:ident,)+) => {$(
136131
#[rustc_const_unstable(feature = "core_intrinsics_fallbacks", issue = "none")]
137132
impl const DisjointBitOr for $t {
133+
#[cfg_attr(miri, track_caller)]
138134
#[inline]
139135
unsafe fn disjoint_bitor(self, other: Self) -> Self {
136+
// Note that the assume here is required for UB detection in Miri!
137+
140138
// SAFETY: our precondition is that there are no bits in common,
141139
// so this is just telling that to the backend.
142140
unsafe { super::assume((self & other) == zero!($t)) };

library/core/src/intrinsics/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3257,7 +3257,8 @@ pub const fn three_way_compare<T: Copy>(_lhs: T, _rhss: T) -> crate::cmp::Orderi
32573257
#[rustc_const_unstable(feature = "disjoint_bitor", issue = "135758")]
32583258
#[rustc_nounwind]
32593259
#[cfg_attr(not(bootstrap), rustc_intrinsic)]
3260-
#[miri::intrinsic_fallback_is_spec] // the fallbacks all `assume` to tell MIRI
3260+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
3261+
#[miri::intrinsic_fallback_is_spec] // the fallbacks all `assume` to tell Miri
32613262
pub const unsafe fn disjoint_bitor<T: ~const fallback::DisjointBitOr>(a: T, b: T) -> T {
32623263
// SAFETY: same preconditions as this function.
32633264
unsafe { fallback::DisjointBitOr::disjoint_bitor(a, b) }

library/core/src/num/uint_macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ macro_rules! uint_impl {
12131213
///
12141214
/// # Safety
12151215
///
1216-
/// Requires that `(self | other) == 0`, otherwise it's immediate UB.
1216+
/// Requires that `(self & other) == 0`, otherwise it's immediate UB.
12171217
///
12181218
/// Equivalently, requires that `(self | other) == (self + other)`.
12191219
#[unstable(feature = "disjoint_bitor", issue = "135758")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![feature(core_intrinsics)]
2+
fn main() {
3+
// one bit in common
4+
unsafe { std::intrinsics::disjoint_bitor(0b01101001_u8, 0b10001110) }; //~ ERROR: Undefined Behavior
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: Undefined Behavior: `assume` called with `false`
2+
--> tests/fail/intrinsics/disjoint_bitor.rs:LL:CC
3+
|
4+
LL | unsafe { std::intrinsics::disjoint_bitor(0b01101001_u8, 0b10001110) };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `assume` called with `false`
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `main` at tests/fail/intrinsics/disjoint_bitor.rs:LL:CC
11+
12+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+
error: aborting due to 1 previous error
15+

0 commit comments

Comments
 (0)