AST codegen: `true as i32` sign-extends the i1, giving -1

Open Beginner friendly
#467 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
rust
Domain
compilers

Research direction

Start at the AST cast lowering responsible for bool-to-integer conversions, then inspect the differential suite and its inline mlir! coverage. Verify the example true as i32 through both --legacy-codegen and flat paths; done means both produce 1 and the differential comparison agrees.

Written by the indexing model from the issue text.

Description

bug codegen good first issue

The oracle lowers a bool-to-integer cast with a sign extension, so true as i32 is -1. The flat path gives 1.

fn main() -> i32 { let b = true; return b as i32; }
path exit
--legacy-codegen 255
flat 1

Found while writing a differential test for inline mlir! blocks: a returns : bool block cast to i32 disagreed between the paths for this reason alone. The test avoids the cast. The oracle is the parity reference for the differential suite, so any flat program that casts a bool is currently compared against the wrong number.

Fix: arith.extui for an i1 source in the AST cast lowering.

Dominant language
Rust
Stars
14
Forks
2
Avg merge
12h 9m
Merged PRs (30d)
78

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vx-lang/Vx

All issues in vx-lang/Vx

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.