Skip to content

Multiple bounds checking elision failures #120433

New issue

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

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

Already on GitHub? # to your account

Open
SUPERCILEX opened this issue Jan 27, 2024 · 2 comments
Open

Multiple bounds checking elision failures #120433

SUPERCILEX opened this issue Jan 27, 2024 · 2 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-optimization Category: An issue highlighting optimization opportunities or PRs implementing such E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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

@SUPERCILEX
Copy link
Contributor

I tried this code:

pub fn foo(buf: &[u8], alloced_size: usize) -> &[u8] {
    if alloced_size.checked_add(1).map(|total| buf.len() < total).unwrap_or(true) {
        return &[];
    }
    let size = buf[0];
    &buf[1..1 + usize::min(alloced_size, usize::from(size))]
}

The assembly code has two generated panics here when none can happen.

@SUPERCILEX SUPERCILEX added the C-bug Category: This is a bug. label Jan 27, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 27, 2024
@fmease fmease added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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. A-mir-opt Area: MIR optimizations C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. C-bug Category: This is a bug. labels Jan 28, 2024
@veera-sivarajan
Copy link
Contributor

fixed since rustc 1.81.0: https://rust.godbolt.org/z/bvEKh8ahe

@rustbot label +e-needs-test

@rustbot rustbot added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Mar 28, 2025
@moxian
Copy link
Contributor

moxian commented Mar 28, 2025

fixed by #126852 most likely

# for free to join this conversation on GitHub. Already have an account? # 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-optimization Category: An issue highlighting optimization opportunities or PRs implementing such E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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

5 participants