#Stuck with LLVM broken module with heavy comptime

1 messages · Page 1 of 1 (latest)

boreal jolt
#

No matter what I change inside this code (in the limits of the comptime framework provided for a function), it ends up crashing the compiler. Can anyone tell me how to make it compile and not crash? I will report this but I would like a workaround in the meanwhile.
Steps to reproduce (the executable that's crashing is not that big):

git clone https://github.com/davidgm94/rise.git
cd rise
git switch llvm-broken-module
zig build
#
Basic Block in function 'user.programs.init.main.main' does not have terminator!
label %Block
Basic Block in function 'user.syscall__anon_2331' does not have terminator!
label %Case2
Basic Block in function 'user.syscall__anon_2400' does not have terminator!
label %Case2
Basic Block in function 'user.syscall__anon_2417' does not have terminator!
label %Case2
#

main suspect:

    const options = rise.syscall.Options{
        .rise = .{
            .type = capability_type,
            .command = @enumToInt(capability_command),
        },
    };

    const raw_arguments: [6]usize = switch (@typeInfo(@TypeOf(arguments))) {
        .Pointer => |pointer| switch (pointer.size) {
            .Slice => .{0} ** 4 ++ [2]usize{ @ptrToInt(arguments.ptr), arguments.len },
            else => @compileError("Unexpected pointer type"),
        },
        .Void => .{0} ** 6,
        else => |_| @compileError("t: " ++ @typeName(@TypeOf(arguments))),
    };

    const result = arch.syscall(options, raw_arguments);
    const ThisErrorSet = capabilities.ErrorSet(capability_type, capability_command);
    const error_enum = @intToEnum(ThisErrorSet.Enum, result.rise.first.@"error");
    return switch (error_enum) {
        .ok => switch (capabilities.Result(capability_type, capability_command)) {
            noreturn => unreachable,
            else => while (true) {},
        },
        inline else => |comptime_error_enum| @field(ThisErrorSet.Error, @tagName(comptime_error_enum)),
    };
}
sharp sage
#

Not sure if this will fix it, but here's one idea:

Try looking for places where there's a switch with each prong returning a value, thus making the switch of type noreturn.
Try giving it an else prong with else => unreachable, or otherwise reworking it so that you can do unreachable; at the end of the function. 🤔

boreal jolt
#

thanks, I will try to move stuff to see if I can make it work 🙂