zig icon indicating copy to clipboard operation
zig copied to clipboard

x86_64 regression: `@bitCast` to bool vectors produces incorrect results

Open IntegratedQuantum opened this issue 1 month ago • 3 comments

Zig Version

0.16.0-dev.1415+db622f14c (worked in 0.15.2)

Steps to Reproduce and Observed Behavior

Run the following Zig code that bitcasts a u3 to a bool vector:

const std = @import("std");

pub fn main() !void {
	var value: u3 = 7;
	_ = &value;
	std.log.err("{any}", .{@as(@Vector(3, bool), @bitCast(value))});
}

Observe how it produces false in newer versions with the x86_64 backend:

$ zig-debug run test.zig -fno-llvm
error: { false, false, false }

Expected Behavior

It should return true since all bits are set, this works in the llvm backend as well as the 0.15.2 x86_64 backend:

$ zig-debug run test.zig -fllvm
error: { true, true, true }
$ ~/Downloads/zig-x86_64-linux-0.15.2/zig run test.zig -fno-llvm
error: { true, true, true }

IntegratedQuantum avatar Nov 22 '25 12:11 IntegratedQuantum

Note: it works if value is const instead of var. Also the same behavior occurs when bitcasting to a vector of u1 instead of bool

aqrit avatar Nov 22 '25 13:11 aqrit

I think this is a duplicate of #24179

Vexu avatar Nov 22 '25 23:11 Vexu

Not a duplicate, sounds like a real regression. This might be my fault (I may have broken some Legalize logic)

mlugg avatar Nov 22 '25 23:11 mlugg