Skip to content

stage2 crash in astgen due to errors getting ignored #8920

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
g-w1 opened this issue May 28, 2021 · 0 comments
Closed

stage2 crash in astgen due to errors getting ignored #8920

g-w1 opened this issue May 28, 2021 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@g-w1
Copy link
Contributor

g-w1 commented May 28, 2021

This crashes astgen:

fn ChaChaLetsCrashAstGen() type {
    return struct {
        pub fn AHHHHHHHHHHHHHHHHHHHHHHHHHHHHH() void {
            const bruh = 1091290;
            const bruh = 1091290;
        }
    };
}
❯ ./zig ast-check test.zig                                                                                                                                                                                                                   
thread 4039 panic: reached unreachable code
/home/jacob/dev/zig/src/AstGen.zig:2137:27: 0xee4458 in AstGen.genDefers (zig1)
            .namespace => unreachable,
                          ^
/home/jacob/dev/zig/src/AstGen.zig:6013:22: 0xdba900 in AstGen.ret (zig1)
        try genDefers(gz, &astgen.fn_block.?.base, scope, .none);
                     ^
/home/jacob/dev/zig/src/AstGen.zig:628:33: 0xc98c9b in AstGen.expr (zig1)
        .@"return" => return ret(gz, scope, node),
                                ^
/home/jacob/dev/zig/src/AstGen.zig:1821:41: 0xeeece4 in AstGen.unusedResultExpr (zig1)
    const maybe_unused_result = try expr(gz, scope, .none, statement);
                                        ^
/home/jacob/dev/zig/src/AstGen.zig:1809:41: 0xee8a7b in AstGen.blockExprStmts (zig1)
            else => try unusedResultExpr(gz, scope, statement),
                                        ^
/home/jacob/dev/zig/src/AstGen.zig:1646:23: 0xdc1b7d in AstGen.blockExpr (zig1)
    try blockExprStmts(gz, scope, block_node, statements);
                      ^
/home/jacob/dev/zig/src/AstGen.zig:718:33: 0xc9d009 in AstGen.expr (zig1)
                return blockExpr(gz, scope, rl, node, statements[0..1]);
                                ^
/home/jacob/dev/zig/src/AstGen.zig:2925:25: 0xc9245d in AstGen.fnDecl (zig1)
            _ = try expr(&fn_gz, params_scope, .none, body_node);
                        ^
/home/jacob/dev/zig/src/AstGen.zig:3390:38: 0xb5541c in AstGen.structDeclInner (zig1)
                        astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProtoSimple(&params, fn_proto)) catch |err| switch (err) {The fact that you have shadowing is not the point. I think a lot of other errors could have worked, shadowing is just the first one I thought of.


                                     ^
/home/jacob/dev/zig/src/AstGen.zig:107:31: 0x9a8f15 in AstGen.generate (zig1)
    if (AstGen.structDeclInner(
                              ^
/home/jacob/dev/zig/src/main.zig:3678:35: 0x91ed82 in main.cmdAstCheck (zig1)
    file.zir = try AstGen.generate(gpa, file.tree);
                                  ^
/home/jacob/dev/zig/src/main.zig:243:27: 0x8a39c6 in main.mainArgs (zig1)
        return cmdAstCheck(gpa, arena, cmd_args);
                          ^
/home/jacob/dev/zig/src/stage1.zig:45:24: 0x8a20f9 in main (zig1)
        stage2.mainArgs(gpa, arena, args) catch unreachable;
                       ^
Aborted (core dumped)

Segfaults on tarball zig, or prints stack trace on debug zig

The fact that you have shadowing is not the point. I think a lot of other errors could have worked, shadowing is just the first one I thought of.

Ok, so why does this trigger a bug, heres what I think

.fn_proto_simple => {
    var params: [1]ast.Node.Index = undefined;
    astgen.fnDecl(gz, &namespace.base, &wip_decls, member_node, body, tree.fnProtoSimple(&params, fn_proto)) catch |err| switch (err) {
        error.OutOfMemory => return error.OutOfMemory,
        error.AnalysisFail => {},
    };
    continue;
},

When we have this code, it ignores error.AnalysisFail. This is fine for most things, but when you have a function that returns a
struct, it kinda breaks down. It keeps trying to do analyze to the struct, since, it effectively ignored the error. Then it does
weird stuff to invalid zir, which is a no-no.

This is blocking my unused vars pr. I can't really think of a fix for this.

@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels May 28, 2021
@andrewrk andrewrk added this to the 0.8.0 milestone May 28, 2021
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 frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

2 participants