Skip to content

assertion referencing builtin from module with different optimize mode in tests #23453

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

Open
xdBronch opened this issue Apr 3, 2025 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@xdBronch
Copy link
Contributor

xdBronch commented Apr 3, 2025

Zig Version

0.15.0-dev.196+e9220525e

Steps to Reproduce and Observed Behavior

// main.zig
const mod = @import("mod");

test {
    _ = mod.builtin;
}
// mod.zig
pub const builtin = @import("builtin");

zig4 test --dep mod -OReleaseFast -Mroot=main.zig -ODebug -Mmod=mod.zig

thread 14213 panic: reached unreachable code
Analyzing mod.zig
    > %2 = import(.none, "builtin") 
      %3 = break_inline(%1, %2)
    For full context, use the command
      zig ast-check -t mod.zig

  in main.zig
    > %8 = field_val(%6, "builtin") 

/home/user/dev/zig/lib/std/debug.zig:546:14: 0x4cfec0d in assert (zig)
    if (!ok) unreachable; // assertion failure
             ^
/home/user/dev/zig/src/Zcu/PerThread.zig:1858:11: 0x51660d8 in semaFile (zig)
    assert(file.zir != null);
          ^
/home/user/dev/zig/src/Zcu/PerThread.zig:575:23: 0x500243a in ensureFileAnalyzed (zig)
    return pt.semaFile(file_index);
                      ^
/home/user/dev/zig/src/Sema.zig:14061:38: 0x5fc0688 in zirImport (zig)
            try pt.ensureFileAnalyzed(result.file_index);
                                     ^
/home/user/dev/zig/src/Sema.zig:1182:64: 0x5b4309c in analyzeBodyInner (zig)
            .import                       => try sema.zirImport(block, inst),
                                                               ^
/home/user/dev/zig/src/Sema.zig:1025:30: 0x573c77e in analyzeInlineBody (zig)
    if (sema.analyzeBodyInner(block, body)) |_| {
                             ^
/home/user/dev/zig/src/Sema.zig:1058:39: 0x536907e in resolveInlineBody (zig)
    return (try sema.analyzeInlineBody(block, body, break_target)) orelse .unreachable_value;
                                      ^
/home/user/dev/zig/src/Zcu/PerThread.zig:1077:58: 0x516949a in analyzeNavVal (zig)
            const result_ref = try sema.resolveInlineBody(&block, value_body, inst_resolved.inst);
                                                         ^
/home/user/dev/zig/src/Zcu/PerThread.zig:941:80: 0x5002983 in ensureNavValUpToDate (zig)
    const invalidate_value: bool, const new_failed: bool = if (pt.analyzeNavVal(nav_id)) |result| res: {
                                                                               ^
/home/user/dev/zig/src/Sema.zig:31763:49: 0x5365c5f in ensureNavResolved (zig)
        .fully => return pt.ensureNavValUpToDate(nav_index),
                                                ^
/home/user/dev/zig/src/Sema.zig:31791:31: 0x60810aa in analyzeNavRefInner (zig)
    try sema.ensureNavResolved(src, orig_nav_index, if (is_ref) .type else .fully);
                              ^
/home/user/dev/zig/src/Sema.zig:31682:44: 0x5f5b7ed in analyzeNavVal (zig)
    const ref = try sema.analyzeNavRefInner(src, nav_index, false);
                                           ^
/home/user/dev/zig/src/Sema.zig:27895:34: 0x649ec53 in namespaceLookupVal (zig)
    return try sema.analyzeNavVal(block, src, nav);
                                 ^
/home/user/dev/zig/src/Sema.zig:27373:56: 0x6499472 in fieldVal (zig)
                        if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(zcu), field_name)) |inst| {
                                                       ^
/home/user/dev/zig/src/Sema.zig:10136:25: 0x5fbd9fa in zirFieldVal (zig)
    return sema.fieldVal(block, src, object, field_name, field_name_src);
                        ^
/home/user/dev/zig/src/Sema.zig:1177:66: 0x5b42f6c in analyzeBodyInner (zig)
            .field_val                    => try sema.zirFieldVal(block, inst),
                                                                 ^
/home/user/dev/zig/src/Sema.zig:1007:26: 0x5f52b41 in analyzeFnBody (zig)
    sema.analyzeBodyInner(block, body) catch |err| switch (err) {
                         ^
/home/user/dev/zig/src/Zcu/PerThread.zig:2708:23: 0x5af28d3 in analyzeFnBodyInner (zig)
    sema.analyzeFnBody(&inner_block, fn_info.body) catch |err| switch (err) {
                      ^
/home/user/dev/zig/src/Zcu/PerThread.zig:1625:40: 0x571a247 in analyzeFuncBody (zig)
    var air = try pt.analyzeFnBodyInner(func_index);
                                       ^
/home/user/dev/zig/src/Zcu/PerThread.zig:1545:66: 0x53583e6 in ensureFuncBodyUpToDate (zig)
    const ies_outdated, const new_failed = if (pt.analyzeFuncBody(func_index)) |result|
                                                                 ^
/home/user/dev/zig/src/Compilation.zig:4055:38: 0x51641a6 in processOneJob (zig)
            pt.ensureFuncBodyUpToDate(func) catch |err| switch (err) {
                                     ^

Expected Behavior

no crash!

@xdBronch xdBronch added the bug Observed behavior contradicts documented or intended behavior label Apr 3, 2025
@alexrp alexrp added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Apr 3, 2025
@alexrp alexrp added this to the 0.15.0 milestone Apr 3, 2025
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