Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
RaphiJS6-13 opened this issue Oct 9, 2020 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@RaphiJS6-13
Copy link

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
@LemonBoy
Copy link
Contributor

LemonBoy commented Oct 9, 2020

[obj] "{rcx}" (obj)

You're shoving an object into a register, you probably want &obj or something like that.

@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Oct 10, 2020
@andrewrk andrewrk added this to the 0.8.0 milestone Oct 10, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
RetroDev256 added a commit to RetroDev256/zig that referenced this issue Sep 9, 2024
RetroDev256 added a commit to RetroDev256/zig that referenced this issue Sep 9, 2024
RetroDev256 added a commit to RetroDev256/zig that referenced this issue Sep 9, 2024
RetroDev256 added a commit to RetroDev256/zig that referenced this issue Sep 9, 2024
RetroDev256 added a commit to RetroDev256/zig that referenced this issue Sep 9, 2024
RetroDev256 added a commit to RetroDev256/zig that referenced this issue Sep 10, 2024
RetroDev256 added a commit to RetroDev256/zig that referenced this issue Sep 10, 2024
RetroDev256 added a commit to RetroDev256/zig that referenced this issue Nov 24, 2024
alexrp pushed a commit to RetroDev256/zig that referenced this issue Feb 5, 2025
RetroDev256 added a commit to RetroDev256/zig that referenced this issue Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
3 participants