Skip to content

SsaRangePropagation propagates range information from optional asserts #163779

Closed

Description

@saethlin
#[inline(never)]
pub fn on_arith_overflow(a: u32, b: u32) -> bool {
    let _ = std::ops::Add::add(a, b);
    a.overflowing_add(b).1
}

Currently compiles, with optimizations enabled and overflow-checks off (the default release profile or -O):

bb0: {
    _3 = AddWithOverflow(copy _1, copy _2);
    assert(!copy (_3.1: bool), "attempt to compute `{} + {}`, which would overflow", copy _1, copy _2) -> [success: bb1, unwind continue];
}

bb1: {
    _0 = const false;
    return;
}

or in LLVM:

start:
  ret i1 false

Found via LLM

Activity

  1. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    A-mir-optArea: MIR optimizations
    I-miscompileIssue: Correct Rust code lowers to incorrect machine code
    on Oct 5, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Oct 5, 2026
  3. self-assigned this
    on Oct 5, 2026
  4. theemathas commented on Oct 5, 2026

    @theemathas
    Contributor

    As per zulip, this regressed in #150309, which shipped in 1.95.0.

    cc @dianqk, @cjgillot (author and reviewer of regressing PR)

  5. added
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 5, 2026
  6. ChayimFriedman2 commented on Oct 5, 2026

    @ChayimFriedman2
    Contributor

    Note that this does not reproduce with + before the overflowing_add(), you need to call the Add::add() method. Which explains why this wasn't found, and also that this is probably related to #[rustc_inherit_overflow_checks].

  7. added
    P-highHigh priority
    and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Oct 5, 2026
  8. added 2 commits that reference this issue on Oct 5, 2026
  9. added
    A-mir-opt-GVNArea: MIR opt Global Value Numbering (GVN)
    and removed
    A-mir-opt-GVNArea: MIR opt Global Value Numbering (GVN)
    on Oct 5, 2026
  10. added a commit that references this issue on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-mir-optArea: MIR optimizationsC-bugCategory: This is a bug.I-miscompileIssue: Correct Rust code lowers to incorrect machine codeP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions