Skip to content

Assertion failed. Assigning static item using out of bounds index. #13701

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

Closed
adam-frisby opened this issue Apr 23, 2014 · 4 comments
Closed

Assertion failed. Assigning static item using out of bounds index. #13701

adam-frisby opened this issue Apr 23, 2014 · 4 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@adam-frisby
Copy link

Attempting to compile the following code causes rustc to crash.

const VEC: [int, ..4] = [0, 1, 2, 3];

fn main() {
    static v: int = VEC[6];
}

Windows 8.1
rustc 0.11-pre-nightly (7d725a3 2014-04-21 23:01:39 -0700)
host: i686-pc-mingw32

C:\test.rs:1:1: 1:39 warning: code is never used: `VEC`, #[warn(dead_code)] on by default
C:\test.rs:1 static VEC: [int, ..4] = [0, 1, 2, 3];
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\test.rs:4:2: 4:25 warning: code is never used: `v`, #[warn(dead_code)] on by default
C:\test.rs:4    static v: int = VEC[6];
                                ^~~~~~~~~~~~~~~~~~~~~~~
C:\test.rs:4:18: 4:24 error: const index-expr is out of bounds
C:\test.rs:4    static v: int = VEC[6];
                                                ^~~~~~

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Assertion failed!

Program: C:\Program Files (x86)\Rust\bin\rustc.exe
File: c:/bot/slave/nightly-win/build/src/llvm/lib/IR/Constants.cpp, Line 2021

Expression: ReqTy && "extractvalue indices invalid!"
[Finished in 1.0s with exit code 3]

Xubuntu 13.10
rustc 0.11-pre-nightly (a5cd502 2014-04-22 02:06:35 -0700)
host: x86_64-unknown-linux-gnu

test.rs:1:1: 1:39 warning: code is never used: `VEC`, #[warn(dead_code)] on by default
test.rs:1 static VEC: [int, ..4] = [0, 1, 2, 3];
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.rs:4:2: 4:25 warning: code is never used: `v`, #[warn(dead_code)] on by default
test.rs:4   static v: int = VEC[6];
            ^~~~~~~~~~~~~~~~~~~~~~~
test.rs:4:18: 4:24 error: const index-expr is out of bounds
test.rs:4   static v: int = VEC[6];
                            ^~~~~~
rustc: /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/llvm/lib/IR/Constants.cpp:2021: static llvm::Constant* llvm::ConstantExpr::getExtractValue(llvm::Constant*, llvm::ArrayRef<unsigned int>): Assertion `ReqTy && "extractvalue indices invalid!"' failed.
Aborted (core dumped)
@adam-frisby adam-frisby changed the title Compiler crash. Assigning static item using out of bounds index. Assertion failed. Assigning static item using out of bounds index. Apr 23, 2014
@steveklabnik steveklabnik added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Sep 22, 2014
@ghost ghost added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Nov 7, 2014
@ghost ghost removed the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Dec 12, 2014
@Twisol
Copy link

Twisol commented Jan 4, 2015

/cc @eddyb

@steveklabnik
Copy link
Member

triage:

hello.rs:4:25: 4:31 error: const index-expr is out of bounds
hello.rs:4         static v: int = VEC[6];
                                   ^~~~~~
rustc: /home/steve/src/rust/src/llvm/lib/IR/Constants.cpp:2176: static llvm::Constant* llvm::ConstantExpr::getExtractValue(llvm::Constant*, llvm::ArrayRef<unsigned int>, llvm::Type*): Assertion `ReqTy && "extractvalue indices invalid!"' failed.

@JustAPerson
Copy link
Contributor

tl;dr: this bug appears to be fixed.
Updated for current Rust (on playpen as of today 29 March 2015):

@pix64's example does not crash but still gives an out of bound error:

const VEC: [isize; 4] = [0, 1, 2, 3];

fn main() {
    static v: isize = VEC[6];
}

@alexcrichton
Copy link
Member

Yay!

flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 28, 2024
changelog: [`missing_safety_doc`]: accept uppercase "SAFETY"

In [Oxc](https://github.com/oxc-project/oxc)'s codebase, we try to draw
attention as clearly as possible to the safety constraints of unsafe
code by including an uppercase `# SAFETY` doc comment.

Clippy's `missing_safety_doc` lint does not recognise "SAFETY" in upper
case, so we also need to include `#[expect(clippy::missing_safety_doc)]`
on every unsafe function, to avoid a false positive. Unfortunately this
defeats the purpose of the lint, as if someone later removes the safety
docs, the lint rule does not trigger.

I don't know how common this style of documenting unsafe functions is,
but I don't imagine also supporting `# SAFETY` would disturb other users
who prefer `# Safety`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

5 participants