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

unconditional_panic array bounds check doesn't work through Deref #109260

Closed
e2-71828 opened this issue Mar 17, 2023 · 2 comments
Closed

unconditional_panic array bounds check doesn't work through Deref #109260

e2-71828 opened this issue Mar 17, 2023 · 2 comments
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. L-unconditional_panic Lint: unconditional_panic S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@e2-71828
Copy link

(Initially reported on URLO)

In the following program:

fn main() {
    let mut arr_0: [u32; 10] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

    let ptr_0 = Box::new(arr_0);

    let ptr_v = ptr_0[11];
    let arr_v = arr_0[11];
    println!("v:{}", ptr_v);
}

The out-of-bounds access of ptr_0[11] is not flagged at compile time, but the similar access of arr_0[11] is.

@e2-71828 e2-71828 added the C-bug Category: This is a bug. label Mar 17, 2023
@clubby789
Copy link
Contributor

It looks like the MIR ends up as

_7 = const false;
assert(move _7, "index out of bounds: the length is {} but the index is {}", move _6, _5) -> [success: bb2, unwind: bb4];

and the lint isn't able to look through that constant to identify it

@jyn514 jyn514 added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-const-eval Area: Constant evaluation (MIR interpretation) labels May 1, 2023
@jieyouxu jieyouxu added L-unconditional_panic Lint: unconditional_panic T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue labels May 13, 2024
@veera-sivarajan
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. L-unconditional_panic Lint: unconditional_panic S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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