Skip to content

x86 backend encoding failure concatenating slice #25485

Description

@AndrewKraevskii

Zig Version

0.16.0-dev.604+e932ab003

Steps to Reproduce and Observed Behavior

test {
    const slice = &.{};
    const typed_slice: []u8 = slice;
    _ = typed_slice ++ &[1]u8{0};
}
$ zig test repro.zig -target x86_64-linux
error(x86_64_encoder): no encoding found for: none mov r64 m128 none none
repro.zig:1:1: error: emit MIR failed: InvalidInstruction (Zig compiler bug)
test {
^~~~

Expected Behavior

I expect it to compile or give error about types not matching. This compiles on llvm backend.

Activity

  1. added
    bugObserved behavior contradicts documented or intended behavior
    on Oct 5, 2025
  2. mlugg commented on Oct 11, 2025

    @mlugg
    Member

    cc @jacobly0; except, uh, looking at it, this could well be a frontend OPV bug...

  3. changed the title [-]Untyped slice compiler bug.[/-] [+]x86 backend encoding failure [/+] on Oct 11, 2025
  4. changed the title [-]x86 backend encoding failure [/-] [+]x86 backend encoding failure concatenating `[]void`[/+] on Oct 11, 2025
  5. AndrewKraevskii commented on Oct 11, 2025

    @AndrewKraevskii
    ContributorAuthor

    @mlugg its not related to void. It would happen with any type I just chose void since its simpler. Maybe I shouldn't have

  6. changed the title [-]x86 backend encoding failure concatenating `[]void`[/-] [+]x86 backend encoding failure concatenating slice[/+] on Oct 11, 2025
  7. mlugg commented on Oct 11, 2025

    @mlugg
    Member

    Ah, okay, in that case it's more likely to be a backend bug.

  8. added
    frontendTokenization, parsing, AstGen, Sema, and Liveness.
    and removed on Oct 11, 2025
  9. jacobly0 commented on Oct 11, 2025

    @jacobly0
    Member

    Pretty sure the original repro had some additional OPV bugs.

  10. xdBronch commented on Oct 11, 2025

    @xdBronch
    Contributor

    very many bugs in this

    a.zig:4:30: error: unable to evaluate comptime expression
        _ = comptime typed_slice ++ &[1]u8{0};
                     ~~~~~~~~~~~~^~~~~~~~~~~~
    a.zig:4:18: note: operation is runtime due to this operand
        _ = comptime typed_slice ++ &[1]u8{0};
                     ^~~~~~~~~~~
    a.zig:4:9: note: 'comptime' keyword forces comptime evaluation
        _ = comptime typed_slice ++ &[1]u8{0};
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

    this one i believe is because the empty tuple -> slice conversion gives the pointer an integer representation https://github.com/ziglang/zig/blob/95242cc43132c7b6aeb2f7171389075859aba008/src/Sema.zig#L28797-L28800

  11. AndrewKraevskii commented on Oct 11, 2025

    @AndrewKraevskii
    ContributorAuthor

    very many bugs in this

    a.zig:4:30: error: unable to evaluate comptime expression
        _ = comptime typed_slice ++ &[1]u8{0};
                     ~~~~~~~~~~~~^~~~~~~~~~~~
    a.zig:4:18: note: operation is runtime due to this operand
        _ = comptime typed_slice ++ &[1]u8{0};
                     ^~~~~~~~~~~
    a.zig:4:9: note: 'comptime' keyword forces comptime evaluation
        _ = comptime typed_slice ++ &[1]u8{0};
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

    this one i believe is because the empty tuple -> slice conversion gives the pointer an integer representation https://github.com/ziglang/zig/blob/95242cc43132c7b6aeb2f7171389075859aba008/src/Sema.zig#L28797-L28800

    This is the error I got originally. I tried to simplify reproduction but error changed to other at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions