]> git.proxmox.com Git - rustc.git/blob - src/librustc_trans/trans/glue.rs
Imported Upstream version 1.2.0+dfsg1
[rustc.git] / src / librustc_trans / trans / glue.rs
1 // Copyright 2012-2013 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 //!
12 //
13 // Code relating to drop glue.
14
15
16 use back::abi;
17 use back::link::*;
18 use llvm;
19 use llvm::{ValueRef, get_param};
20 use metadata::csearch;
21 use middle::lang_items::ExchangeFreeFnLangItem;
22 use middle::subst;
23 use middle::subst::{Subst, Substs};
24 use middle::ty::{self, Ty};
25 use trans::adt;
26 use trans::adt::GetDtorType; // for tcx.dtor_type()
27 use trans::base::*;
28 use trans::build::*;
29 use trans::callee;
30 use trans::cleanup;
31 use trans::cleanup::CleanupMethods;
32 use trans::common::*;
33 use trans::debuginfo::DebugLoc;
34 use trans::declare;
35 use trans::expr;
36 use trans::foreign;
37 use trans::inline;
38 use trans::machine::*;
39 use trans::monomorphize;
40 use trans::type_of::{type_of, type_of_dtor, sizing_type_of, align_of};
41 use trans::type_::Type;
42
43 use arena::TypedArena;
44 use libc::c_uint;
45 use syntax::ast;
46
47 pub fn trans_exchange_free_dyn<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
48 v: ValueRef,
49 size: ValueRef,
50 align: ValueRef,
51 debug_loc: DebugLoc)
52 -> Block<'blk, 'tcx> {
53 let _icx = push_ctxt("trans_exchange_free");
54 let ccx = cx.ccx();
55 callee::trans_lang_call(cx,
56 langcall(cx, None, "", ExchangeFreeFnLangItem),
57 &[PointerCast(cx, v, Type::i8p(ccx)), size, align],
58 Some(expr::Ignore),
59 debug_loc).bcx
60 }
61
62 pub fn trans_exchange_free<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
63 v: ValueRef,
64 size: u64,
65 align: u32,
66 debug_loc: DebugLoc)
67 -> Block<'blk, 'tcx> {
68 trans_exchange_free_dyn(cx,
69 v,
70 C_uint(cx.ccx(), size),
71 C_uint(cx.ccx(), align),
72 debug_loc)
73 }
74
75 pub fn trans_exchange_free_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
76 ptr: ValueRef,
77 content_ty: Ty<'tcx>,
78 debug_loc: DebugLoc)
79 -> Block<'blk, 'tcx> {
80 assert!(type_is_sized(bcx.ccx().tcx(), content_ty));
81 let sizing_type = sizing_type_of(bcx.ccx(), content_ty);
82 let content_size = llsize_of_alloc(bcx.ccx(), sizing_type);
83
84 // `Box<ZeroSizeType>` does not allocate.
85 if content_size != 0 {
86 let content_align = align_of(bcx.ccx(), content_ty);
87 trans_exchange_free(bcx, ptr, content_size, content_align, debug_loc)
88 } else {
89 bcx
90 }
91 }
92
93 pub fn get_drop_glue_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
94 t: Ty<'tcx>) -> Ty<'tcx> {
95 let tcx = ccx.tcx();
96 // Even if there is no dtor for t, there might be one deeper down and we
97 // might need to pass in the vtable ptr.
98 if !type_is_sized(tcx, t) {
99 return t
100 }
101
102 // FIXME (#22815): note that type_needs_drop conservatively
103 // approximates in some cases and may say a type expression
104 // requires drop glue when it actually does not.
105 //
106 // (In this case it is not clear whether any harm is done, i.e.
107 // erroneously returning `t` in some cases where we could have
108 // returned `tcx.types.i8` does not appear unsound. The impact on
109 // code quality is unknown at this time.)
110
111 if !type_needs_drop(tcx, t) {
112 return tcx.types.i8;
113 }
114 match t.sty {
115 ty::TyBox(typ) if !type_needs_drop(tcx, typ)
116 && type_is_sized(tcx, typ) => {
117 let llty = sizing_type_of(ccx, typ);
118 // `Box<ZeroSizeType>` does not allocate.
119 if llsize_of_alloc(ccx, llty) == 0 {
120 tcx.types.i8
121 } else {
122 t
123 }
124 }
125 _ => t
126 }
127 }
128
129 pub fn drop_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
130 v: ValueRef,
131 t: Ty<'tcx>,
132 debug_loc: DebugLoc) -> Block<'blk, 'tcx> {
133 drop_ty_core(bcx, v, t, debug_loc, false)
134 }
135
136 pub fn drop_ty_core<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
137 v: ValueRef,
138 t: Ty<'tcx>,
139 debug_loc: DebugLoc,
140 skip_dtor: bool) -> Block<'blk, 'tcx> {
141 // NB: v is an *alias* of type t here, not a direct value.
142 debug!("drop_ty_core(t={:?}, skip_dtor={})", t, skip_dtor);
143 let _icx = push_ctxt("drop_ty");
144 if bcx.fcx.type_needs_drop(t) {
145 let ccx = bcx.ccx();
146 let g = if skip_dtor {
147 DropGlueKind::TyContents(t)
148 } else {
149 DropGlueKind::Ty(t)
150 };
151 let glue = get_drop_glue_core(ccx, g);
152 let glue_type = get_drop_glue_type(ccx, t);
153 let ptr = if glue_type != t {
154 PointerCast(bcx, v, type_of(ccx, glue_type).ptr_to())
155 } else {
156 v
157 };
158
159 Call(bcx, glue, &[ptr], None, debug_loc);
160 }
161 bcx
162 }
163
164 pub fn drop_ty_immediate<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
165 v: ValueRef,
166 t: Ty<'tcx>,
167 debug_loc: DebugLoc,
168 skip_dtor: bool)
169 -> Block<'blk, 'tcx> {
170 let _icx = push_ctxt("drop_ty_immediate");
171 let vp = alloca(bcx, type_of(bcx.ccx(), t), "");
172 store_ty(bcx, v, vp, t);
173 drop_ty_core(bcx, vp, t, debug_loc, skip_dtor)
174 }
175
176 pub fn get_drop_glue<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> ValueRef {
177 get_drop_glue_core(ccx, DropGlueKind::Ty(t))
178 }
179
180 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
181 pub enum DropGlueKind<'tcx> {
182 /// The normal path; runs the dtor, and then recurs on the contents
183 Ty(Ty<'tcx>),
184 /// Skips the dtor, if any, for ty; drops the contents directly.
185 /// Note that the dtor is only skipped at the most *shallow*
186 /// level, namely, an `impl Drop for Ty` itself. So, for example,
187 /// if Ty is Newtype(S) then only the Drop impl for for Newtype
188 /// itself will be skipped, while the Drop impl for S, if any,
189 /// will be invoked.
190 TyContents(Ty<'tcx>),
191 }
192
193 impl<'tcx> DropGlueKind<'tcx> {
194 fn ty(&self) -> Ty<'tcx> {
195 match *self { DropGlueKind::Ty(t) | DropGlueKind::TyContents(t) => t }
196 }
197
198 fn map_ty<F>(&self, mut f: F) -> DropGlueKind<'tcx> where F: FnMut(Ty<'tcx>) -> Ty<'tcx>
199 {
200 match *self {
201 DropGlueKind::Ty(t) => DropGlueKind::Ty(f(t)),
202 DropGlueKind::TyContents(t) => DropGlueKind::TyContents(f(t)),
203 }
204 }
205 }
206
207 fn get_drop_glue_core<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
208 g: DropGlueKind<'tcx>) -> ValueRef {
209 debug!("make drop glue for {:?}", g);
210 let g = g.map_ty(|t| get_drop_glue_type(ccx, t));
211 debug!("drop glue type {:?}", g);
212 match ccx.drop_glues().borrow().get(&g) {
213 Some(&glue) => return glue,
214 _ => { }
215 }
216 let t = g.ty();
217
218 let llty = if type_is_sized(ccx.tcx(), t) {
219 type_of(ccx, t).ptr_to()
220 } else {
221 type_of(ccx, ty::mk_uniq(ccx.tcx(), t)).ptr_to()
222 };
223
224 let llfnty = Type::glue_fn(ccx, llty);
225
226 // To avoid infinite recursion, don't `make_drop_glue` until after we've
227 // added the entry to the `drop_glues` cache.
228 if let Some(old_sym) = ccx.available_drop_glues().borrow().get(&g) {
229 let llfn = declare::declare_cfn(ccx, &old_sym, llfnty, ty::mk_nil(ccx.tcx()));
230 ccx.drop_glues().borrow_mut().insert(g, llfn);
231 return llfn;
232 };
233
234 let fn_nm = mangle_internal_name_by_type_and_seq(ccx, t, "drop");
235 let llfn = declare::define_cfn(ccx, &fn_nm, llfnty, ty::mk_nil(ccx.tcx())).unwrap_or_else(||{
236 ccx.sess().bug(&format!("symbol `{}` already defined", fn_nm));
237 });
238 ccx.available_drop_glues().borrow_mut().insert(g, fn_nm);
239
240 let _s = StatRecorder::new(ccx, format!("drop {:?}", t));
241
242 let empty_substs = ccx.tcx().mk_substs(Substs::trans_empty());
243 let (arena, fcx): (TypedArena<_>, FunctionContext);
244 arena = TypedArena::new();
245 fcx = new_fn_ctxt(ccx, llfn, ast::DUMMY_NODE_ID, false,
246 ty::FnConverging(ty::mk_nil(ccx.tcx())),
247 empty_substs, None, &arena);
248
249 let bcx = init_function(&fcx, false, ty::FnConverging(ty::mk_nil(ccx.tcx())));
250
251 update_linkage(ccx, llfn, None, OriginalTranslation);
252
253 ccx.stats().n_glues_created.set(ccx.stats().n_glues_created.get() + 1);
254 // All glue functions take values passed *by alias*; this is a
255 // requirement since in many contexts glue is invoked indirectly and
256 // the caller has no idea if it's dealing with something that can be
257 // passed by value.
258 //
259 // llfn is expected be declared to take a parameter of the appropriate
260 // type, so we don't need to explicitly cast the function parameter.
261
262 let llrawptr0 = get_param(llfn, fcx.arg_offset() as c_uint);
263 let bcx = make_drop_glue(bcx, llrawptr0, g);
264 finish_fn(&fcx, bcx, ty::FnConverging(ty::mk_nil(ccx.tcx())), DebugLoc::None);
265
266 llfn
267 }
268
269 fn trans_struct_drop_flag<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
270 t: Ty<'tcx>,
271 struct_data: ValueRef,
272 dtor_did: ast::DefId,
273 class_did: ast::DefId,
274 substs: &subst::Substs<'tcx>)
275 -> Block<'blk, 'tcx> {
276 assert!(type_is_sized(bcx.tcx(), t), "Precondition: caller must ensure t is sized");
277
278 let repr = adt::represent_type(bcx.ccx(), t);
279 let drop_flag = unpack_datum!(bcx, adt::trans_drop_flag_ptr(bcx, &*repr, struct_data));
280 let loaded = load_ty(bcx, drop_flag.val, bcx.tcx().dtor_type());
281 let drop_flag_llty = type_of(bcx.fcx.ccx, bcx.tcx().dtor_type());
282 let init_val = C_integral(drop_flag_llty, adt::DTOR_NEEDED as u64, false);
283
284 let bcx = if !bcx.ccx().check_drop_flag_for_sanity() {
285 bcx
286 } else {
287 let drop_flag_llty = type_of(bcx.fcx.ccx, bcx.tcx().dtor_type());
288 let done_val = C_integral(drop_flag_llty, adt::DTOR_DONE as u64, false);
289 let not_init = ICmp(bcx, llvm::IntNE, loaded, init_val, DebugLoc::None);
290 let not_done = ICmp(bcx, llvm::IntNE, loaded, done_val, DebugLoc::None);
291 let drop_flag_neither_initialized_nor_cleared =
292 And(bcx, not_init, not_done, DebugLoc::None);
293 with_cond(bcx, drop_flag_neither_initialized_nor_cleared, |cx| {
294 let llfn = cx.ccx().get_intrinsic(&("llvm.debugtrap"));
295 Call(cx, llfn, &[], None, DebugLoc::None);
296 cx
297 })
298 };
299
300 let drop_flag_dtor_needed = ICmp(bcx, llvm::IntEQ, loaded, init_val, DebugLoc::None);
301 with_cond(bcx, drop_flag_dtor_needed, |cx| {
302 trans_struct_drop(cx, t, struct_data, dtor_did, class_did, substs)
303 })
304 }
305
306 pub fn get_res_dtor<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
307 did: ast::DefId,
308 t: Ty<'tcx>,
309 parent_id: ast::DefId,
310 substs: &Substs<'tcx>)
311 -> ValueRef {
312 let _icx = push_ctxt("trans_res_dtor");
313 let did = inline::maybe_instantiate_inline(ccx, did);
314
315 if !substs.types.is_empty() {
316 assert_eq!(did.krate, ast::LOCAL_CRATE);
317
318 // Since we're in trans we don't care for any region parameters
319 let substs = ccx.tcx().mk_substs(Substs::erased(substs.types.clone()));
320
321 let (val, _, _) = monomorphize::monomorphic_fn(ccx, did, substs, None);
322
323 val
324 } else if did.krate == ast::LOCAL_CRATE {
325 get_item_val(ccx, did.node)
326 } else {
327 let tcx = ccx.tcx();
328 let name = csearch::get_symbol(&ccx.sess().cstore, did);
329 let class_ty = ty::lookup_item_type(tcx, parent_id).ty.subst(tcx, substs);
330 let llty = type_of_dtor(ccx, class_ty);
331 let dtor_ty = ty::mk_ctor_fn(ccx.tcx(),
332 did,
333 &[get_drop_glue_type(ccx, t)],
334 ty::mk_nil(ccx.tcx()));
335 foreign::get_extern_fn(ccx, &mut *ccx.externs().borrow_mut(), &name[..], llvm::CCallConv,
336 llty, dtor_ty)
337 }
338 }
339
340 fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
341 t: Ty<'tcx>,
342 v0: ValueRef,
343 dtor_did: ast::DefId,
344 class_did: ast::DefId,
345 substs: &subst::Substs<'tcx>)
346 -> Block<'blk, 'tcx>
347 {
348 debug!("trans_struct_drop t: {}", t);
349
350 // Find and call the actual destructor
351 let dtor_addr = get_res_dtor(bcx.ccx(), dtor_did, t, class_did, substs);
352
353 // Class dtors have no explicit args, so the params should
354 // just consist of the environment (self).
355 let params = unsafe {
356 let ty = Type::from_ref(llvm::LLVMTypeOf(dtor_addr));
357 ty.element_type().func_params()
358 };
359 assert_eq!(params.len(), 1);
360
361 // Be sure to put the contents into a scope so we can use an invoke
362 // instruction to call the user destructor but still call the field
363 // destructors if the user destructor panics.
364 //
365 // FIXME (#14875) panic-in-drop semantics might be unsupported; we
366 // might well consider changing below to more direct code.
367 let contents_scope = bcx.fcx.push_custom_cleanup_scope();
368
369 // Issue #23611: schedule cleanup of contents, re-inspecting the
370 // discriminant (if any) in case of variant swap in drop code.
371 bcx.fcx.schedule_drop_adt_contents(cleanup::CustomScope(contents_scope), v0, t);
372
373 let glue_type = get_drop_glue_type(bcx.ccx(), t);
374 let dtor_ty = ty::mk_ctor_fn(bcx.tcx(), class_did, &[glue_type], ty::mk_nil(bcx.tcx()));
375 let (_, bcx) = invoke(bcx, dtor_addr, &[v0], dtor_ty, DebugLoc::None);
376
377 bcx.fcx.pop_and_trans_custom_cleanup_scope(bcx, contents_scope)
378 }
379
380 pub fn size_and_align_of_dst<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: Ty<'tcx>, info: ValueRef)
381 -> (ValueRef, ValueRef) {
382 debug!("calculate size of DST: {}; with lost info: {}",
383 t, bcx.val_to_string(info));
384 if type_is_sized(bcx.tcx(), t) {
385 let sizing_type = sizing_type_of(bcx.ccx(), t);
386 let size = C_uint(bcx.ccx(), llsize_of_alloc(bcx.ccx(), sizing_type));
387 let align = C_uint(bcx.ccx(), align_of(bcx.ccx(), t));
388 return (size, align);
389 }
390 match t.sty {
391 ty::TyStruct(id, substs) => {
392 let ccx = bcx.ccx();
393 // First get the size of all statically known fields.
394 // Don't use type_of::sizing_type_of because that expects t to be sized.
395 assert!(!ty::type_is_simd(bcx.tcx(), t));
396 let repr = adt::represent_type(ccx, t);
397 let sizing_type = adt::sizing_type_of(ccx, &*repr, true);
398 let sized_size = C_uint(ccx, llsize_of_alloc(ccx, sizing_type));
399 let sized_align = C_uint(ccx, llalign_of_min(ccx, sizing_type));
400
401 // Recurse to get the size of the dynamically sized field (must be
402 // the last field).
403 let fields = ty::struct_fields(bcx.tcx(), id, substs);
404 let last_field = fields[fields.len()-1];
405 let field_ty = last_field.mt.ty;
406 let (unsized_size, unsized_align) = size_and_align_of_dst(bcx, field_ty, info);
407
408 // Return the sum of sizes and max of aligns.
409 let size = Add(bcx, sized_size, unsized_size, DebugLoc::None);
410 let align = Select(bcx,
411 ICmp(bcx,
412 llvm::IntULT,
413 sized_align,
414 unsized_align,
415 DebugLoc::None),
416 sized_align,
417 unsized_align);
418 (size, align)
419 }
420 ty::TyTrait(..) => {
421 // info points to the vtable and the second entry in the vtable is the
422 // dynamic size of the object.
423 let info = PointerCast(bcx, info, Type::int(bcx.ccx()).ptr_to());
424 let size_ptr = GEPi(bcx, info, &[1]);
425 let align_ptr = GEPi(bcx, info, &[2]);
426 (Load(bcx, size_ptr), Load(bcx, align_ptr))
427 }
428 ty::TySlice(_) | ty::TyStr => {
429 let unit_ty = ty::sequence_element_type(bcx.tcx(), t);
430 // The info in this case is the length of the str, so the size is that
431 // times the unit size.
432 let llunit_ty = sizing_type_of(bcx.ccx(), unit_ty);
433 let unit_align = llalign_of_min(bcx.ccx(), llunit_ty);
434 let unit_size = llsize_of_alloc(bcx.ccx(), llunit_ty);
435 (Mul(bcx, info, C_uint(bcx.ccx(), unit_size), DebugLoc::None),
436 C_uint(bcx.ccx(), unit_align))
437 }
438 _ => bcx.sess().bug(&format!("Unexpected unsized type, found {}", t))
439 }
440 }
441
442 fn make_drop_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v0: ValueRef, g: DropGlueKind<'tcx>)
443 -> Block<'blk, 'tcx> {
444 let t = g.ty();
445 let skip_dtor = match g { DropGlueKind::Ty(_) => false, DropGlueKind::TyContents(_) => true };
446 // NB: v0 is an *alias* of type t here, not a direct value.
447 let _icx = push_ctxt("make_drop_glue");
448
449 // Only drop the value when it ... well, we used to check for
450 // non-null, (and maybe we need to continue doing so), but we now
451 // must definitely check for special bit-patterns corresponding to
452 // the special dtor markings.
453
454 let inttype = Type::int(bcx.ccx());
455 let dropped_pattern = C_integral(inttype, adt::dtor_done_usize(bcx.fcx.ccx) as u64, false);
456
457 match t.sty {
458 ty::TyBox(content_ty) => {
459 // Support for TyBox is built-in and its drop glue is
460 // special. It may move to library and have Drop impl. As
461 // a safe-guard, assert TyBox not used with TyContents.
462 assert!(!skip_dtor);
463 if !type_is_sized(bcx.tcx(), content_ty) {
464 let llval = GEPi(bcx, v0, &[0, abi::FAT_PTR_ADDR]);
465 let llbox = Load(bcx, llval);
466 let llbox_as_usize = PtrToInt(bcx, llbox, Type::int(bcx.ccx()));
467 let drop_flag_not_dropped_already =
468 ICmp(bcx, llvm::IntNE, llbox_as_usize, dropped_pattern, DebugLoc::None);
469 with_cond(bcx, drop_flag_not_dropped_already, |bcx| {
470 let bcx = drop_ty(bcx, v0, content_ty, DebugLoc::None);
471 let info = GEPi(bcx, v0, &[0, abi::FAT_PTR_EXTRA]);
472 let info = Load(bcx, info);
473 let (llsize, llalign) = size_and_align_of_dst(bcx, content_ty, info);
474
475 // `Box<ZeroSizeType>` does not allocate.
476 let needs_free = ICmp(bcx,
477 llvm::IntNE,
478 llsize,
479 C_uint(bcx.ccx(), 0u64),
480 DebugLoc::None);
481 with_cond(bcx, needs_free, |bcx| {
482 trans_exchange_free_dyn(bcx, llbox, llsize, llalign, DebugLoc::None)
483 })
484 })
485 } else {
486 let llval = v0;
487 let llbox = Load(bcx, llval);
488 let llbox_as_usize = PtrToInt(bcx, llbox, inttype);
489 let drop_flag_not_dropped_already =
490 ICmp(bcx, llvm::IntNE, llbox_as_usize, dropped_pattern, DebugLoc::None);
491 with_cond(bcx, drop_flag_not_dropped_already, |bcx| {
492 let bcx = drop_ty(bcx, llbox, content_ty, DebugLoc::None);
493 trans_exchange_free_ty(bcx, llbox, content_ty, DebugLoc::None)
494 })
495 }
496 }
497 ty::TyStruct(did, substs) | ty::TyEnum(did, substs) => {
498 let tcx = bcx.tcx();
499 match (ty::ty_dtor(tcx, did), skip_dtor) {
500 (ty::TraitDtor(dtor, true), false) => {
501 // FIXME(16758) Since the struct is unsized, it is hard to
502 // find the drop flag (which is at the end of the struct).
503 // Lets just ignore the flag and pretend everything will be
504 // OK.
505 if type_is_sized(bcx.tcx(), t) {
506 trans_struct_drop_flag(bcx, t, v0, dtor, did, substs)
507 } else {
508 // Give the user a heads up that we are doing something
509 // stupid and dangerous.
510 bcx.sess().warn(&format!("Ignoring drop flag in destructor for {}\
511 because the struct is unsized. See issue\
512 #16758", t));
513 trans_struct_drop(bcx, t, v0, dtor, did, substs)
514 }
515 }
516 (ty::TraitDtor(dtor, false), false) => {
517 trans_struct_drop(bcx, t, v0, dtor, did, substs)
518 }
519 (ty::NoDtor, _) | (_, true) => {
520 // No dtor? Just the default case
521 iter_structural_ty(bcx, v0, t, |bb, vv, tt| drop_ty(bb, vv, tt, DebugLoc::None))
522 }
523 }
524 }
525 ty::TyTrait(..) => {
526 // No support in vtable for distinguishing destroying with
527 // versus without calling Drop::drop. Assert caller is
528 // okay with always calling the Drop impl, if any.
529 assert!(!skip_dtor);
530 let data_ptr = GEPi(bcx, v0, &[0, abi::FAT_PTR_ADDR]);
531 let vtable_ptr = Load(bcx, GEPi(bcx, v0, &[0, abi::FAT_PTR_EXTRA]));
532 let dtor = Load(bcx, vtable_ptr);
533 Call(bcx,
534 dtor,
535 &[PointerCast(bcx, Load(bcx, data_ptr), Type::i8p(bcx.ccx()))],
536 None,
537 DebugLoc::None);
538 bcx
539 }
540 _ => {
541 if bcx.fcx.type_needs_drop(t) {
542 iter_structural_ty(bcx,
543 v0,
544 t,
545 |bb, vv, tt| drop_ty(bb, vv, tt, DebugLoc::None))
546 } else {
547 bcx
548 }
549 }
550 }
551 }