Skip to content

rustc crash on stable #70078

Closed
Closed
@DutchGhost

Description

@DutchGhost

I tried this code:

mod internal {
    extern "C" {
        pub static main: fn();
    }
}

fn main() {
    unsafe { internal::main() }
}

I expected to see this happen: This program should compile, and probably crash at runtime

Instead, this happened: rustc crashes with exit code: 0xc0000374, STATUS_HEAP_CORRUPTION), (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION), and (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN). Each time I run cargo build, rustc exits with one of those 3 statuses.

Oh, and one time I got it to ICE instead, which the backtrace is from

Meta

rustc --version --verbose:

rustc 1.41.1 (f3e1a954d 2020-02-24)
Backtrace

warning: `extern` block uses type `fn()`, which is not FFI-safe
 --> src\main.rs:3:26
  |
3 |         pub static main: fn();
  |                          ^^^^ not FFI-safe
  |
  = note: `#[warn(improper_ctypes)]` on by default
  = help: consider using an `extern fn(...) -> ...` function pointer instead
  = note: this function pointer has Rust-specific calling convention

thread 'rustc' panicked at 'out of bounds argument access: 0 out of 0 arguments', src\librustc_codegen_llvm\llvm\mod.rs:200:9
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: <std::io::IoSliceMut as core::fmt::Debug>::fmt
   3: std::panicking::take_hook
   4: std::panicking::take_hook
   5: rustc_driver::report_ice
   6: std::panicking::rust_panic_with_hook
   7: rust_begin_unwind
   8: std::panicking::begin_panic_fmt
   9: rustc_codegen_llvm::abi::<impl rustc_codegen_ssa::traits::abi::AbiBuilderMethods for rustc_codegen_llvm::builder::Builder>::get_param
  10: <rustc_codegen_llvm::llvm_::ffi::PassKind as core::fmt::Debug>::fmt
  11: <rustc_codegen_llvm::llvm_::ffi::PassKind as core::fmt::Debug>::fmt
  12: <rustc_codegen_llvm::base::ValueIter as core::iter::traits::iterator::Iterator>::next
  13: <rustc_codegen_llvm::back::lto::ThinLTOImports as core::fmt::Debug>::fmt
  14: <rustc_codegen_llvm::base::ValueIter as core::iter::traits::iterator::Iterator>::next
  15: <rustc_codegen_llvm::llvm_::ffi::PassKind as core::fmt::Debug>::fmt
  16: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  17: rustc_interface::passes::QueryContext::print_stats
  18: rustc_interface::passes::QueryContext::print_stats
  19: <env_logger::filter::inner::Filter as core::fmt::Debug>::fmt
  20: rustc_interface::queries::Queries::ongoing_codegen
  21: rustc_driver::pretty::print_after_hir_lowering
  22: <syntax_pos::symbol::SymbolStr as core::fmt::Display>::fmt
  23: <chalk_engine::stack::StackIndex as core::convert::From<usize>>::from
  24: <rustc_driver::Compilation as core::fmt::Debug>::fmt
  25: <chalk_engine::stack::StackIndex as core::convert::From<usize>>::from
  26: _rust_maybe_catch_panic
  27: rustc_driver::pretty::print_after_hir_lowering
  28: ZN244_$LT$std..error..$LT$impl$u20$core..convert..From$LT$alloc..string..String$GT$$u20$for$u20$alloc..boxed..Box$LT$dyn$u20$std..error..Error$u2b$core..marker..Send$u2b$core..marker..Sync$GT$$GT$..from..StringError$u20$as$u20$core..fmt..Display$GT$3fmt17
  29: std::sys::windows::thread::Thread::new
  30: BaseThreadInitThunk
  31: RtlUserThreadStart
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.41.1 (f3e1a954d 2020-02-24) running on x86_64-pc-windows-msvc

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `mainfun`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions