Skip to content

Typed MIR validator accepts a field projection through a reference with no deref #2269

Closed

Description

@ehartford

Spec: §2.3 / D65 (one owner per fact; post-Sema invalid MIR is a compiler bug the validators must name).

On the D111 stack (before 9dabfbe) MIR lowered for p in ps.iter() over a Vec[Pair] (Pair: not Copy, no drop glue) as a view loop while Sema bound p by value. The body read p.a as the place _7.a where _7 held a &Pair. Codegen emitted getelementptr inbounds nuw ptr, ptr %1, i32 0, i32 0 and LLVM's SROA crashed (EXC_BAD_ACCESS in StructType::getTypeAtIndex).

Every tool said ok on that MIR: --validate-all, analyze audit:resolution, analyze audit:mir.

Repro (fails only on a compiler with the lowering bug; fixed in 9dabfbe):

type Pair { a: i64, b: i64 }
fn main:
    var ps: Vec[Pair] = Vec.new()
    for p in ps.iter():
        if p.a != 7:
            return
    let x = 1
    print(x)

Cause in the validator: mir_validate_place_type (src/MirCore.w) returns a place's stored place_sema_types entry when present, so the structural walk in mir_validate_place_prefix_type, which would find a PK_FIELD applied to a TY_REF base, never runs.

Expected: the typed validator compares a place's stored type with the type its projections derive from the local, and refuses a PK_FIELD/PK_INDEX applied directly to a reference or pointer (a missing PK_DEREF). The same check would also have caught a binding's local typed T receiving a &T value.

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced in source. The typed validator walks a field projection through mir_validate_struct_field_type (src/MirCore.w:3639), which peels a reference or raw pointer and keeps going (:3642-3644: if tk == TypeKind.TY_REF or tk == TypeKind.TY_PTR: … return mir_validate_struct_field_type(mir_mod, inner, field_sym)). A field projection through a &Pair with no PK_DEREF is therefore accepted. The D65 field-place audit compares bases with references peeled too.

    post-release: validator hardening; the lowering defect that exposed it is fixed.

  2. added this to the post-v0.16.0 milestone on Oct 28, 2026
  3. added a commit that references this issue on Nov 11, 2026
  4. ehartford commented on Nov 11, 2026

    @ehartford
    ContributorAuthor

    Fixed in #3255 (6a905fd). Root cause: the typed validator read each place's declared type, so a field projection straight off a reference local looked well-typed. mir_validate_scalar_field_projection now refuses it: "projects field N of a reference with no dereference". Covered by the negative case in mir_structural_validator_test.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

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions