Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x86_64 backend miscomp #20113

Open
Rexicon226 opened this issue May 29, 2024 · 0 comments
Open

x86_64 backend miscomp #20113

Rexicon226 opened this issue May 29, 2024 · 0 comments
Labels
arch-x86_64 64-bit x86 backend-self-hosted bug Observed behavior contradicts documented or intended behavior miscompilation The compiler reports success but produces semantically incorrect code.
Milestone

Comments

@Rexicon226
Copy link
Contributor

Zig Version

master

Steps to Reproduce and Observed Behavior

const std = @import("std");

const Data = packed struct {
    rd: u5,
    rl: bool,
};

pub const Operand = union(enum) {
    reg: enum {
        t0, // commenting this out fixes the issue
        s0,
    },
    barrier: enum(u4) {
        rl,
    },
};

pub fn main() !void {
    var rd: Operand = .{ .reg = .s0 };
    var rl: Operand = .{ .barrier = .rl };
    _ = &rd;
    _ = &rl;

    const ret: Data = .{
        .rd = @intFromEnum(rd.reg),
        .rl = rl.barrier == .rl,
    };

    std.debug.print("ret: {}, {}\n", .{ ret.rl, rl.barrier == .rl });
}

output:

ret: false, true

Expected Behavior

when commenting out the t0 enum and/or compiling with LLVM, expected output is:

ret: true, true
@Rexicon226 Rexicon226 added the bug Observed behavior contradicts documented or intended behavior label May 29, 2024
@Vexu Vexu added this to the 0.14.0 milestone May 29, 2024
@jacobly0 jacobly0 added the miscompilation The compiler reports success but produces semantically incorrect code. label Feb 13, 2025
@jacobly0 jacobly0 modified the milestones: 0.14.0, 0.14.1, 0.15.0 Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-x86_64 64-bit x86 backend-self-hosted bug Observed behavior contradicts documented or intended behavior miscompilation The compiler reports success but produces semantically incorrect code.
Projects
None yet
Development

No branches or pull requests

3 participants