Skip to content

x86_64 backend miscomp #20113

Open
Open
@Rexicon226

Description

@Rexicon226

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-x86_6464-bit x86backend-self-hostedbugObserved behavior contradicts documented or intended behaviormiscompilationThe compiler reports success but produces semantically incorrect code.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions