Description
Found this while experimenting with the right FFI type to declare a char[]
(not char *
) symbol in an extern "C"
block. Credit to @acfoltzer for the original code sample that I tweaked to end up with this error. This produces an ICE on nightly, or a segfault on stable.
rustc 1.30.0-nightly (20dc0c507 2018-09-19)
Code:
$ head Cargo.toml build.rs src/*
==> Cargo.toml <==
[package]
name = "testcrate"
version = "0.0.1"
[build-dependencies]
cc = "1.0"
==> build.rs <==
extern crate cc;
fn main() {
cc::Build::new()
.file("src/foo.c")
.compile("foo");
}
==> src/foo.c <==
char symbol[1024] = "hello world";
==> src/main.rs <==
use std::os::raw::c_char;
extern "C" {
pub static mut symbol: [c_char];
}
fn main() {
println!("{:p}", unsafe { &symbol });
}
Result:
$ cargo +nightly build --verbose
Fresh cc v1.0.25
Compiling testcrate v0.0.1 (/tmp/testcrate)
Running `rustc --crate-name testcrate src/main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=eb3a438da9110935 -C extra-filename=-eb3a438da9110935 --out-dir /tmp/testcrate/target/debug/deps -C incremental=/tmp/testcrate/target/debug/incremental -L dependency=/tmp/testcrate/target/debug/deps -L native=/tmp/testcrate/target/debug/build/testcrate-b3e5d3e42b558a4c/out -l static=foo`
warning: `extern` block uses type `[i8]` which is not FFI-safe: slices have no C equivalent
--> src/main.rs:3:28
|
3 | pub static mut symbol: [c_char];
| ^^^^^^^^
|
= note: #[warn(improper_ctypes)] on by default
= help: consider using a raw pointer instead
thread 'main' panicked at 'assertion failed: !layout.is_unsized()', librustc_codegen_llvm/mir/place.rs:50:9
note: Run with `RUST_BACKTRACE=1` for 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/blob/master/CONTRIBUTING.md#bug-reports
note: rustc 1.30.0-nightly (20dc0c507 2018-09-19) running on x86_64-unknown-linux-gnu
note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin
note: some of the compiler flags provided by cargo are hidden
error: Could not compile `testcrate`.
Caused by:
process didn't exit successfully: `rustc --crate-name testcrate src/main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=eb3a438da9110935 -C extra-filename=-eb3a438da9110935 --out-dir /tmp/testcrate/target/debug/deps -C incremental=/tmp/testcrate/target/debug/incremental -L dependency=/tmp/testcrate/target/debug/deps -L native=/tmp/testcrate/target/debug/build/testcrate-b3e5d3e42b558a4c/out -l static=foo` (exit code: 101)