Skip to content

by-val struct init containing OPV field emits AIR which breaks self-hosted x86_64 #23902

@mlugg

Description

@mlugg

Zig Version

0.15.0-dev.552+bc2f7c754

Steps to Reproduce and Observed Behavior

const S = struct { x: u32, y: enum { opv } };
export fn foo(x: u32) void {
    other(.{ .x = x, .y = .opv });
}
fn other(_: S) void {}
$ zig build-obj repro.zig -fno-llvm
error(x86_64_encoder): no encoding found for: none mov m256 imm8s none none
repro.zig:2:8: error: emit MIR failed: InvalidInstruction (Zig compiler bug)
export fn foo(x: u32) void {
~~~~~~~^~~~~~~~~~~~~~~~~~~

Note that on a different compiler build this crashes the x86_64 backend instead of emitting a nice error, so it's possible it could crash in some cases.

Expected Behavior

Successful compilation, which does happen with the LLVM backend.

@jacobly0 reports that this happens because the aggregate_init instruction contains the OPV field .y = .opv, which the x86_64 backend does not expect (whereas the LLVM backend does expect it). This is one of many bugs where AIR instructions corresponding to OPV values are wrongly emitted (related: #22419).

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-x86_6464-bit x86backend-self-hostedbugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions