Skip to content

Coercion from slice of non-const pointer to slice of const pointer, during param passing, causes "broken LLVM module found: Call parameter type does not match function signature!" #10603

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

Closed
jumpnbrownweasel opened this issue Jan 16, 2022 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@jumpnbrownweasel
Copy link
Contributor

Zig Version

zig-linux-x86_64-0.9.0 and zig-linux-x86_64-0.10.0-dev.290+3901b6fb0

Steps to Reproduce

Here's a narrowed down case that fails:

const std = @import("std");

pub fn main() !void {
    var x: usize = 123;
    var array: [1]*usize = .{&x};
    f(array[0..1]);
}

fn f(slice: []*const usize) void {
    std.log.info("{}", .{slice.len});
}

// Does not fail if I remove const from the parameter in f.
//
// Does not fail if I first assign to a local in main and pass the local to f.
//
//  const slice: []*const usize = array[0..1];
//  f(slice);

Expected Behavior

Expected coercion from slice of non-const pointers to slice of const pointers to work. This does work during assignment, just not parameter passing.

Actual Behavior

Output:

broken LLVM module found: Call parameter type does not match funct
ion signature!
  %3 = bitcast %"[]*const usize"* %1 to %"[]*usize"*, !dbg !17223
 %"[]*const usize"*  call fastcc void @f(%"[]*usize"* %3), !dbg !1
7224

This is a bug in the Zig compiler.thread 153925 panic:
Unable to dump stack trace: debug info stripped
Aborted (core dumped)

I get this result on the latest master build and the 0.9.0 build from the download page:

zig-linux-x86_64-0.10.0-dev.290+3901b6fb0
zig-linux-x86_64-0.9.0

@jumpnbrownweasel jumpnbrownweasel added the bug Observed behavior contradicts documented or intended behavior label Jan 16, 2022
@jumpnbrownweasel
Copy link
Contributor Author

jumpnbrownweasel commented Jan 16, 2022

I have found several issues on github with a similar error, but not exactly the same. The closest seems to be 7908 since it also has a bitcast issue. But unlike 7908, here the bitcast issue is specifically related to coercion from a slice of pointers to a slice of const pointers, when the coercion is via parameter passing.

@jumpnbrownweasel
Copy link
Contributor Author

Since this coercion works during assignment, a workaround is to assign to a local, then pass the local to the function.

@jumpnbrownweasel jumpnbrownweasel changed the title Coercion from slice of non-const pointer to slice of pointer, during param passing, causes "broken LLVM module found: Call parameter type does not match function signature!" Coercion from slice of non-const pointer to slice of const pointer, during param passing, causes "broken LLVM module found: Call parameter type does not match function signature!" Jan 16, 2022
@Vexu
Copy link
Member

Vexu commented Jan 16, 2022

Duplicate of #4907, #4904, #6147.

@Vexu Vexu closed this as completed Jan 16, 2022
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
Projects
None yet
Development

No branches or pull requests

2 participants