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

ICE on function definition in extern blocks #75283

Closed
lf- opened this issue Aug 8, 2020 · 1 comment · Fixed by #75350
Closed

ICE on function definition in extern blocks #75283

lf- opened this issue Aug 8, 2020 · 1 comment · Fixed by #75350
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lf-
Copy link
Contributor

lf- commented Aug 8, 2020

Hi! I encountered this ICE while putting bad code into my compiler while learning FFI for the first time. It also reproduced on stable 1.45.2, with the different location:

thread 'rustc' panicked at 'index out of bounds: the len is 13 but the index is 25', /rustc/d3fb005a39e62501b8b0b356166e515ae24e2e54/src/librustc_hir/definitions.rs:347:9

Code

extern "C" {
    fn lol() {
        println!("hello world!");
// whoops, forgot to close my function block
}

Meta

rustc --version --verbose:

dev/nix-doc - [main●] » rustc --version --verbose
rustc 1.47.0-nightly (6c8927b0c 2020-07-26)
binary: rustc
commit-hash: 6c8927b0cf80ceee19386026cf9d7fd4fd9d486f
commit-date: 2020-07-26
host: x86_64-unknown-linux-gnu
release: 1.47.0-nightly
LLVM version: 10.0

# STABLE
dev/nix-doc - [main●] » rustup run stable rustc --version --verbose
rustc 1.45.2 (d3fb005a3 2020-07-31)
binary: rustc
commit-hash: d3fb005a39e62501b8b0b356166e515ae24e2e54
commit-date: 2020-07-31
host: x86_64-unknown-linux-gnu
release: 1.45.2
LLVM version: 10.0

Error output

dev/nix-doc - [main●] » RUST_BACKTRACE=0 rustc -Zno-codegen ice-repro.rs
error: this file contains an unclosed delimiter
 --> ice-repro.rs:4:3
  |
1 | extern "C" {
  |            - unclosed delimiter
2 |     fn lol() {
  |              - this delimiter might not be properly closed...
3 |         println!("hello world!");
4 | }
  | - ^
  | |
  | ...as it matches this but it has different indentation

error: incorrect function inside `extern` block
 --> ice-repro.rs:2:8
  |
1 |   extern "C" {
  |   ---------- `extern` blocks define existing foreign functions and functions inside of them cannot have a body
2 |       fn lol() {
  |  ________^^^___-
  | |        |
  | |        cannot have a body
3 | |         println!("hello world!");
4 | | }
  | |_- help: remove the invalid body: `;`
  |
  = help: you might have meant to write a function accessible through FFI, which can be done by writing `extern fn` outside of the `extern` block
  = note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html

thread 'rustc' panicked at 'index out of bounds: the len is 13 but the index is 25', src/librustc_ast_lowering/lib.rs:577:29
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.47.0-nightly (6c8927b0c 2020-07-26) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z no-codegen

error: aborting due to 2 previous errors
Backtrace

thread 'rustc' panicked at 'index out of bounds: the len is 13 but the index is 25', src/librustc_ast_lowering/lib.rs:577:29
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1117
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1508
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:217
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:530
  12: rust_begin_unwind
             at src/libstd/panicking.rs:437
  13: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  14: core::panicking::panic_bounds_check
             at src/libcore/panicking.rs:62
  15: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  16: rustc_ast_lowering::lower_crate
  17: rustc_interface::passes::BoxedResolver::access::{{closure}}
  18: rustc_interface::passes::configure_and_expand::{{closure}}
  19: rustc_interface::passes::BoxedResolver::access
  20: rustc_interface::queries::Queries::lower_to_hir
  21: rustc_interface::queries::Queries::global_ctxt
  22: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  23: rustc_span::with_source_map
  24: rustc_interface::interface::create_compiler_and_run
  25: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@lf- lf- added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 8, 2020
@jonas-schievink jonas-schievink added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Aug 8, 2020
@estebank
Copy link
Contributor

estebank commented Aug 9, 2020

The unclosed delimiters were a red herring, it reproduces even with correct delimiters. My guess is that we're trying to perform some evaluation on the body that should not have been done and instead treated as no body present for extern items.

@estebank estebank self-assigned this Aug 9, 2020
@jyn514 jyn514 changed the title ICE with unclosed delimiters on incorrectly used extern blocks ICE on function definition in extern blocks Aug 9, 2020
JohnTitor added a commit to JohnTitor/rust that referenced this issue Aug 10, 2020
…r=davidtwco

Do not ICE when lowering invalid extern fn with bodies

Fix rust-lang#75283.
@bors bors closed this as completed in bdf426a Aug 10, 2020
@Dylan-DPC-zz Dylan-DPC-zz removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Aug 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants