Skip to content

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

Closed

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

  1. 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
  2. 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

  3. added
    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
    on Aug 15, 2020
  4. 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

  5. MSxDOS commented on Mar 5, 2021

    @MSxDOS
    Author

    The example is fixed on nightly, probably by #81451

  6. added a commit that references this issue on Mar 8, 2021
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

      Issue actions