-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
arch-x86_6464-bit x8664-bit x86backend-self-hostedbugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviormiscompilationThe compiler reports success but produces semantically incorrect code.The compiler reports success but produces semantically incorrect code.
Milestone
Description
Zig Version
0.14.0-dev.616+ab4eeb770
Steps to Reproduce and Observed Behavior
I know the x86 backend isn't passing all tests yet anyway, so I'm not sure if documenting these sorts of bugs is useful or not--if not let me know! I'm just very excited about how fast my project compiles under this backend haha.
Here's a reproduction of the problem:
const std = @import("std");
pub fn main() void {
// Create a packed struct
const Packed = packed struct {
should_be_true: bool,
};
// Create a variable and then set it to zero. If we set it immediately to zero the bug
// doesn't occur, presumably because the bitwise math can then be trivially optimized out.
var zero: u32 = 5;
zero -= 5;
std.debug.assert(zero == 0); // <-- All good
// This bitwise math results in true as expected
const should_be_true = (zero & 1) != 1;
std.debug.assert(should_be_true); // <-- All good
// Store the same bitwise math in this packed struct. Now the value is true instead of
// false.
const result: Packed = .{ .should_be_true = (zero & 1) != 1 };
std.debug.assert(result.should_be_true); // <-- This fails
}
Expected Behavior
I expected the result of the bitwise operation to be the same in both cases.
lin72h
Metadata
Metadata
Assignees
Labels
arch-x86_6464-bit x8664-bit x86backend-self-hostedbugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviormiscompilationThe compiler reports success but produces semantically incorrect code.The compiler reports success but produces semantically incorrect code.