Skip to content

broken LLVM module found: Call parameter type does not match function signature! #6624

Open
@RaphiJS6-13

Description

@RaphiJS6-13

I was trying to use inline assembly to access struct fields via their pointer offsets:

const std = @import("std");
pub fn HalfSmartPointer(comptime T: type) type {
    const allocator = std.heap.page_allocator;
    const MAX_REF_COUNT_SIZE = usize;
    return struct {
        // lots of code
    };
}

const X = struct {
    x: HalfSmartPointer(i32),
    y: u32,
};

pub fn main() void {
    var foo = HalfSmartPointer(i32).new(2);
    defer foo.end_scope();

    var x = X {.x = foo, .y = 3};
    const offset: usize = @sizeOf(HalfSmartPointer(i32)); // the offset of the field `y`
    std.debug.warn("{}\n", .{
        asm volatile("addq %[offset], %[x]\nmovq (%[x]), %[output]" 
            : [output] "={rbx}" (-> u32)
            : [offset] "{rdx}" (offset), [x] "{rcx}" (x) 
        )
    });

}

When I compiled it, this happened:

sapphire@Raphi-Spoerri:~/Projects$ zig build-exe main.zig
broken LLVM module found: Call parameter type does not match function signature!
  %x = alloca %X, align 8
 %X = type { %"HalfSmartPointer(i32)", i32 }  %5 = call i32 asm sideeffect "addq $1, $2\0Amovq ($2), $0", "={rbx},{rdx},{rcx}"(i64 32, %X* %x), !dbg !15318
This is a bug in the Zig compiler.
Unable to dump stack trace: debug info stripped
Aborted (core dumped)

A more minimal code that reproduces the bug:

const X = struct {
    x: u64,
};

pub fn main() void {
    var obj = X {.x = 1};
    _ = asm volatile("movq %[obj], %[ret]" 
        : [ret] "={rbx}" (-> u64)
        : [obj] "{rcx}" (obj) 
    );
}

Version

sapphire@Raphi-Spoerri:~/Projects$ zig version
0.6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorstage1The process of building from source via WebAssembly and the C backend.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions