Zig Version
0.13.0-dev.211+6a65561e3
Steps to Reproduce and Observed Behaviour
Compile and run example program with zig run shr_vec_ov_comptime_rhs.zig
shr_vec_ov_comptime_rhs.zig:
pub fn main() void {
var v: @Vector(4, u32) = @splat(1);
const pc_before: u16 = @reduce(.Add, @popCount(v));
v = @shrExact(v, @splat(1));
const pc_after: u16 = @reduce(.Add, @popCount(v));
if (pc_after != pc_before) {
unreachable;
}
}
Output:
zig run shr_vec_ov_comptime_rhs.zig
thread 9474 panic: reached unreachable code
~/.local/share/test/shr_vec_ov_comptime_rhs.zig:11:9: 0x10344c5 in main (shr_vec_ov_comptime_rhs)
unreachable;
^
~/.local/src/zig-linux-x86_64-0.13.0-dev.211+6a65561e3/lib/std/start.zig:514:22: 0x1033c19 in posixCallMainAndExit (shr_vec_ov_comptime_rhs)
root.main();
^
~/.local/src/zig-linux-x86_64-0.13.0-dev.211+6a65561e3/lib/std/start.zig:266:5: 0x1033781 in _start (shr_vec_ov_comptime_rhs)
asm volatile (switch (native_arch) {
^
???:?:?: 0x0 in ??? (???)
Expected Behaviour
Compile and run example program with zig run shr_vec_ov_runtime_rhs.zig
shr_vec_ov_runtime_rhs.zig:
var rhs: @Vector(4, u5) = @splat(1);
pub fn main() void {
var v: @Vector(4, u32) = @splat(1);
const pc_before: u16 = @reduce(.Add, @popCount(v));
v = @shrExact(v, rhs);
const pc_after: u16 = @reduce(.Add, @popCount(v));
if (pc_after != pc_before) {
unreachable;
}
}
Output:
zig run shr_vec_ov_runtime_rhs.zig
thread 9946 panic: right shift overflowed bits
~/.local/share/test/shr_vec_ov_runtime_rhs.zig:8:5: 0x10344ea in main (shr_vec_ov_runtime_rhs)
v = @shrExact(v, rhs);
^
~/.local/src/zig-linux-x86_64-0.13.0-dev.211+6a65561e3/lib/std/start.zig:514:22: 0x1033c19 in posixCallMainAndExit (shr_vec_ov_runtime_rhs)
root.main();
^
~/.local/src/zig-linux-x86_64-0.13.0-dev.211+6a65561e3/lib/std/start.zig:266:5: 0x1033781 in _start (shr_vec_ov_runtime_rhs)
asm volatile (switch (native_arch) {
^
???:?:?: 0x0 in ??? (???)
The only difference between the two examples is that the shift amount in the latter example is runtime-known. The outcomes should be the same.
Zig Version
0.13.0-dev.211+6a65561e3
Steps to Reproduce and Observed Behaviour
Compile and run example program with
zig run shr_vec_ov_comptime_rhs.zigshr_vec_ov_comptime_rhs.zig:Output:
Expected Behaviour
Compile and run example program with
zig run shr_vec_ov_runtime_rhs.zigshr_vec_ov_runtime_rhs.zig:Output:
The only difference between the two examples is that the shift amount in the latter example is runtime-known. The outcomes should be the same.