Skip to content

Sema: invalid air when pointer casting from optional slice #22417

@jacobly0

Description

@jacobly0
fn foo(x: ?[]const u8) [*]const u8 {
    return @ptrCast(x);
}
comptime {
    _ = &foo;
}
$ zig build-obj repro.zig --verbose-air
# Begin Function AIR: repro.foo:
# Total AIR+Liveness bytes: 215B
# AIR Instructions:         7 (63B)
# AIR Extra Data:           10 (40B)
# Liveness tomb_bits:       8B
# Liveness Extra Data:      0 (0B)
# Liveness special table:   0 (0B)
  %0 = arg(?[]const u8, "x")
  %1!= dbg_stmt(2:12)
  %2 = optional_payload(?[]const u8, %0!)
  %3 = slice_ptr([*]const u8, %2!)
  %4 = bitcast([*]const u8, %3!)
  %5!= dbg_stmt(2:5)
  %6!= ret_safe(%4!)
# End Function AIR: repro.foo

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

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions