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

Closed
@jumpnbrownweasel

Description

@jumpnbrownweasel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions