Skip to content

Commit

Permalink
Enable running arrow-array and arrow-arith with miri and avoid strict…
Browse files Browse the repository at this point in the history
… provenance warning (#5387)

* Use fallback for bigint division when running with miri

* Avoid warning about strict provenance when running with miri

* Enable miri in ci
  • Loading branch information
jhorstmann authored Feb 18, 2024
1 parent cc48095 commit 2e6c7b9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/miri.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ cargo miri test -p arrow-buffer
cargo miri test -p arrow-data --features ffi
cargo miri test -p arrow-schema --features ffi
cargo miri test -p arrow-ord
# inline assembly not supported by Miri
# cargo miri test -p arrow-array
# cargo miri test -p arrow-arith
cargo miri test -p arrow-array
cargo miri test -p arrow-arith
4 changes: 2 additions & 2 deletions arrow-buffer/src/bigint/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fn div_rem_word(hi: u64, lo: u64, divisor: u64) -> (u64, u64) {

// LLVM fails to use the div instruction as it is not able to prove
// that hi < divisor, and therefore the result will fit into 64-bits
#[cfg(target_arch = "x86_64")]
#[cfg(all(target_arch = "x86_64", not(miri)))]
unsafe {
let mut quot = lo;
let mut rem = hi;
Expand All @@ -202,7 +202,7 @@ fn div_rem_word(hi: u64, lo: u64, divisor: u64) -> (u64, u64) {
);
(quot, rem)
}
#[cfg(not(target_arch = "x86_64"))]
#[cfg(any(not(target_arch = "x86_64"), miri))]
{
let x = (u128::from(hi) << 64) + u128::from(lo);
let y = u128::from(divisor);
Expand Down
10 changes: 9 additions & 1 deletion arrow-buffer/src/buffer/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,15 @@ fn dangling_ptr() -> NonNull<u8> {
// SAFETY: ALIGNMENT is a non-zero usize which is then casted
// to a *mut T. Therefore, `ptr` is not null and the conditions for
// calling new_unchecked() are respected.
unsafe { NonNull::new_unchecked(ALIGNMENT as *mut u8) }
#[cfg(miri)]
{
// Since miri implies a nightly rust version we can use the unstable strict_provenance feature
unsafe { NonNull::new_unchecked(std::ptr::invalid_mut(ALIGNMENT)) }
}
#[cfg(not(miri))]
{
unsafe { NonNull::new_unchecked(ALIGNMENT as *mut u8) }
}
}

impl<A: ArrowNativeType> Extend<A> for MutableBuffer {
Expand Down
3 changes: 3 additions & 0 deletions arrow-buffer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

//! Low-level buffer abstractions for [Apache Arrow Rust](https://docs.rs/arrow)

// used by [`buffer::mutable::dangling_ptr`]
#![cfg_attr(miri, feature(strict_provenance))]

pub mod alloc;
pub mod buffer;
pub use buffer::*;
Expand Down

0 comments on commit 2e6c7b9

Please sign in to comment.