Closed
Description
Bit-shifts where the right-hand side is of statically unknown value yield spurious results - e.g.:
#[arduino_hal::entry]
fn main() -> ! {
let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);
let mut serial = arduino_hal::default_serial!(dp, pins, 57600);
let x = 1;
let y = hint::black_box(1);
let val: u64 = x << y;
for b in val.to_le_bytes() {
_ = ufmt::uwrite!(&mut serial, "{} ", b);
}
_ = ufmt::uwriteln!(&mut serial, "");
loop {
//
}
}
... prints:
0 0 0 4 0 0 0 0
For u128 we get something even wilder:
1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0
Smaller types, such as u32, seem to behave correctly:
2 0 0 0
My rough guess lays in the vicinity of AVRShiftExpand::expand()
or compiler-builtins
(ABI mismatch?), but I'm yet to confirm it.
Note that this is mostly an informational report - I'll try to fix this bug;