Skip to content

Sema: null unwrap with large saturating left shift amount #23034

@jacobly0

Description

@jacobly0
comptime {
    @compileLog(0 <<| (1 << 64));
}
$ zig build-obj repro.zig
thread 593935 panic: attempt to use null value
Analyzing repro.zig
      %2 = typeof_log2_int_type(@one) node_offset:2:24 to :2:25
      %3 = int(64)
      %4 = as_shift_operand(%2, %3) node_offset:2:29 to :2:31
      %5 = shl(@one, %4) node_offset:2:24 to :2:31
    > %6 = shl_sat(@zero, %5) node_offset:2:17 to :2:32
      %7 = extended(compile_log(%6)) node_offset:2:5 to :2:33
      %8 = ensure_result_used(%7) node_offset:2:5 to :2:33
      %9 = break_inline(%1, @void_value)
    For full context, use the command
      zig ast-check -t repro.zig


Unwind error at address `:0x14ad81f` (error.AddressOutOfRange), trace may be incomplete

src/Value.zig:251:36: 0x1ebe036 in toUnsignedInt (main.zig)
    return getUnsignedInt(val, zcu).?;
                                   ^
src/Value.zig:2554:52: 0x2689ae8 in shlScalar (main.zig)
    const shift: usize = @intCast(rhs.toUnsignedInt(zcu));
                                                   ^
src/Value.zig:2545:21: 0x268a7f5 in shl (main.zig)
    return shlScalar(lhs, rhs, ty, allocator, pt);
                    ^
src/Sema.zig:14236:28: 0x268fe1d in zirShl (main.zig)
            try lhs_val.shl(rhs_val, lhs_ty, sema.arena, pt)
                           ^
src/Sema.zig:1319:42: 0x221a205 in analyzeBodyInner (main.zig)
            .shl_sat   => try sema.zirShl(block, inst, .shl_sat),
                                         ^
src/Sema.zig:1024:30: 0x1e7f6c9 in analyzeInlineBody (main.zig)
    if (sema.analyzeBodyInner(block, body)) |_| {
                             ^
src/Sema.zig:1057:39: 0x1bf37af in resolveInlineBody (main.zig)
    return (try sema.analyzeInlineBody(block, body, break_target)) orelse .unreachable_value;
                                      ^
src/Zcu/PerThread.zig:860:50: 0x1e4a67c in analyzeComptimeUnit (main.zig)
    const result_ref = try sema.resolveInlineBody(&block, value_body, inst_resolved.inst);
                                                 ^
src/Zcu/PerThread.zig:764:34: 0x1bdba0c in ensureComptimeUnitUpToDate (main.zig)
    return pt.analyzeComptimeUnit(cu_id) catch |err| switch (err) {
                                 ^
src/Compilation.zig:4059:67: 0x19bbdb4 in processOneJob (main.zig)
                .@"comptime" => |cu| pt.ensureComptimeUnitUpToDate(cu),
                                                                  ^
src/Compilation.zig:3981:30: 0x18907d4 in performAllTheWorkInner (main.zig)
            try processOneJob(@intFromEnum(Zcu.PerThread.Id.main), comp, job);
                             ^
src/Compilation.zig:3721:36: 0x1718b3c in performAllTheWork (main.zig)
    try comp.performAllTheWorkInner(main_progress_node);
                                   ^
src/Compilation.zig:2333:31: 0x15ee4ea in update (main.zig)
    try comp.performAllTheWork(main_progress_node);
                              ^
src/main.zig:4514:20: 0x16379d8 in updateModule (main.zig)
    try comp.update(prog_node);
                   ^
src/main.zig:3704:21: 0x165c1b1 in buildOutputType (main.zig)
        updateModule(comp, color, root_prog_node) catch |err| switch (err) {
                    ^
src/main.zig:277:31: 0x168efa8 in mainArgs (main.zig)
        return buildOutputType(gpa, arena, args, .{ .build = .Obj });
                              ^
src/main.zig:212:20: 0x159d990 in main (main.zig)
    return mainArgs(gpa, arena, args);
                   ^
lib/std/start.zig:656:37: 0x159b3ee in main (std.zig)
            const result = root.main() catch |err| {
                                    ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions