Skip to content

Multiple bounds checking elision failures #120433

Open
@SUPERCILEX

Description

@SUPERCILEX

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.

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-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.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