Skip to content

Compiler crash when casting from *mut c_void to *mut [u8] #22955

Closed
@snf

Description

@snf
extern crate libc;

fn main() {
    unsafe {
        let data = libc::malloc(100);
        let data_vec = data as *mut [u8];
    }
}
$ rustc --version
rustc 1.0.0-nightly (890293655 2015-02-28) (built 2015-03-01)
$ RUST_BACKTRACE=1 rustc 1.rs 
1.rs:1:1: 1:19 warning: use of unstable library feature 'libc'
1.rs:1 extern crate libc;
       ^~~~~~~~~~~~~~~~~~
1.rs:1:1: 1:19 help: add #![feature(libc)] to the crate attributes to silence this warning
1.rs:1 extern crate libc;
       ^~~~~~~~~~~~~~~~~~
1.rs:5:20: 5:32 warning: use of unstable library feature 'libc'
1.rs:5         let data = libc::malloc(100);
                          ^~~~~~~~~~~~
1.rs:5:20: 5:32 help: add #![feature(libc)] to the crate attributes to silence this warning
1.rs:5         let data = libc::malloc(100);
                          ^~~~~~~~~~~~
1.rs:6:13: 6:21 warning: unused variable: `data_vec`, #[warn(unused_variables)] on by default
1.rs:6         let data_vec = data as *mut [u8];
                   ^~~~~~~~
error: internal compiler error: translating unsupported cast: *mut libc::types::common::c95::c_void (cast_pointer) -> *mut [u8] (cast_other)
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: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:189

stack backtrace:
   1:         0x61ef7c4f - sys::backtrace::write::hb08af03691eab78a5kA
   2:         0x61f20782 - panicking::on_panic::h37164609ca1c02afBnJ
   3:         0x61e6063a - rt::unwind::begin_unwind_inner::h24d5e7492198457b43I
   4:         0x5f189a8d - rt::unwind::begin_unwind::h9113908695753286194
   5:         0x5f18a2c5 - diagnostic::Handler::bug::h35ee8d5e5a4a01aeCHD
   6:         0x5fcaa9fb - session::Session::bug::hf545afa75e911993uwp
   7:         0x615e1650 - trans::expr::trans_imm_cast::h267a0afdb72de17aLPj
   8:         0x615cc199 - trans::expr::trans_unadjusted::h195794326d4a3453m4h
   9:         0x615835bf - trans::expr::trans_into::h4bccf2ad56ca2eb8mnh
  10:         0x6168307e - trans::_match::mk_binding_alloca::h11720668362277363266
  11:         0x6158281d - trans::base::init_local::h445e388f28d5f2ddMps
  12:         0x61583fe2 - trans::controlflow::trans_block::hac110643148141f4T4d
  13:         0x615cd7ae - trans::expr::trans_rvalue_dps_unadjusted::h98f8f68155d4ea21Rzi
  14:         0x6158359e - trans::expr::trans_into::h4bccf2ad56ca2eb8mnh
  15:         0x61584307 - trans::controlflow::trans_block::hac110643148141f4T4d
  16:         0x6164f7ef - trans::base::trans_closure::hf74692cb2d4d8ab8wct
  17:         0x61570538 - trans::base::trans_fn::hd3b302f8da4ef8d2pnt
  18:         0x6156c107 - trans::base::trans_item::h43df28c38e89c2c1hLt
  19:         0x616562fc - trans::base::trans_crate::h6e541e412696da41RGu
  20:         0x62581fd2 - driver::phase_4_translate_to_llvm::h39966ab909496f1crNa
  21:         0x6255d5c8 - driver::compile_input::hee81c045ab46c74fIba
  22:         0x62627e6e - run_compiler::h875c1e123fe4ae2cF5b
  23:         0x62625a1c - thunk::F.Invoke<A, R>::invoke::h12424714292252424185
  24:         0x62624770 - rt::unwind::try::try_fn::h4021821266450575721
  25:         0x61f8bfe8 - rust_try_inner
  26:         0x61f8bfd5 - rust_try
  27:         0x62624e5c - thunk::F.Invoke<A, R>::invoke::h8199562432922027576
  28:         0x61f0c2d5 - sys::thread::thread_start::h1b1bb1e7ac08d3a6yRE
  29:         0x5bc420a3 - start_thread
  30:         0x61adfccc - __clone
  31:         0xffffffff - <unknown>

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions