Skip to content

Codegen: an Option bound out of a match on an element view, compared with Some(2), is lowered as a pointer-niche compare (icmp of {i32,[1 x i64]} with i32 0) #3057

Closed

Description

@ehartford

Found writing the #3047 Gap 2 fixture; reproduces on main's installed compiler (afbdbb133).

enum Spec:
    Scalar(i64)
    Slice(Option[i64], Option[i64], Option[i64])
    Dots
fn check(specs: &[Spec]):
    match specs[0]:
        .Slice(start, stop, step) =>
            assert(start == Some(2))
            assert(stop == Some(5))
            assert(step == None)
        _ => panic("slice")
fn main:
    let xs = [Spec.Slice(Some(2), Some(5), None), Spec.Dots]
    check(xs[0..])
Both operands to ICmp instruction are not of the same type!
  %26 = icmp eq { i32, [1 x i64] } %25, i32 0
===== INVALID LLVM FUNCTION check =====

specs[0] is an element view (&Spec), so the pattern binds start as a view of the payload (D22 §3.8); the == beside Some(2) / None then takes Sema's option-pointer path (the Option[&T] niche: compare with null), while the value is the Option[i64] aggregate. The same bindings read through start.unwrap() == 2, match start: Some(v) => and step.is_none() compile and run. The D65 class (#2385 is the None == cousin): with analyze repro.w audit:resolution's operand-type check should name the comparison, and --dump-typed the binding's recorded type; the fixture spec_ss11_7_multi_index_and_dispatch.w reads its slice bounds through unwrap()/is_none() until this is fixed.

Activity

  1. added
    bug
    crash
    on Nov 7, 2026
  2. added 2 commits that reference this issue on Nov 7, 2026
  3. ehartford commented on Nov 11, 2026

    @ehartford
    ContributorAuthor

    Merged to main ae20d89 (#3248): MirLower gave a bare None the reference's type when the other operand was a view; it now takes the viewed Option's. audit:resolution named the operand before and reports violations=0 after. Fixture test/behavior/behav_3057_option_view_compared_with_none.w.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcrash

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions