Skip to content

Resolve TODOs for MIR to LLVM conversion tests #303

Closed

Description

@uurl

Summary

There are existing TODOs requesting unit test coverage for MIR to LLVM conversion code paths. This issue tracks correcting those TODOs by adding focused regression tests for conversion behavior that is currently implemented but not explicitly covered.

Scope

Add unit tests for:

  • Constant conversion

    • Integer constants preserve their bit pattern.
    • Integer constants lower to signless LLVM integer types.
    • f32 and f64 constants preserve their floating-point attributes.
    • MIR-specific f16 attributes are rewritten to the LLVM half attribute representation.
  • Aggregate conversion

    • Slice construction lowers to the canonical { ptr, len } aggregate layout.
    • Struct construction respects explicit layout slots and skips zero-sized fields.
    • ZST field extraction does not emit llvm.extractvalue.
    • Enum construction uses the declared discriminant value rather than the variant index.
  • Cast conversion

    • Signed integer widening lowers to llvm.sext.
    • Unsigned integer widening lowers to llvm.zext.
    • Integer narrowing lowers to llvm.trunc.
    • Unsigned integer to float lowers to llvm.uitofp.
    • Float to signed integer lowers through the saturating intrinsic.
    • Pointer address exposure lowers to llvm.ptrtoint.

Motivation

These tests make the lowering behavior explicit and protect several nontrivial semantic details:

  • Rust/MIR signedness should not leak incorrectly into lowered LLVM integer constants.
  • Explicit struct layout and padding must be preserved.
  • Zero-sized types should not produce storage-based extract operations.
  • Enum discriminants must use their declared bit-pattern values.
  • Cast lowering must select the correct LLVM operation or intrinsic based on source and destination types.

Acceptance criteria

  • The TODOs for constant, aggregate, and cast conversion tests are resolved.
  • The new tests pass with cargo test.
  • The tests validate observable lowered LLVM operations and attributes rather than only checking that lowering succeeds.

Activity

  1. added
    QoL-improvement
    IR-lowering
    tests
    tracking
    codegen
    on Jun 29, 2026
  2. honeyspoon commented on Jul 24, 2026

    @honeyspoon
    Contributor

    All items in the scope section appear to be covered by tests on main:

    Feature Test Location
    Integer constant bit preservation convert_integer_preserves_bits_and_makes_type_signless constants.rs:242
    f16 attribute conversion convert_f16_constant_rewrites_mir_attr_to_builtin_half_attr constants.rs:312
    f32/f64 constant preservation convert_f32_constant_preserves_float_attr, convert_f64_... constants.rs:255, 283
    Slice construction construct_slice_lowers_to_ptr_len_insert_values aggregate.rs:1578
    Struct ZST field extraction extract_field_from_zst_does_not_emit_extractvalue aggregate.rs:1703
    Enum discriminant values construct_enum_uses_declared_discriminant_not_variant_index aggregate.rs:1766
    Signed widening (sext) int_to_int_signed_widen_lowers_to_s_ext cast.rs:1189
    Unsigned widening (zext) int_to_int_unsigned_widen_lowers_to_z_ext cast.rs:1200
    Integer narrowing (trunc) int_to_int_narrow_lowers_to_trunc cast.rs:1211
    Unsigned int to float (uitofp) int_to_float_unsigned_lowers_to_ui_to_fp cast.rs:1222
    Float to signed int (saturating) float_to_int_signed_lowers_to_saturating_intrinsic_call cast.rs:1233
    Pointer address exposure (ptrtoint) test at cast.rs:1250 cast.rs:1250

    These tests are in crates/mir-lower/src/convert/ops/{constants,aggregate,cast}.rs and validate observable lowered LLVM operations and attributes as described in the acceptance criteria. This issue may be closable.

  3. nihalpasham commented on Sep 3, 2026

    @nihalpasham
    Collaborator

    Every item in the scope table has a test on main (constants.rs, cast.rs, aggregate/{construct,fields,enums}.rs) and no TODO is left in mir-lower. Closing as completed.

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

    IR-loweringQoL-improvementcodegenteststracking

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions