Skip to content

Commit 1eeaf20

Browse files
committed
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.
1 parent 9bba711 commit 1eeaf20

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

src/librustc_trans/trans/type_of.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ fn llvm_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
472472
}
473473

474474
pub fn type_of_dtor<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, self_ty: Ty<'tcx>) -> Type {
475-
let self_ty = type_of(ccx, self_ty).ptr_to();
476-
Type::func(&[self_ty], &Type::void(ccx))
475+
if type_is_sized(ccx.tcx(), self_ty) {
476+
Type::func(&[type_of(ccx, self_ty).ptr_to()], &Type::void(ccx))
477+
} else {
478+
Type::func(&type_of(ccx, self_ty).field_types(), &Type::void(ccx))
479+
}
477480
}

src/test/auxiliary/fat_drop.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub static mut DROPPED: bool = false;
12+
13+
pub struct S {
14+
_unsized: [u8]
15+
}
16+
17+
impl Drop for S {
18+
fn drop(&mut self) {
19+
unsafe {
20+
DROPPED = true;
21+
}
22+
}
23+
}

src/test/run-pass/extern_fat_drop.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:fat_drop.rs
12+
13+
#![feature(core_intrinsics)]
14+
15+
extern crate fat_drop;
16+
17+
fn main() {
18+
unsafe {
19+
let s: &mut fat_drop::S = std::mem::uninitialized();
20+
std::intrinsics::drop_in_place(s);
21+
assert!(fat_drop::DROPPED);
22+
}
23+
}

0 commit comments

Comments
 (0)