From 4664b8b0281bf742f993bec48bd99e0a0e411f1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Horstmann?= Date: Fri, 9 Feb 2024 18:43:14 +0100 Subject: [PATCH 1/3] Use fallback for bigint division when running with miri --- arrow-buffer/src/bigint/div.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arrow-buffer/src/bigint/div.rs b/arrow-buffer/src/bigint/div.rs index e1b2ed4f8aa5..8a75dad0ffd8 100644 --- a/arrow-buffer/src/bigint/div.rs +++ b/arrow-buffer/src/bigint/div.rs @@ -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; @@ -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); From 07576182de462850ce9c68844e62f8125699cc3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Horstmann?= Date: Fri, 9 Feb 2024 18:44:14 +0100 Subject: [PATCH 2/3] Avoid warning about strict provenance when running with miri --- arrow-buffer/src/buffer/mutable.rs | 10 +++++++++- arrow-buffer/src/lib.rs | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/arrow-buffer/src/buffer/mutable.rs b/arrow-buffer/src/buffer/mutable.rs index 69c986cc1056..72ea9f1090f1 100644 --- a/arrow-buffer/src/buffer/mutable.rs +++ b/arrow-buffer/src/buffer/mutable.rs @@ -480,7 +480,15 @@ fn dangling_ptr() -> NonNull { // 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 Extend for MutableBuffer { diff --git a/arrow-buffer/src/lib.rs b/arrow-buffer/src/lib.rs index cbcdb979e693..612897af9bed 100644 --- a/arrow-buffer/src/lib.rs +++ b/arrow-buffer/src/lib.rs @@ -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::*; From 7b807262c265116cbc471bc30a1330175c6a8e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Horstmann?= Date: Fri, 9 Feb 2024 18:44:28 +0100 Subject: [PATCH 3/3] Enable miri in ci --- .github/workflows/miri.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/miri.sh b/.github/workflows/miri.sh index 44485cacce64..86be2100ee67 100755 --- a/.github/workflows/miri.sh +++ b/.github/workflows/miri.sh @@ -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 \ No newline at end of file