This is an automated email from the ASF dual-hosted git repository.

Jefffrey pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new e82873eb1b Fix the u8 shift overflow in the buffer_bit_ops benchmark 
(#11175)
e82873eb1b is described below

commit e82873eb1bccb3619f3879dae4100681f1b81944
Author: Amit Vijapur <[email protected]>
AuthorDate: Wed Sep 23 02:47:01 2026 +0100

    Fix the u8 shift overflow in the buffer_bit_ops benchmark (#11175)
    
    # Which issue does this PR close?
    
    Part of #10952.
    
    # Rationale for this change
    
    Running the benches once under `cargo test --benches` (the check #10952
    asks for) turns up one bench that cannot even start: `buffer_bit_ops`
    panics at line 31 with `attempt to shift left with overflow`.
    `0b01010101 << i` is assigned into a `u8` slot, so the literal infers
    `u8` and the shift overflows for every `i >= 8`. `cargo bench` builds in
    release, where the shift amount is masked and the bench runs, which is
    why it has never shown up.
    
    # What changes are included in this PR?
    
    The two shifts become `wrapping_shl`, which masks the shift amount the
    same way release mode does, so the fixture bytes are identical to what
    the benchmark has been measuring all along (checked for `i` in `0..64`).
    rustfmt split the expression over three lines.
    
    # Are these changes tested?
    
    `cargo test -p arrow --features test_utils --bench buffer_bit_ops`
    panics on `main` and passes here. The byte-identity check was a small
    standalone program comparing the new expression against the masked
    semantics of the old one.
    
    # Are there any user-facing changes?
    
    No.
---
 arrow/benches/buffer_bit_ops.rs | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arrow/benches/buffer_bit_ops.rs b/arrow/benches/buffer_bit_ops.rs
index 2304779c38..dbbd166d60 100644
--- a/arrow/benches/buffer_bit_ops.rs
+++ b/arrow/benches/buffer_bit_ops.rs
@@ -28,7 +28,9 @@ fn create_buffer(size: usize) -> Buffer {
     let mut result = MutableBuffer::new(size).with_bitset(size, false);
 
     for i in 0..size {
-        result.as_slice_mut()[i] = 0b01010101 << i << (i % 4);
+        result.as_slice_mut()[i] = 0b01010101u8
+            .wrapping_shl(i as u32)
+            .wrapping_shl((i % 4) as u32);
     }
 
     result.into()

Reply via email to