Skip to content

Unnecessary assertion inside while i < *::MAX loop #75546

Closed
@MSxDOS

Description

@MSxDOS
pub fn test() {
    let mut i = 1u32;
    while i < u32::MAX {
        assert_ne!(i, 0, "No way...");
        i += 1;
    }
}

https://godbolt.org/z/oY5ra8

The assertion disappears when comparing against a non-MAX value for a given type, or with mir-opt-level 2 and above.

Activity

added
A-mir-optArea: MIR optimizations
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
I-slowIssue: Problems and improvements with respect to performance of generated code.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Aug 15, 2020
tesuji

tesuji commented on Aug 15, 2020

@tesuji
Contributor

Another LLVM issue, probably because of wrapping around integers:
C version: https://godbolt.org/z/688dhv
@rustbot modify labels: A-LLVM

added
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
on Aug 15, 2020
MSxDOS

MSxDOS commented on Oct 11, 2020

@MSxDOS
Author

The assertion disappears ... with mir-opt-level 2 and above

Now it also requires -Zunsound-mir-opts

MSxDOS

MSxDOS commented on Mar 5, 2021

@MSxDOS
Author

The example is fixed on nightly, probably by #81451

added a commit that references this issue on Mar 8, 2021

Rollup merge of rust-lang#82874 - erikdesjardins:cgtests, r=nagisa

a5035c9
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

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-mir-optArea: MIR optimizationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @tesuji@MSxDOS@rustbot

        Issue actions

          Unnecessary assertion inside `while i < *::MAX` loop · Issue #75546 · rust-lang/rust