]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_ssa/mir/block.rs
Auto merge of #57760 - dlrobertson:varargs1, r=alexreg
[rust.git] / src / librustc_codegen_ssa / mir / block.rs
1 use rustc::middle::lang_items;
2 use rustc::ty::{self, Ty, TypeFoldable};
3 use rustc::ty::layout::{self, LayoutOf, HasTyCtxt};
4 use rustc::mir;
5 use rustc::mir::interpret::EvalErrorKind;
6 use rustc_target::abi::call::{ArgType, FnType, PassMode, IgnoreMode};
7 use rustc_target::spec::abi::Abi;
8 use rustc_mir::monomorphize;
9 use crate::base;
10 use crate::MemFlags;
11 use crate::common::{self, IntPredicate};
12 use crate::meth;
13
14 use crate::traits::*;
15
16 use std::borrow::Cow;
17
18 use syntax::symbol::Symbol;
19 use syntax_pos::Pos;
20
21 use super::{FunctionCx, LocalRef};
22 use super::place::PlaceRef;
23 use super::operand::{OperandValue, OperandRef};
24 use super::operand::OperandValue::{Pair, Ref, Immediate};
25
26 /// Used by `FunctionCx::codegen_terminator` for emitting common patterns
27 /// e.g., creating a basic block, calling a function, etc.
28 struct TerminatorCodegenHelper<'a, 'tcx> {
29     bb: &'a mir::BasicBlock,
30     terminator: &'a mir::Terminator<'tcx>,
31     funclet_bb: Option<mir::BasicBlock>,
32 }
33
34 impl<'a, 'tcx> TerminatorCodegenHelper<'a, 'tcx> {
35     /// Returns the associated funclet from `FunctionCx::funclets` for the
36     /// `funclet_bb` member if it is not `None`.
37     fn funclet<'c, 'b, Bx: BuilderMethods<'b, 'tcx>>(
38         &self,
39         fx: &'c mut FunctionCx<'b, 'tcx, Bx>,
40     ) -> Option<&'c Bx::Funclet> {
41         match self.funclet_bb {
42             Some(funcl) => fx.funclets[funcl].as_ref(),
43             None => None,
44         }
45     }
46
47     fn lltarget<'b, 'c, Bx: BuilderMethods<'b, 'tcx>>(
48         &self,
49         fx: &'c mut FunctionCx<'b, 'tcx, Bx>,
50         target: mir::BasicBlock,
51     ) -> (Bx::BasicBlock, bool) {
52         let span = self.terminator.source_info.span;
53         let lltarget = fx.blocks[target];
54         let target_funclet = fx.cleanup_kinds[target].funclet_bb(target);
55         match (self.funclet_bb, target_funclet) {
56             (None, None) => (lltarget, false),
57             (Some(f), Some(t_f)) if f == t_f || !base::wants_msvc_seh(fx.cx.tcx().sess) =>
58                 (lltarget, false),
59             // jump *into* cleanup - need a landing pad if GNU
60             (None, Some(_)) => (fx.landing_pad_to(target), false),
61             (Some(_), None) => span_bug!(span, "{:?} - jump out of cleanup?", self.terminator),
62             (Some(_), Some(_)) => (fx.landing_pad_to(target), true),
63         }
64     }
65
66     /// Create a basic block.
67     fn llblock<'c, 'b, Bx: BuilderMethods<'b, 'tcx>>(
68         &self,
69         fx: &'c mut FunctionCx<'b, 'tcx, Bx>,
70         target: mir::BasicBlock,
71     ) -> Bx::BasicBlock {
72         let (lltarget, is_cleanupret) = self.lltarget(fx, target);
73         if is_cleanupret {
74             // MSVC cross-funclet jump - need a trampoline
75
76             debug!("llblock: creating cleanup trampoline for {:?}", target);
77             let name = &format!("{:?}_cleanup_trampoline_{:?}", self.bb, target);
78             let mut trampoline = fx.new_block(name);
79             trampoline.cleanup_ret(self.funclet(fx).unwrap(),
80                                    Some(lltarget));
81             trampoline.llbb()
82         } else {
83             lltarget
84         }
85     }
86
87     fn funclet_br<'c, 'b, Bx: BuilderMethods<'b, 'tcx>>(
88         &self,
89         fx: &'c mut FunctionCx<'b, 'tcx, Bx>,
90         bx: &mut Bx,
91         target: mir::BasicBlock,
92     ) {
93         let (lltarget, is_cleanupret) = self.lltarget(fx, target);
94         if is_cleanupret {
95             // micro-optimization: generate a `ret` rather than a jump
96             // to a trampoline.
97             bx.cleanup_ret(self.funclet(fx).unwrap(), Some(lltarget));
98         } else {
99             bx.br(lltarget);
100         }
101     }
102
103     /// Call `fn_ptr` of `fn_ty` with the arguments `llargs`, the optional
104     /// return destination `destination` and the cleanup function `cleanup`.
105     fn do_call<'c, 'b, Bx: BuilderMethods<'b, 'tcx>>(
106         &self,
107         fx: &'c mut FunctionCx<'b, 'tcx, Bx>,
108         bx: &mut Bx,
109         fn_ty: FnType<'tcx, Ty<'tcx>>,
110         fn_ptr: Bx::Value,
111         llargs: &[Bx::Value],
112         destination: Option<(ReturnDest<'tcx, Bx::Value>, mir::BasicBlock)>,
113         cleanup: Option<mir::BasicBlock>,
114     ) {
115         if let Some(cleanup) = cleanup {
116             let ret_bx = if let Some((_, target)) = destination {
117                 fx.blocks[target]
118             } else {
119                 fx.unreachable_block()
120             };
121             let invokeret = bx.invoke(fn_ptr,
122                                       &llargs,
123                                       ret_bx,
124                                       self.llblock(fx, cleanup),
125                                       self.funclet(fx));
126             bx.apply_attrs_callsite(&fn_ty, invokeret);
127
128             if let Some((ret_dest, target)) = destination {
129                 let mut ret_bx = fx.build_block(target);
130                 fx.set_debug_loc(&mut ret_bx, self.terminator.source_info);
131                 fx.store_return(&mut ret_bx, ret_dest, &fn_ty.ret, invokeret);
132             }
133         } else {
134             let llret = bx.call(fn_ptr, &llargs, self.funclet(fx));
135             bx.apply_attrs_callsite(&fn_ty, llret);
136             if fx.mir[*self.bb].is_cleanup {
137                 // Cleanup is always the cold path. Don't inline
138                 // drop glue. Also, when there is a deeply-nested
139                 // struct, there are "symmetry" issues that cause
140                 // exponential inlining - see issue #41696.
141                 bx.do_not_inline(llret);
142             }
143
144             if let Some((ret_dest, target)) = destination {
145                 fx.store_return(bx, ret_dest, &fn_ty.ret, llret);
146                 self.funclet_br(fx, bx, target);
147             } else {
148                 bx.unreachable();
149             }
150         }
151     }
152 }
153
154 /// Codegen implementations for some terminator variants.
155 impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
156     /// Generates code for a `Resume` terminator.
157     fn codegen_resume_terminator<'b>(
158         &mut self,
159         helper: TerminatorCodegenHelper<'b, 'tcx>,
160         mut bx: Bx,
161     ) {
162         if let Some(funclet) = helper.funclet(self) {
163             bx.cleanup_ret(funclet, None);
164         } else {
165             let slot = self.get_personality_slot(&mut bx);
166             let lp0 = slot.project_field(&mut bx, 0);
167             let lp0 = bx.load_operand(lp0).immediate();
168             let lp1 = slot.project_field(&mut bx, 1);
169             let lp1 = bx.load_operand(lp1).immediate();
170             slot.storage_dead(&mut bx);
171
172             if !bx.sess().target.target.options.custom_unwind_resume {
173                 let mut lp = bx.const_undef(self.landing_pad_type());
174                 lp = bx.insert_value(lp, lp0, 0);
175                 lp = bx.insert_value(lp, lp1, 1);
176                 bx.resume(lp);
177             } else {
178                 bx.call(bx.eh_unwind_resume(), &[lp0],
179                         helper.funclet(self));
180                 bx.unreachable();
181             }
182         }
183     }
184
185     fn codegen_switchint_terminator<'b>(
186         &mut self,
187         helper: TerminatorCodegenHelper<'b, 'tcx>,
188         mut bx: Bx,
189         discr: &mir::Operand<'tcx>,
190         switch_ty: Ty<'tcx>,
191         values: &Cow<'tcx, [u128]>,
192         targets: &Vec<mir::BasicBlock>,
193     ) {
194         let discr = self.codegen_operand(&mut bx, &discr);
195         if targets.len() == 2 {
196             // If there are two targets, emit br instead of switch
197             let lltrue = helper.llblock(self, targets[0]);
198             let llfalse = helper.llblock(self, targets[1]);
199             if switch_ty == bx.tcx().types.bool {
200                 // Don't generate trivial icmps when switching on bool
201                 if let [0] = values[..] {
202                     bx.cond_br(discr.immediate(), llfalse, lltrue);
203                 } else {
204                     assert_eq!(&values[..], &[1]);
205                     bx.cond_br(discr.immediate(), lltrue, llfalse);
206                 }
207             } else {
208                 let switch_llty = bx.immediate_backend_type(
209                     bx.layout_of(switch_ty)
210                 );
211                 let llval = bx.const_uint_big(switch_llty, values[0]);
212                 let cmp = bx.icmp(IntPredicate::IntEQ, discr.immediate(), llval);
213                 bx.cond_br(cmp, lltrue, llfalse);
214             }
215         } else {
216             let (otherwise, targets) = targets.split_last().unwrap();
217             let switch = bx.switch(discr.immediate(),
218                                    helper.llblock(self, *otherwise),
219                                    values.len());
220             let switch_llty = bx.immediate_backend_type(
221                 bx.layout_of(switch_ty)
222             );
223             for (&value, target) in values.iter().zip(targets) {
224                 let llval = bx.const_uint_big(switch_llty, value);
225                 let llbb = helper.llblock(self, *target);
226                 bx.add_case(switch, llval, llbb)
227             }
228         }
229     }
230
231     fn codegen_return_terminator<'b>(
232         &mut self,
233         mut bx: Bx,
234     ) {
235         if self.fn_ty.c_variadic {
236             if let Some(va_list) = self.va_list_ref {
237                 bx.va_end(va_list.llval);
238             }
239         }
240         let llval = match self.fn_ty.ret.mode {
241             PassMode::Ignore(IgnoreMode::Zst) | PassMode::Indirect(..) => {
242                 bx.ret_void();
243                 return;
244             }
245
246             PassMode::Ignore(IgnoreMode::CVarArgs) => {
247                 bug!("C-variadic arguments should never be the return type");
248             }
249
250             PassMode::Direct(_) | PassMode::Pair(..) => {
251                 let op =
252                     self.codegen_consume(&mut bx, &mir::Place::Local(mir::RETURN_PLACE));
253                 if let Ref(llval, _, align) = op.val {
254                     bx.load(llval, align)
255                 } else {
256                     op.immediate_or_packed_pair(&mut bx)
257                 }
258             }
259
260             PassMode::Cast(cast_ty) => {
261                 let op = match self.locals[mir::RETURN_PLACE] {
262                     LocalRef::Operand(Some(op)) => op,
263                     LocalRef::Operand(None) => bug!("use of return before def"),
264                     LocalRef::Place(cg_place) => {
265                         OperandRef {
266                             val: Ref(cg_place.llval, None, cg_place.align),
267                             layout: cg_place.layout
268                         }
269                     }
270                     LocalRef::UnsizedPlace(_) => bug!("return type must be sized"),
271                 };
272                 let llslot = match op.val {
273                     Immediate(_) | Pair(..) => {
274                         let scratch =
275                             PlaceRef::alloca(&mut bx, self.fn_ty.ret.layout, "ret");
276                         op.val.store(&mut bx, scratch);
277                         scratch.llval
278                     }
279                     Ref(llval, _, align) => {
280                         assert_eq!(align, op.layout.align.abi,
281                                    "return place is unaligned!");
282                         llval
283                     }
284                 };
285                 let addr = bx.pointercast(llslot, bx.type_ptr_to(
286                     bx.cast_backend_type(&cast_ty)
287                 ));
288                 bx.load(addr, self.fn_ty.ret.layout.align.abi)
289             }
290         };
291         bx.ret(llval);
292     }
293
294
295     fn codegen_drop_terminator<'b>(
296         &mut self,
297         helper: TerminatorCodegenHelper<'b, 'tcx>,
298         mut bx: Bx,
299         location: &mir::Place<'tcx>,
300         target: mir::BasicBlock,
301         unwind: Option<mir::BasicBlock>,
302     ) {
303         let ty = location.ty(self.mir, bx.tcx()).to_ty(bx.tcx());
304         let ty = self.monomorphize(&ty);
305         let drop_fn = monomorphize::resolve_drop_in_place(bx.tcx(), ty);
306
307         if let ty::InstanceDef::DropGlue(_, None) = drop_fn.def {
308             // we don't actually need to drop anything.
309             helper.funclet_br(self, &mut bx, target);
310             return
311         }
312
313         let place = self.codegen_place(&mut bx, location);
314         let (args1, args2);
315         let mut args = if let Some(llextra) = place.llextra {
316             args2 = [place.llval, llextra];
317             &args2[..]
318         } else {
319             args1 = [place.llval];
320             &args1[..]
321         };
322         let (drop_fn, fn_ty) = match ty.sty {
323             ty::Dynamic(..) => {
324                 let sig = drop_fn.fn_sig(self.cx.tcx());
325                 let sig = self.cx.tcx().normalize_erasing_late_bound_regions(
326                     ty::ParamEnv::reveal_all(),
327                     &sig,
328                 );
329                 let fn_ty = bx.new_vtable(sig, &[]);
330                 let vtable = args[1];
331                 args = &args[..1];
332                 (meth::DESTRUCTOR.get_fn(&mut bx, vtable, &fn_ty), fn_ty)
333             }
334             _ => {
335                 (bx.get_fn(drop_fn),
336                  bx.fn_type_of_instance(&drop_fn))
337             }
338         };
339         helper.do_call(self, &mut bx, fn_ty, drop_fn, args,
340                        Some((ReturnDest::Nothing, target)),
341                        unwind);
342     }
343
344     fn codegen_assert_terminator<'b>(
345         &mut self,
346         helper: TerminatorCodegenHelper<'b, 'tcx>,
347         mut bx: Bx,
348         terminator: &mir::Terminator<'tcx>,
349         cond: &mir::Operand<'tcx>,
350         expected: bool,
351         msg: &mir::AssertMessage<'tcx>,
352         target: mir::BasicBlock,
353         cleanup: Option<mir::BasicBlock>,
354     ) {
355         let span = terminator.source_info.span;
356         let cond = self.codegen_operand(&mut bx, cond).immediate();
357         let mut const_cond = bx.const_to_opt_u128(cond, false).map(|c| c == 1);
358
359         // This case can currently arise only from functions marked
360         // with #[rustc_inherit_overflow_checks] and inlined from
361         // another crate (mostly core::num generic/#[inline] fns),
362         // while the current crate doesn't use overflow checks.
363         // NOTE: Unlike binops, negation doesn't have its own
364         // checked operation, just a comparison with the minimum
365         // value, so we have to check for the assert message.
366         if !bx.check_overflow() {
367             if let mir::interpret::EvalErrorKind::OverflowNeg = *msg {
368                 const_cond = Some(expected);
369             }
370         }
371
372         // Don't codegen the panic block if success if known.
373         if const_cond == Some(expected) {
374             helper.funclet_br(self, &mut bx, target);
375             return;
376         }
377
378         // Pass the condition through llvm.expect for branch hinting.
379         let cond = bx.expect(cond, expected);
380
381         // Create the failure block and the conditional branch to it.
382         let lltarget = helper.llblock(self, target);
383         let panic_block = self.new_block("panic");
384         if expected {
385             bx.cond_br(cond, lltarget, panic_block.llbb());
386         } else {
387             bx.cond_br(cond, panic_block.llbb(), lltarget);
388         }
389
390         // After this point, bx is the block for the call to panic.
391         bx = panic_block;
392         self.set_debug_loc(&mut bx, terminator.source_info);
393
394         // Get the location information.
395         let loc = bx.sess().source_map().lookup_char_pos(span.lo());
396         let filename = Symbol::intern(&loc.file.name.to_string()).as_str();
397         let filename = bx.const_str_slice(filename);
398         let line = bx.const_u32(loc.line as u32);
399         let col = bx.const_u32(loc.col.to_usize() as u32 + 1);
400         let align = self.cx.tcx().data_layout.aggregate_align.abi
401             .max(self.cx.tcx().data_layout.i32_align.abi)
402             .max(self.cx.tcx().data_layout.pointer_align.abi);
403
404         // Put together the arguments to the panic entry point.
405         let (lang_item, args) = match *msg {
406             EvalErrorKind::BoundsCheck { ref len, ref index } => {
407                 let len = self.codegen_operand(&mut bx, len).immediate();
408                 let index = self.codegen_operand(&mut bx, index).immediate();
409
410                 let file_line_col = bx.const_struct(&[filename, line, col], false);
411                 let file_line_col = bx.static_addr_of(
412                     file_line_col,
413                     align,
414                     Some("panic_bounds_check_loc")
415                 );
416                 (lang_items::PanicBoundsCheckFnLangItem,
417                  vec![file_line_col, index, len])
418             }
419             _ => {
420                 let str = msg.description();
421                 let msg_str = Symbol::intern(str).as_str();
422                 let msg_str = bx.const_str_slice(msg_str);
423                 let msg_file_line_col = bx.const_struct(
424                     &[msg_str, filename, line, col],
425                     false
426                 );
427                 let msg_file_line_col = bx.static_addr_of(
428                     msg_file_line_col,
429                     align,
430                     Some("panic_loc")
431                 );
432                 (lang_items::PanicFnLangItem,
433                  vec![msg_file_line_col])
434             }
435         };
436
437         // Obtain the panic entry point.
438         let def_id = common::langcall(bx.tcx(), Some(span), "", lang_item);
439         let instance = ty::Instance::mono(bx.tcx(), def_id);
440         let fn_ty = bx.fn_type_of_instance(&instance);
441         let llfn = bx.get_fn(instance);
442
443         // Codegen the actual panic invoke/call.
444         helper.do_call(self, &mut bx, fn_ty, llfn, &args, None, cleanup);
445     }
446
447     fn codegen_call_terminator<'b>(
448         &mut self,
449         helper: TerminatorCodegenHelper<'b, 'tcx>,
450         mut bx: Bx,
451         terminator: &mir::Terminator<'tcx>,
452         func: &mir::Operand<'tcx>,
453         args: &Vec<mir::Operand<'tcx>>,
454         destination: &Option<(mir::Place<'tcx>, mir::BasicBlock)>,
455         cleanup: Option<mir::BasicBlock>,
456     ) {
457         let span = terminator.source_info.span;
458         // Create the callee. This is a fn ptr or zero-sized and hence a kind of scalar.
459         let callee = self.codegen_operand(&mut bx, func);
460
461         let (instance, mut llfn) = match callee.layout.ty.sty {
462             ty::FnDef(def_id, substs) => {
463                 (Some(ty::Instance::resolve(bx.tcx(),
464                                             ty::ParamEnv::reveal_all(),
465                                             def_id,
466                                             substs).unwrap()),
467                  None)
468             }
469             ty::FnPtr(_) => {
470                 (None, Some(callee.immediate()))
471             }
472             _ => bug!("{} is not callable", callee.layout.ty),
473         };
474         let def = instance.map(|i| i.def);
475         let sig = callee.layout.ty.fn_sig(bx.tcx());
476         let sig = bx.tcx().normalize_erasing_late_bound_regions(
477             ty::ParamEnv::reveal_all(),
478             &sig,
479         );
480         let abi = sig.abi;
481
482         // Handle intrinsics old codegen wants Expr's for, ourselves.
483         let intrinsic = match def {
484             Some(ty::InstanceDef::Intrinsic(def_id)) =>
485                 Some(bx.tcx().item_name(def_id).as_str()),
486             _ => None
487         };
488         let intrinsic = intrinsic.as_ref().map(|s| &s[..]);
489
490         if intrinsic == Some("transmute") {
491             if let Some(destination_ref) = destination.as_ref() {
492                 let &(ref dest, target) = destination_ref;
493                 self.codegen_transmute(&mut bx, &args[0], dest);
494                 helper.funclet_br(self, &mut bx, target);
495             } else {
496                 // If we are trying to transmute to an uninhabited type,
497                 // it is likely there is no allotted destination. In fact,
498                 // transmuting to an uninhabited type is UB, which means
499                 // we can do what we like. Here, we declare that transmuting
500                 // into an uninhabited type is impossible, so anything following
501                 // it must be unreachable.
502                 assert_eq!(bx.layout_of(sig.output()).abi, layout::Abi::Uninhabited);
503                 bx.unreachable();
504             }
505             return;
506         }
507
508         // The "spoofed" `VaList` added to a C-variadic functions signature
509         // should not be included in the `extra_args` calculation.
510         let extra_args_start_idx = sig.inputs().len() - if sig.c_variadic { 1 } else { 0 };
511         let extra_args = &args[extra_args_start_idx..];
512         let extra_args = extra_args.iter().map(|op_arg| {
513             let op_ty = op_arg.ty(self.mir, bx.tcx());
514             self.monomorphize(&op_ty)
515         }).collect::<Vec<_>>();
516
517         let fn_ty = match def {
518             Some(ty::InstanceDef::Virtual(..)) => {
519                 bx.new_vtable(sig, &extra_args)
520             }
521             Some(ty::InstanceDef::DropGlue(_, None)) => {
522                 // Empty drop glue; a no-op.
523                 let &(_, target) = destination.as_ref().unwrap();
524                 helper.funclet_br(self, &mut bx, target);
525                 return;
526             }
527             _ => bx.new_fn_type(sig, &extra_args)
528         };
529
530         // Emit a panic or a no-op for `panic_if_uninhabited`.
531         if intrinsic == Some("panic_if_uninhabited") {
532             let ty = instance.unwrap().substs.type_at(0);
533             let layout = bx.layout_of(ty);
534             if layout.abi.is_uninhabited() {
535                 let loc = bx.sess().source_map().lookup_char_pos(span.lo());
536                 let filename = Symbol::intern(&loc.file.name.to_string()).as_str();
537                 let filename = bx.const_str_slice(filename);
538                 let line = bx.const_u32(loc.line as u32);
539                 let col = bx.const_u32(loc.col.to_usize() as u32 + 1);
540                 let align = self.cx.tcx().data_layout.aggregate_align.abi
541                     .max(self.cx.tcx().data_layout.i32_align.abi)
542                     .max(self.cx.tcx().data_layout.pointer_align.abi);
543
544                 let str = format!(
545                     "Attempted to instantiate uninhabited type {}",
546                     ty
547                 );
548                 let msg_str = Symbol::intern(&str).as_str();
549                 let msg_str = bx.const_str_slice(msg_str);
550                 let msg_file_line_col = bx.const_struct(
551                     &[msg_str, filename, line, col],
552                     false,
553                 );
554                 let msg_file_line_col = bx.static_addr_of(
555                     msg_file_line_col,
556                     align,
557                     Some("panic_loc"),
558                 );
559
560                 // Obtain the panic entry point.
561                 let def_id =
562                     common::langcall(bx.tcx(), Some(span), "", lang_items::PanicFnLangItem);
563                 let instance = ty::Instance::mono(bx.tcx(), def_id);
564                 let fn_ty = bx.fn_type_of_instance(&instance);
565                 let llfn = bx.get_fn(instance);
566
567                 // Codegen the actual panic invoke/call.
568                 helper.do_call(
569                     self,
570                     &mut bx,
571                     fn_ty,
572                     llfn,
573                     &[msg_file_line_col],
574                     destination.as_ref().map(|(_, bb)| (ReturnDest::Nothing, *bb)),
575                     cleanup,
576                 );
577             } else {
578                 // a NOP
579                 helper.funclet_br(self, &mut bx, destination.as_ref().unwrap().1)
580             }
581             return;
582         }
583
584         // The arguments we'll be passing. Plus one to account for outptr, if used.
585         let arg_count = fn_ty.args.len() + fn_ty.ret.is_indirect() as usize;
586         let mut llargs = Vec::with_capacity(arg_count);
587
588         // Prepare the return value destination
589         let ret_dest = if let Some((ref dest, _)) = *destination {
590             let is_intrinsic = intrinsic.is_some();
591             self.make_return_dest(&mut bx, dest, &fn_ty.ret, &mut llargs,
592                                   is_intrinsic)
593         } else {
594             ReturnDest::Nothing
595         };
596
597         if intrinsic.is_some() && intrinsic != Some("drop_in_place") {
598             let dest = match ret_dest {
599                 _ if fn_ty.ret.is_indirect() => llargs[0],
600                 ReturnDest::Nothing =>
601                     bx.const_undef(bx.type_ptr_to(bx.memory_ty(&fn_ty.ret))),
602                 ReturnDest::IndirectOperand(dst, _) | ReturnDest::Store(dst) =>
603                     dst.llval,
604                 ReturnDest::DirectOperand(_) =>
605                     bug!("Cannot use direct operand with an intrinsic call"),
606             };
607
608             let args: Vec<_> = args.iter().enumerate().map(|(i, arg)| {
609                 // The indices passed to simd_shuffle* in the
610                 // third argument must be constant. This is
611                 // checked by const-qualification, which also
612                 // promotes any complex rvalues to constants.
613                 if i == 2 && intrinsic.unwrap().starts_with("simd_shuffle") {
614                     match *arg {
615                         // The shuffle array argument is usually not an explicit constant,
616                         // but specified directly in the code. This means it gets promoted
617                         // and we can then extract the value by evaluating the promoted.
618                         mir::Operand::Copy(mir::Place::Promoted(box(index, ty))) |
619                         mir::Operand::Move(mir::Place::Promoted(box(index, ty))) => {
620                             let param_env = ty::ParamEnv::reveal_all();
621                             let cid = mir::interpret::GlobalId {
622                                 instance: self.instance,
623                                 promoted: Some(index),
624                             };
625                             let c = bx.tcx().const_eval(param_env.and(cid));
626                             let (llval, ty) = self.simd_shuffle_indices(
627                                 &bx,
628                                 terminator.source_info.span,
629                                 ty,
630                                 c,
631                             );
632                             return OperandRef {
633                                 val: Immediate(llval),
634                                 layout: bx.layout_of(ty),
635                             };
636
637                         }
638                         mir::Operand::Copy(_) |
639                         mir::Operand::Move(_) => {
640                             span_bug!(span, "shuffle indices must be constant");
641                         }
642                         mir::Operand::Constant(ref constant) => {
643                             let c = self.eval_mir_constant(&bx, constant);
644                             let (llval, ty) = self.simd_shuffle_indices(
645                                 &bx,
646                                 constant.span,
647                                 constant.ty,
648                                 c,
649                             );
650                             return OperandRef {
651                                 val: Immediate(llval),
652                                 layout: bx.layout_of(ty)
653                             };
654                         }
655                     }
656                 }
657
658                 self.codegen_operand(&mut bx, arg)
659             }).collect();
660
661
662             let callee_ty = instance.as_ref().unwrap().ty(bx.tcx());
663             bx.codegen_intrinsic_call(callee_ty, &fn_ty, &args, dest,
664                                       terminator.source_info.span);
665
666             if let ReturnDest::IndirectOperand(dst, _) = ret_dest {
667                 self.store_return(&mut bx, ret_dest, &fn_ty.ret, dst.llval);
668             }
669
670             if let Some((_, target)) = *destination {
671                 helper.funclet_br(self, &mut bx, target);
672             } else {
673                 bx.unreachable();
674             }
675
676             return;
677         }
678
679         // Split the rust-call tupled arguments off.
680         let (first_args, untuple) = if abi == Abi::RustCall && !args.is_empty() {
681             let (tup, args) = args.split_last().unwrap();
682             (args, Some(tup))
683         } else {
684             (&args[..], None)
685         };
686
687         // Useful determining if the current argument is the "spoofed" `VaList`
688         let last_arg_idx = if sig.inputs().is_empty() {
689             None
690         } else {
691             Some(sig.inputs().len() - 1)
692         };
693         'make_args: for (i, arg) in first_args.iter().enumerate() {
694             // If this is a C-variadic function the function signature contains
695             // an "spoofed" `VaList`. This argument is ignored, but we need to
696             // populate it with a dummy operand so that the users real arguments
697             // are not overwritten.
698             let i = if sig.c_variadic && last_arg_idx.map(|x| x == i).unwrap_or(false) {
699                 let layout = match self.cx.tcx().lang_items().va_list() {
700                     Some(did) => bx.cx().layout_of(bx.tcx().type_of(did)),
701                     None => bug!("`va_list` language item required for C-variadics"),
702                 };
703                 let op = OperandRef {
704                     val: OperandValue::Immediate(
705                         bx.cx().const_undef(bx.cx().immediate_backend_type(layout)
706                     )),
707                     layout: layout,
708                 };
709                 self.codegen_argument(&mut bx, op, &mut llargs, &fn_ty.args[i]);
710                 if i + 1 < fn_ty.args.len() {
711                     i + 1
712                 } else {
713                     break 'make_args
714                 }
715             } else {
716                 i
717             };
718             let mut op = self.codegen_operand(&mut bx, arg);
719
720             if let (0, Some(ty::InstanceDef::Virtual(_, idx))) = (i, def) {
721                 if let Pair(..) = op.val {
722                     // In the case of Rc<Self>, we need to explicitly pass a
723                     // *mut RcBox<Self> with a Scalar (not ScalarPair) ABI. This is a hack
724                     // that is understood elsewhere in the compiler as a method on
725                     // `dyn Trait`.
726                     // To get a `*mut RcBox<Self>`, we just keep unwrapping newtypes until
727                     // we get a value of a built-in pointer type
728                     'descend_newtypes: while !op.layout.ty.is_unsafe_ptr()
729                                     && !op.layout.ty.is_region_ptr()
730                     {
731                         'iter_fields: for i in 0..op.layout.fields.count() {
732                             let field = op.extract_field(&mut bx, i);
733                             if !field.layout.is_zst() {
734                                 // we found the one non-zero-sized field that is allowed
735                                 // now find *its* non-zero-sized field, or stop if it's a
736                                 // pointer
737                                 op = field;
738                                 continue 'descend_newtypes
739                             }
740                         }
741
742                         span_bug!(span, "receiver has no non-zero-sized fields {:?}", op);
743                     }
744
745                     // now that we have `*dyn Trait` or `&dyn Trait`, split it up into its
746                     // data pointer and vtable. Look up the method in the vtable, and pass
747                     // the data pointer as the first argument
748                     match op.val {
749                         Pair(data_ptr, meta) => {
750                             llfn = Some(meth::VirtualIndex::from_index(idx)
751                                 .get_fn(&mut bx, meta, &fn_ty));
752                             llargs.push(data_ptr);
753                             continue 'make_args
754                         }
755                         other => bug!("expected a Pair, got {:?}", other),
756                     }
757                 } else if let Ref(data_ptr, Some(meta), _) = op.val {
758                     // by-value dynamic dispatch
759                     llfn = Some(meth::VirtualIndex::from_index(idx)
760                         .get_fn(&mut bx, meta, &fn_ty));
761                     llargs.push(data_ptr);
762                     continue;
763                 } else {
764                     span_bug!(span, "can't codegen a virtual call on {:?}", op);
765                 }
766             }
767
768             // The callee needs to own the argument memory if we pass it
769             // by-ref, so make a local copy of non-immediate constants.
770             match (arg, op.val) {
771                 (&mir::Operand::Copy(_), Ref(_, None, _)) |
772                 (&mir::Operand::Constant(_), Ref(_, None, _)) => {
773                     let tmp = PlaceRef::alloca(&mut bx, op.layout, "const");
774                     op.val.store(&mut bx, tmp);
775                     op.val = Ref(tmp.llval, None, tmp.align);
776                 }
777                 _ => {}
778             }
779
780             self.codegen_argument(&mut bx, op, &mut llargs, &fn_ty.args[i]);
781         }
782         if let Some(tup) = untuple {
783             self.codegen_arguments_untupled(&mut bx, tup, &mut llargs,
784                 &fn_ty.args[first_args.len()..])
785         }
786
787         let fn_ptr = match (llfn, instance) {
788             (Some(llfn), _) => llfn,
789             (None, Some(instance)) => bx.get_fn(instance),
790             _ => span_bug!(span, "no llfn for call"),
791         };
792
793         helper.do_call(self, &mut bx, fn_ty, fn_ptr, &llargs,
794                        destination.as_ref().map(|&(_, target)| (ret_dest, target)),
795                        cleanup);
796     }
797 }
798
799 impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
800     pub fn codegen_block(
801         &mut self,
802         bb: mir::BasicBlock,
803     ) {
804         let mut bx = self.build_block(bb);
805         let data = &self.mir[bb];
806
807         debug!("codegen_block({:?}={:?})", bb, data);
808
809         for statement in &data.statements {
810             bx = self.codegen_statement(bx, statement);
811         }
812
813         self.codegen_terminator(bx, bb, data.terminator());
814     }
815
816     fn codegen_terminator(
817         &mut self,
818         mut bx: Bx,
819         bb: mir::BasicBlock,
820         terminator: &mir::Terminator<'tcx>
821     ) {
822         debug!("codegen_terminator: {:?}", terminator);
823
824         // Create the cleanup bundle, if needed.
825         let funclet_bb = self.cleanup_kinds[bb].funclet_bb(bb);
826         let helper = TerminatorCodegenHelper {
827             bb: &bb, terminator, funclet_bb
828         };
829
830         self.set_debug_loc(&mut bx, terminator.source_info);
831         match terminator.kind {
832             mir::TerminatorKind::Resume => {
833                 self.codegen_resume_terminator(helper, bx)
834             }
835
836             mir::TerminatorKind::Abort => {
837                 bx.abort();
838                 bx.unreachable();
839             }
840
841             mir::TerminatorKind::Goto { target } => {
842                 helper.funclet_br(self, &mut bx, target);
843             }
844
845             mir::TerminatorKind::SwitchInt {
846                 ref discr, switch_ty, ref values, ref targets
847             } => {
848                 self.codegen_switchint_terminator(helper, bx, discr, switch_ty,
849                                                   values, targets);
850             }
851
852             mir::TerminatorKind::Return => {
853                 self.codegen_return_terminator(bx);
854             }
855
856             mir::TerminatorKind::Unreachable => {
857                 bx.unreachable();
858             }
859
860             mir::TerminatorKind::Drop { ref location, target, unwind } => {
861                 self.codegen_drop_terminator(helper, bx, location, target, unwind);
862             }
863
864             mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, cleanup } => {
865                 self.codegen_assert_terminator(helper, bx, terminator, cond,
866                                                expected, msg, target, cleanup);
867             }
868
869             mir::TerminatorKind::DropAndReplace { .. } => {
870                 bug!("undesugared DropAndReplace in codegen: {:?}", terminator);
871             }
872
873             mir::TerminatorKind::Call {
874                 ref func,
875                 ref args,
876                 ref destination,
877                 cleanup,
878                 from_hir_call: _
879             } => {
880                 self.codegen_call_terminator(helper, bx, terminator, func,
881                                              args, destination, cleanup);
882             }
883             mir::TerminatorKind::GeneratorDrop |
884             mir::TerminatorKind::Yield { .. } => bug!("generator ops in codegen"),
885             mir::TerminatorKind::FalseEdges { .. } |
886             mir::TerminatorKind::FalseUnwind { .. } => bug!("borrowck false edges in codegen"),
887         }
888     }
889
890     fn codegen_argument(
891         &mut self,
892         bx: &mut Bx,
893         op: OperandRef<'tcx, Bx::Value>,
894         llargs: &mut Vec<Bx::Value>,
895         arg: &ArgType<'tcx, Ty<'tcx>>
896     ) {
897         // Fill padding with undef value, where applicable.
898         if let Some(ty) = arg.pad {
899             llargs.push(bx.const_undef(bx.reg_backend_type(&ty)))
900         }
901
902         if arg.is_ignore() {
903             return;
904         }
905
906         if let PassMode::Pair(..) = arg.mode {
907             match op.val {
908                 Pair(a, b) => {
909                     llargs.push(a);
910                     llargs.push(b);
911                     return;
912                 }
913                 _ => bug!("codegen_argument: {:?} invalid for pair argument", op)
914             }
915         } else if arg.is_unsized_indirect() {
916             match op.val {
917                 Ref(a, Some(b), _) => {
918                     llargs.push(a);
919                     llargs.push(b);
920                     return;
921                 }
922                 _ => bug!("codegen_argument: {:?} invalid for unsized indirect argument", op)
923             }
924         }
925
926         // Force by-ref if we have to load through a cast pointer.
927         let (mut llval, align, by_ref) = match op.val {
928             Immediate(_) | Pair(..) => {
929                 match arg.mode {
930                     PassMode::Indirect(..) | PassMode::Cast(_) => {
931                         let scratch = PlaceRef::alloca(bx, arg.layout, "arg");
932                         op.val.store(bx, scratch);
933                         (scratch.llval, scratch.align, true)
934                     }
935                     _ => {
936                         (op.immediate_or_packed_pair(bx), arg.layout.align.abi, false)
937                     }
938                 }
939             }
940             Ref(llval, _, align) => {
941                 if arg.is_indirect() && align < arg.layout.align.abi {
942                     // `foo(packed.large_field)`. We can't pass the (unaligned) field directly. I
943                     // think that ATM (Rust 1.16) we only pass temporaries, but we shouldn't
944                     // have scary latent bugs around.
945
946                     let scratch = PlaceRef::alloca(bx, arg.layout, "arg");
947                     base::memcpy_ty(bx, scratch.llval, scratch.align, llval, align,
948                                     op.layout, MemFlags::empty());
949                     (scratch.llval, scratch.align, true)
950                 } else {
951                     (llval, align, true)
952                 }
953             }
954         };
955
956         if by_ref && !arg.is_indirect() {
957             // Have to load the argument, maybe while casting it.
958             if let PassMode::Cast(ty) = arg.mode {
959                 let addr = bx.pointercast(llval, bx.type_ptr_to(
960                     bx.cast_backend_type(&ty))
961                 );
962                 llval = bx.load(addr, align.min(arg.layout.align.abi));
963             } else {
964                 // We can't use `PlaceRef::load` here because the argument
965                 // may have a type we don't treat as immediate, but the ABI
966                 // used for this call is passing it by-value. In that case,
967                 // the load would just produce `OperandValue::Ref` instead
968                 // of the `OperandValue::Immediate` we need for the call.
969                 llval = bx.load(llval, align);
970                 if let layout::Abi::Scalar(ref scalar) = arg.layout.abi {
971                     if scalar.is_bool() {
972                         bx.range_metadata(llval, 0..2);
973                     }
974                 }
975                 // We store bools as i8 so we need to truncate to i1.
976                 llval = base::to_immediate(bx, llval, arg.layout);
977             }
978         }
979
980         llargs.push(llval);
981     }
982
983     fn codegen_arguments_untupled(
984         &mut self,
985         bx: &mut Bx,
986         operand: &mir::Operand<'tcx>,
987         llargs: &mut Vec<Bx::Value>,
988         args: &[ArgType<'tcx, Ty<'tcx>>]
989     ) {
990         let tuple = self.codegen_operand(bx, operand);
991
992         // Handle both by-ref and immediate tuples.
993         if let Ref(llval, None, align) = tuple.val {
994             let tuple_ptr = PlaceRef::new_sized(llval, tuple.layout, align);
995             for i in 0..tuple.layout.fields.count() {
996                 let field_ptr = tuple_ptr.project_field(bx, i);
997                 let field = bx.load_operand(field_ptr);
998                 self.codegen_argument(bx, field, llargs, &args[i]);
999             }
1000         } else if let Ref(_, Some(_), _) = tuple.val {
1001             bug!("closure arguments must be sized")
1002         } else {
1003             // If the tuple is immediate, the elements are as well.
1004             for i in 0..tuple.layout.fields.count() {
1005                 let op = tuple.extract_field(bx, i);
1006                 self.codegen_argument(bx, op, llargs, &args[i]);
1007             }
1008         }
1009     }
1010
1011     fn get_personality_slot(
1012         &mut self,
1013         bx: &mut Bx
1014     ) -> PlaceRef<'tcx, Bx::Value> {
1015         let cx = bx.cx();
1016         if let Some(slot) = self.personality_slot {
1017             slot
1018         } else {
1019             let layout = cx.layout_of(cx.tcx().intern_tup(&[
1020                 cx.tcx().mk_mut_ptr(cx.tcx().types.u8),
1021                 cx.tcx().types.i32
1022             ]));
1023             let slot = PlaceRef::alloca(bx, layout, "personalityslot");
1024             self.personality_slot = Some(slot);
1025             slot
1026         }
1027     }
1028
1029     /// Returns the landing-pad wrapper around the given basic block.
1030     ///
1031     /// No-op in MSVC SEH scheme.
1032     fn landing_pad_to(
1033         &mut self,
1034         target_bb: mir::BasicBlock
1035     ) -> Bx::BasicBlock {
1036         if let Some(block) = self.landing_pads[target_bb] {
1037             return block;
1038         }
1039
1040         let block = self.blocks[target_bb];
1041         let landing_pad = self.landing_pad_uncached(block);
1042         self.landing_pads[target_bb] = Some(landing_pad);
1043         landing_pad
1044     }
1045
1046     fn landing_pad_uncached(
1047         &mut self,
1048         target_bb: Bx::BasicBlock
1049     ) -> Bx::BasicBlock {
1050         if base::wants_msvc_seh(self.cx.sess()) {
1051             span_bug!(self.mir.span, "landing pad was not inserted?")
1052         }
1053
1054         let mut bx = self.new_block("cleanup");
1055
1056         let llpersonality = self.cx.eh_personality();
1057         let llretty = self.landing_pad_type();
1058         let lp = bx.landing_pad(llretty, llpersonality, 1);
1059         bx.set_cleanup(lp);
1060
1061         let slot = self.get_personality_slot(&mut bx);
1062         slot.storage_live(&mut bx);
1063         Pair(bx.extract_value(lp, 0), bx.extract_value(lp, 1)).store(&mut bx, slot);
1064
1065         bx.br(target_bb);
1066         bx.llbb()
1067     }
1068
1069     fn landing_pad_type(&self) -> Bx::Type {
1070         let cx = self.cx;
1071         cx.type_struct(&[cx.type_i8p(), cx.type_i32()], false)
1072     }
1073
1074     fn unreachable_block(
1075         &mut self
1076     ) -> Bx::BasicBlock {
1077         self.unreachable_block.unwrap_or_else(|| {
1078             let mut bx = self.new_block("unreachable");
1079             bx.unreachable();
1080             self.unreachable_block = Some(bx.llbb());
1081             bx.llbb()
1082         })
1083     }
1084
1085     pub fn new_block(&self, name: &str) -> Bx {
1086         Bx::new_block(self.cx, self.llfn, name)
1087     }
1088
1089     pub fn build_block(
1090         &self,
1091         bb: mir::BasicBlock
1092     ) -> Bx {
1093         let mut bx = Bx::with_cx(self.cx);
1094         bx.position_at_end(self.blocks[bb]);
1095         bx
1096     }
1097
1098     fn make_return_dest(
1099         &mut self,
1100         bx: &mut Bx,
1101         dest: &mir::Place<'tcx>,
1102         fn_ret: &ArgType<'tcx, Ty<'tcx>>,
1103         llargs: &mut Vec<Bx::Value>, is_intrinsic: bool
1104     ) -> ReturnDest<'tcx, Bx::Value> {
1105         // If the return is ignored, we can just return a do-nothing ReturnDest
1106         if fn_ret.is_ignore() {
1107             return ReturnDest::Nothing;
1108         }
1109         let dest = if let mir::Place::Local(index) = *dest {
1110             match self.locals[index] {
1111                 LocalRef::Place(dest) => dest,
1112                 LocalRef::UnsizedPlace(_) => bug!("return type must be sized"),
1113                 LocalRef::Operand(None) => {
1114                     // Handle temporary places, specifically Operand ones, as
1115                     // they don't have allocas
1116                     return if fn_ret.is_indirect() {
1117                         // Odd, but possible, case, we have an operand temporary,
1118                         // but the calling convention has an indirect return.
1119                         let tmp = PlaceRef::alloca(bx, fn_ret.layout, "tmp_ret");
1120                         tmp.storage_live(bx);
1121                         llargs.push(tmp.llval);
1122                         ReturnDest::IndirectOperand(tmp, index)
1123                     } else if is_intrinsic {
1124                         // Currently, intrinsics always need a location to store
1125                         // the result. so we create a temporary alloca for the
1126                         // result
1127                         let tmp = PlaceRef::alloca(bx, fn_ret.layout, "tmp_ret");
1128                         tmp.storage_live(bx);
1129                         ReturnDest::IndirectOperand(tmp, index)
1130                     } else {
1131                         ReturnDest::DirectOperand(index)
1132                     };
1133                 }
1134                 LocalRef::Operand(Some(_)) => {
1135                     bug!("place local already assigned to");
1136                 }
1137             }
1138         } else {
1139             self.codegen_place(bx, dest)
1140         };
1141         if fn_ret.is_indirect() {
1142             if dest.align < dest.layout.align.abi {
1143                 // Currently, MIR code generation does not create calls
1144                 // that store directly to fields of packed structs (in
1145                 // fact, the calls it creates write only to temps),
1146                 //
1147                 // If someone changes that, please update this code path
1148                 // to create a temporary.
1149                 span_bug!(self.mir.span, "can't directly store to unaligned value");
1150             }
1151             llargs.push(dest.llval);
1152             ReturnDest::Nothing
1153         } else {
1154             ReturnDest::Store(dest)
1155         }
1156     }
1157
1158     fn codegen_transmute(
1159         &mut self,
1160         bx: &mut Bx,
1161         src: &mir::Operand<'tcx>,
1162         dst: &mir::Place<'tcx>
1163     ) {
1164         if let mir::Place::Local(index) = *dst {
1165             match self.locals[index] {
1166                 LocalRef::Place(place) => self.codegen_transmute_into(bx, src, place),
1167                 LocalRef::UnsizedPlace(_) => bug!("transmute must not involve unsized locals"),
1168                 LocalRef::Operand(None) => {
1169                     let dst_layout = bx.layout_of(self.monomorphized_place_ty(dst));
1170                     assert!(!dst_layout.ty.has_erasable_regions());
1171                     let place = PlaceRef::alloca(bx, dst_layout, "transmute_temp");
1172                     place.storage_live(bx);
1173                     self.codegen_transmute_into(bx, src, place);
1174                     let op = bx.load_operand(place);
1175                     place.storage_dead(bx);
1176                     self.locals[index] = LocalRef::Operand(Some(op));
1177                 }
1178                 LocalRef::Operand(Some(op)) => {
1179                     assert!(op.layout.is_zst(),
1180                             "assigning to initialized SSAtemp");
1181                 }
1182             }
1183         } else {
1184             let dst = self.codegen_place(bx, dst);
1185             self.codegen_transmute_into(bx, src, dst);
1186         }
1187     }
1188
1189     fn codegen_transmute_into(
1190         &mut self,
1191         bx: &mut Bx,
1192         src: &mir::Operand<'tcx>,
1193         dst: PlaceRef<'tcx, Bx::Value>
1194     ) {
1195         let src = self.codegen_operand(bx, src);
1196         let llty = bx.backend_type(src.layout);
1197         let cast_ptr = bx.pointercast(dst.llval, bx.type_ptr_to(llty));
1198         let align = src.layout.align.abi.min(dst.align);
1199         src.val.store(bx, PlaceRef::new_sized(cast_ptr, src.layout, align));
1200     }
1201
1202
1203     // Stores the return value of a function call into it's final location.
1204     fn store_return(
1205         &mut self,
1206         bx: &mut Bx,
1207         dest: ReturnDest<'tcx, Bx::Value>,
1208         ret_ty: &ArgType<'tcx, Ty<'tcx>>,
1209         llval: Bx::Value
1210     ) {
1211         use self::ReturnDest::*;
1212
1213         match dest {
1214             Nothing => (),
1215             Store(dst) => bx.store_arg_ty(&ret_ty, llval, dst),
1216             IndirectOperand(tmp, index) => {
1217                 let op = bx.load_operand(tmp);
1218                 tmp.storage_dead(bx);
1219                 self.locals[index] = LocalRef::Operand(Some(op));
1220             }
1221             DirectOperand(index) => {
1222                 // If there is a cast, we have to store and reload.
1223                 let op = if let PassMode::Cast(_) = ret_ty.mode {
1224                     let tmp = PlaceRef::alloca(bx, ret_ty.layout, "tmp_ret");
1225                     tmp.storage_live(bx);
1226                     bx.store_arg_ty(&ret_ty, llval, tmp);
1227                     let op = bx.load_operand(tmp);
1228                     tmp.storage_dead(bx);
1229                     op
1230                 } else {
1231                     OperandRef::from_immediate_or_packed_pair(bx, llval, ret_ty.layout)
1232                 };
1233                 self.locals[index] = LocalRef::Operand(Some(op));
1234             }
1235         }
1236     }
1237 }
1238
1239 enum ReturnDest<'tcx, V> {
1240     // Do nothing, the return value is indirect or ignored
1241     Nothing,
1242     // Store the return value to the pointer
1243     Store(PlaceRef<'tcx, V>),
1244     // Stores an indirect return value to an operand local place
1245     IndirectOperand(PlaceRef<'tcx, V>, mir::Local),
1246     // Stores a direct return value to an operand local place
1247     DirectOperand(mir::Local)
1248 }