Skip to content

x86_64 backend "emit MIR failed: CannotEncode" with comptime local in naked function #24621

@190n

Description

@190n

Zig Version

0.15.0-dev.1271+bb2984673

Steps to Reproduce and Observed Behavior

repro.zig:

const saved_registers = [_][]const u8{ "rbx", "rbp", "r12", "r13", "r14", "r15" };

export fn entry() callconv(.naked) noreturn {
    inline for (saved_registers) |register| {
        asm volatile ("pushq %%" ++ register);
    }
}
$ zig build-obj -target x86_64-linux-gnu repro.zig
repro.zig:3:8: error: emit MIR failed: CannotEncode (Zig compiler bug)
export fn entry() callconv(.naked) noreturn {
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The particular assembly doesn't seem to matter.

Expected Behavior

no error:

$ zig build-obj -target x86_64-linux-gnu -fllvm repro.zig
$ llvm-objdump -d repro.o

repro.o:        file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <entry>:
       0: 53                            pushq   %rbx
       1: 55                            pushq   %rbp
       2: 41 54                         pushq   %r12
       4: 41 55                         pushq   %r13
       6: 41 56                         pushq   %r14
       8: 41 57                         pushq   %r15
       a: 0f 0b                         ud2

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-x86_6464-bit x86backend-self-hostedbugObserved behavior contradicts documented or intended behaviordebug-infoDebug information of binary generated by Zig is not as expected.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions