Skip to content

Commit 2e6c7b9

Browse files
authored
Enable running arrow-array and arrow-arith with miri and avoid strict 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
1 parent cc48095 commit 2e6c7b9

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

.github/workflows/miri.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ cargo miri test -p arrow-buffer
1616
cargo miri test -p arrow-data --features ffi
1717
cargo miri test -p arrow-schema --features ffi
1818
cargo miri test -p arrow-ord
19-
# inline assembly not supported by Miri
20-
# cargo miri test -p arrow-array
21-
# cargo miri test -p arrow-arith
19+
cargo miri test -p arrow-array
20+
cargo miri test -p arrow-arith

arrow-buffer/src/bigint/div.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ fn div_rem_word(hi: u64, lo: u64, divisor: u64) -> (u64, u64) {
189189

190190
// LLVM fails to use the div instruction as it is not able to prove
191191
// that hi < divisor, and therefore the result will fit into 64-bits
192-
#[cfg(target_arch = "x86_64")]
192+
#[cfg(all(target_arch = "x86_64", not(miri)))]
193193
unsafe {
194194
let mut quot = lo;
195195
let mut rem = hi;
@@ -202,7 +202,7 @@ fn div_rem_word(hi: u64, lo: u64, divisor: u64) -> (u64, u64) {
202202
);
203203
(quot, rem)
204204
}
205-
#[cfg(not(target_arch = "x86_64"))]
205+
#[cfg(any(not(target_arch = "x86_64"), miri))]
206206
{
207207
let x = (u128::from(hi) << 64) + u128::from(lo);
208208
let y = u128::from(divisor);

arrow-buffer/src/buffer/mutable.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,15 @@ fn dangling_ptr() -> NonNull<u8> {
480480
// SAFETY: ALIGNMENT is a non-zero usize which is then casted
481481
// to a *mut T. Therefore, `ptr` is not null and the conditions for
482482
// calling new_unchecked() are respected.
483-
unsafe { NonNull::new_unchecked(ALIGNMENT as *mut u8) }
483+
#[cfg(miri)]
484+
{
485+
// Since miri implies a nightly rust version we can use the unstable strict_provenance feature
486+
unsafe { NonNull::new_unchecked(std::ptr::invalid_mut(ALIGNMENT)) }
487+
}
488+
#[cfg(not(miri))]
489+
{
490+
unsafe { NonNull::new_unchecked(ALIGNMENT as *mut u8) }
491+
}
484492
}
485493

486494
impl<A: ArrowNativeType> Extend<A> for MutableBuffer {

arrow-buffer/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
//! Low-level buffer abstractions for [Apache Arrow Rust](https://docs.rs/arrow)
1919
20+
// used by [`buffer::mutable::dangling_ptr`]
21+
#![cfg_attr(miri, feature(strict_provenance))]
22+
2023
pub mod alloc;
2124
pub mod buffer;
2225
pub use buffer::*;

0 commit comments

Comments
 (0)