Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MSxDOS opened this issue Aug 15, 2020 · 3 comments
Closed

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

MSxDOS opened this issue Aug 15, 2020 · 3 comments
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-mir-opt Area: MIR optimizations C-enhancement Category: An issue proposing an enhancement or a PR with one. I-slow Issue: Problems and improvements with respect to performance of generated code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@MSxDOS
Copy link

MSxDOS commented Aug 15, 2020

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.

@rustbot rustbot added A-mir-opt Area: MIR optimizations C-enhancement Category: An issue proposing an enhancement or a PR with one. I-slow Issue: Problems and improvements with respect to performance of generated code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 15, 2020
@tesuji
Copy link
Contributor

tesuji commented Aug 15, 2020

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

@rustbot rustbot added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Aug 15, 2020
@MSxDOS
Copy link
Author

MSxDOS commented Oct 11, 2020

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

Now it also requires -Zunsound-mir-opts

@MSxDOS
Copy link
Author

MSxDOS commented Mar 5, 2021

The example is fixed on nightly, probably by #81451

@MSxDOS MSxDOS closed this as completed Mar 5, 2021
m-ou-se added a commit to m-ou-se/rust that referenced this issue Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-mir-opt Area: MIR optimizations C-enhancement Category: An issue proposing an enhancement or a PR with one. I-slow Issue: Problems and improvements with respect to performance of generated code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants