Fix ICE when trying to drop an unsized type from a different crate
The code to get the LLVM type signature for the drop function doesn't handle unsized types correctly.
This commit is contained in:
parent
9bba711063
commit
1eeaf2065b
@ -472,6 +472,9 @@ fn llvm_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
}
|
||||
|
||||
pub fn type_of_dtor<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, self_ty: Ty<'tcx>) -> Type {
|
||||
let self_ty = type_of(ccx, self_ty).ptr_to();
|
||||
Type::func(&[self_ty], &Type::void(ccx))
|
||||
if type_is_sized(ccx.tcx(), self_ty) {
|
||||
Type::func(&[type_of(ccx, self_ty).ptr_to()], &Type::void(ccx))
|
||||
} else {
|
||||
Type::func(&type_of(ccx, self_ty).field_types(), &Type::void(ccx))
|
||||
}
|
||||
}
|
||||
|
23
src/test/auxiliary/fat_drop.rs
Normal file
23
src/test/auxiliary/fat_drop.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
pub static mut DROPPED: bool = false;
|
||||
|
||||
pub struct S {
|
||||
_unsized: [u8]
|
||||
}
|
||||
|
||||
impl Drop for S {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
DROPPED = true;
|
||||
}
|
||||
}
|
||||
}
|
23
src/test/run-pass/extern_fat_drop.rs
Normal file
23
src/test/run-pass/extern_fat_drop.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// aux-build:fat_drop.rs
|
||||
|
||||
#![feature(core_intrinsics)]
|
||||
|
||||
extern crate fat_drop;
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
let s: &mut fat_drop::S = std::mem::uninitialized();
|
||||
std::intrinsics::drop_in_place(s);
|
||||
assert!(fat_drop::DROPPED);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user