Skip to content

malformed extern fn decl containing slice causes segfault rather than error message #22977

Open
@paperdev-code

Description

Zig Version

0.14.0-dev.3286+05d8b565a

Steps to Reproduce and Observed Behavior

given the following code;

//                     v- is bad
extern const bad: fn ([]const u8) void;
pub fn main() void {
    bad();
}

attempt at compilation;

❯ zig run test.zig
Error: nu::shell::terminated_by_signal
└─ mem.sliceAsBytes__anon_19529
  × External command was terminated by a signal
   ╭─[entry #12:1:1]
 1 │ zig run test2.zig
   · ─┬─
   ·  ╰── terminated by SIGSEGV (11)
   ╰────

Expected Behavior

expect the output to be similar to;

//             v- is bad
extern fn bad([]const u8) void;
pub fn main() void {
    bad();
}

which produces;

❯ zig run test2.zig
test2.zig:2:15: error: parameter of type '[]const u8' not allowed in function with calling convention 'x86_64_sysv'
extern fn bad([]const u8) void;
              ^~~~~~~~~~
test2.zig:2:15: note: slices have no guaranteed in-memory representation
referenced by:
    main: test2.zig:4:5
    posixCallMainAndExit: /nix/store/5ijjcxhqcjc96q0pkqrnh97mkxpcqvwg-zig-0.14.0-dev.3286+05d8b565a/lib/std/start.zig:647:22
    4 reference(s) hidden; use '-freference-trace=6' to see all references

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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