Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix ICE caused by Drop implementations for unsized types
Fixes #26709
  • Loading branch information
dotdash committed Jul 3, 2015
1 parent 4c246ec commit eaeede2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/librustc_trans/trans/glue.rs
Expand Up @@ -355,7 +355,7 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let ty = Type::from_ref(llvm::LLVMTypeOf(dtor_addr));
ty.element_type().func_params()
};
assert_eq!(params.len(), 1);
assert_eq!(params.len(), if type_is_sized(bcx.tcx(), t) { 1 } else { 2 });

// Be sure to put the contents into a scope so we can use an invoke
// instruction to call the user destructor but still call the field
Expand All @@ -371,7 +371,12 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,

let glue_type = get_drop_glue_type(bcx.ccx(), t);
let dtor_ty = bcx.tcx().mk_ctor_fn(class_did, &[glue_type], bcx.tcx().mk_nil());
let (_, bcx) = invoke(bcx, dtor_addr, &[v0], dtor_ty, DebugLoc::None);
let (_, bcx) = if type_is_sized(bcx.tcx(), t) {
invoke(bcx, dtor_addr, &[v0], dtor_ty, DebugLoc::None)
} else {
let args = [Load(bcx, expr::get_dataptr(bcx, v0)), Load(bcx, expr::get_len(bcx, v0))];
invoke(bcx, dtor_addr, &args, dtor_ty, DebugLoc::None)
};

bcx.fcx.pop_and_trans_custom_cleanup_scope(bcx, contents_scope)
}
Expand Down
26 changes: 26 additions & 0 deletions src/test/run-pass/issue-26709.rs
@@ -0,0 +1,26 @@
// 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.

struct Wrapper<'a, T: ?Sized>(&'a mut i32, T);

impl<'a, T: ?Sized> Drop for Wrapper<'a, T> {
fn drop(&mut self) {
*self.0 = 432;
}
}

fn main() {
let mut x = 0;
{
let wrapper = Box::new(Wrapper(&mut x, 123));
let _: Box<Wrapper<Send>> = wrapper;
}
assert_eq!(432, x)
}

0 comments on commit eaeede2

Please sign in to comment.