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

zig test empty.zig --error-limit 0 segfaults #22281

Open
wooster0 opened this issue Dec 21, 2024 · 1 comment
Open

zig test empty.zig --error-limit 0 segfaults #22281

wooster0 opened this issue Dec 21, 2024 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@wooster0
Copy link
Contributor

Zig Version

0.14.0-dev.2545+e2e363361

Steps to Reproduce and Observed Behavior

$ touch empty.zig
$ zig test empty.zig --error-limit 0
Segmentation fault

Expected Behavior

A compile error.
This doesn't seem to happen when not compiling with LLVM. I think the problem is errorSetBits() in

return o.builder.intType(o.pt.zcu.errorSetBits());
returning 0 which doesn't seem to be allowed for intType:
assert(bits > 0);

@wooster0 wooster0 added the bug Observed behavior contradicts documented or intended behavior label Dec 21, 2024
@Rexicon226
Copy link
Contributor

To add, there's an assertion fail whenever the --error-limit specified is too small.

zig test empty_file.zig --error-limit [1,63]
/Users/david/Code/zig/lib/std/debug.zig:405:14: 0x10d512157 in assert (zig)
    if (!ok) unreachable; // assertion failure
             ^
/Users/david/Code/zig/src/codegen/llvm/Builder.zig:10973:15: 0x10d9907af in bigIntConstAssumeCapacity (zig)
        assert(value.fitsInTwosComp(.unsigned, bits));
              ^
/Users/david/Code/zig/src/codegen/llvm/Builder.zig:9123:42: 0x10d751e07 in bigIntConst (zig)
    return self.bigIntConstAssumeCapacity(ty, value);
                                         ^
/Users/david/Code/zig/src/codegen/llvm/Builder.zig:9112:28: 0x10d5a4f6b in intConst__anon_66547 (zig)
    return self.bigIntConst(ty, std.math.big.int.Mutable.init(&limbs, int_value).toConst());
                           ^
/Users/david/Code/zig/src/codegen/llvm.zig:3959:56: 0x10d8ea9af in lowerValue (zig)
                const llvm_int = try o.builder.intConst(try o.errorIntType(), int);
                                                       ^
/Users/david/Code/zig/src/codegen/llvm.zig:3979:58: 0x10d8eada3 in lowerValue (zig)
                const llvm_error_value = try o.lowerValue(err_val);
                                                         ^
/Users/david/Code/zig/src/codegen/llvm.zig:5027:42: 0x10ea0b76f in resolveValue (zig)
        const llvm_val = try o.lowerValue(val.toIntern());
                                         ^
/Users/david/Code/zig/src/codegen/llvm.zig:5018:47: 0x10ea
        const llvm_val = try self.resolveValue((try self.air.value(inst, self.ng.object.pt)).?);
                                              ^
/Users/david/Code/zig/src/codegen/llvm.zig:5813:49: 0x10ea70883 in airRet (zig)
            const operand = try self.resolveInst(un_op);
                                                ^
/Users/david/Code/zig/src/codegen/llvm.zig:5324:55: 0x10e64f0e7 in genBody (zig)
                .ret_safe        => return self.airRet(inst, true),
                                                      ^

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