1 // Copyright 2012-2016 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.
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.
11 use llvm::{self, AttributePlace};
13 use builder::{Builder, MemFlags};
14 use common::{ty_fn_sig, C_usize};
15 use context::CodegenCx;
16 use mir::place::PlaceRef;
17 use mir::operand::OperandValue;
19 use type_of::{LayoutLlvmExt, PointerKind};
22 use rustc_target::abi::{LayoutOf, Size, TyLayout};
23 use rustc::ty::{self, Ty};
24 use rustc::ty::layout;
28 pub use rustc_target::spec::abi::Abi;
29 pub use rustc::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA};
30 pub use rustc_target::abi::call::*;
32 macro_rules! for_each_kind {
33 ($flags: ident, $f: ident, $($kind: ident),+) => ({
34 $(if $flags.contains(ArgAttribute::$kind) { $f(llvm::Attribute::$kind) })+
38 trait ArgAttributeExt {
39 fn for_each_kind<F>(&self, f: F) where F: FnMut(llvm::Attribute);
42 impl ArgAttributeExt for ArgAttribute {
43 fn for_each_kind<F>(&self, mut f: F) where F: FnMut(llvm::Attribute) {
44 for_each_kind!(self, f,
45 ByVal, NoAlias, NoCapture, NonNull, ReadOnly, SExt, StructRet, ZExt, InReg)
49 pub trait ArgAttributesExt {
50 fn apply_llfn(&self, idx: AttributePlace, llfn: &Value);
51 fn apply_callsite(&self, idx: AttributePlace, callsite: &Value);
54 impl ArgAttributesExt for ArgAttributes {
55 fn apply_llfn(&self, idx: AttributePlace, llfn: &Value) {
56 let mut regular = self.regular;
58 let deref = self.pointee_size.bytes();
60 if regular.contains(ArgAttribute::NonNull) {
61 llvm::LLVMRustAddDereferenceableAttr(llfn,
65 llvm::LLVMRustAddDereferenceableOrNullAttr(llfn,
69 regular -= ArgAttribute::NonNull;
71 if let Some(align) = self.pointee_align {
72 llvm::LLVMRustAddAlignmentAttr(llfn,
76 regular.for_each_kind(|attr| attr.apply_llfn(idx, llfn));
80 fn apply_callsite(&self, idx: AttributePlace, callsite: &Value) {
81 let mut regular = self.regular;
83 let deref = self.pointee_size.bytes();
85 if regular.contains(ArgAttribute::NonNull) {
86 llvm::LLVMRustAddDereferenceableCallSiteAttr(callsite,
90 llvm::LLVMRustAddDereferenceableOrNullCallSiteAttr(callsite,
94 regular -= ArgAttribute::NonNull;
96 if let Some(align) = self.pointee_align {
97 llvm::LLVMRustAddAlignmentCallSiteAttr(callsite,
101 regular.for_each_kind(|attr| attr.apply_callsite(idx, callsite));
107 fn llvm_type(&self, cx: &CodegenCx<'ll, '_>) -> &'ll Type;
110 impl LlvmType for Reg {
111 fn llvm_type(&self, cx: &CodegenCx<'ll, '_>) -> &'ll Type {
113 RegKind::Integer => Type::ix(cx, self.size.bits()),
115 match self.size.bits() {
118 _ => bug!("unsupported float: {:?}", self)
122 Type::vector(Type::i8(cx), self.size.bytes())
128 impl LlvmType for CastTarget {
129 fn llvm_type(&self, cx: &CodegenCx<'ll, '_>) -> &'ll Type {
130 let rest_ll_unit = self.rest.unit.llvm_type(cx);
131 let (rest_count, rem_bytes) = if self.rest.unit.size.bytes() == 0 {
134 (self.rest.total.bytes() / self.rest.unit.size.bytes(),
135 self.rest.total.bytes() % self.rest.unit.size.bytes())
138 if self.prefix.iter().all(|x| x.is_none()) {
139 // Simplify to a single unit when there is no prefix and size <= unit size
140 if self.rest.total <= self.rest.unit.size {
144 // Simplify to array when all chunks are the same size and type
146 return Type::array(rest_ll_unit, rest_count);
150 // Create list of fields in the main structure
151 let mut args: Vec<_> =
152 self.prefix.iter().flat_map(|option_kind| option_kind.map(
153 |kind| Reg { kind: kind, size: self.prefix_chunk }.llvm_type(cx)))
154 .chain((0..rest_count).map(|_| rest_ll_unit))
157 // Append final integer
159 // Only integers can be really split further.
160 assert_eq!(self.rest.unit.kind, RegKind::Integer);
161 args.push(Type::ix(cx, rem_bytes * 8));
164 Type::struct_(cx, &args, false)
168 pub trait ArgTypeExt<'ll, 'tcx> {
169 fn memory_ty(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
170 fn store(&self, bx: &Builder<'_, 'll, 'tcx>, val: &'ll Value, dst: PlaceRef<'ll, 'tcx>);
171 fn store_fn_arg(&self, bx: &Builder<'_, 'll, 'tcx>, idx: &mut usize, dst: PlaceRef<'ll, 'tcx>);
174 impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
175 /// Get the LLVM type for a place of the original Rust type of
176 /// this argument/return, i.e. the result of `type_of::type_of`.
177 fn memory_ty(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type {
178 self.layout.llvm_type(cx)
181 /// Store a direct/indirect value described by this ArgType into a
182 /// place for the original Rust type of this argument/return.
183 /// Can be used for both storing formal arguments into Rust variables
184 /// or results of call/invoke instructions into their destinations.
185 fn store(&self, bx: &Builder<'_, 'll, 'tcx>, val: &'ll Value, dst: PlaceRef<'ll, 'tcx>) {
186 if self.is_ignore() {
190 if self.is_sized_indirect() {
191 OperandValue::Ref(val, None, self.layout.align).store(bx, dst)
192 } else if self.is_unsized_indirect() {
193 bug!("unsized ArgType must be handled through store_fn_arg");
194 } else if let PassMode::Cast(cast) = self.mode {
195 // FIXME(eddyb): Figure out when the simpler Store is safe, clang
196 // uses it for i16 -> {i8, i8}, but not for i24 -> {i8, i8, i8}.
197 let can_store_through_cast_ptr = false;
198 if can_store_through_cast_ptr {
199 let cast_dst = bx.pointercast(dst.llval, cast.llvm_type(cx).ptr_to());
200 bx.store(val, cast_dst, self.layout.align);
202 // The actual return type is a struct, but the ABI
203 // adaptation code has cast it into some scalar type. The
204 // code that follows is the only reliable way I have
205 // found to do a transform like i64 -> {i32,i32}.
206 // Basically we dump the data onto the stack then memcpy it.
208 // Other approaches I tried:
209 // - Casting rust ret pointer to the foreign type and using Store
210 // is (a) unsafe if size of foreign type > size of rust type and
211 // (b) runs afoul of strict aliasing rules, yielding invalid
212 // assembly under -O (specifically, the store gets removed).
213 // - Truncating foreign type to correct integral type and then
214 // bitcasting to the struct type yields invalid cast errors.
216 // We instead thus allocate some scratch space...
217 let scratch_size = cast.size(cx);
218 let scratch_align = cast.align(cx);
219 let llscratch = bx.alloca(cast.llvm_type(cx), "abi_cast", scratch_align);
220 bx.lifetime_start(llscratch, scratch_size);
222 // ...where we first store the value...
223 bx.store(val, llscratch, scratch_align);
225 // ...and then memcpy it to the intended destination.
226 base::call_memcpy(bx,
227 bx.pointercast(dst.llval, Type::i8p(cx)),
228 bx.pointercast(llscratch, Type::i8p(cx)),
229 C_usize(cx, self.layout.size.bytes()),
230 self.layout.align.min(scratch_align),
233 bx.lifetime_end(llscratch, scratch_size);
236 OperandValue::Immediate(val).store(bx, dst);
240 fn store_fn_arg(&self, bx: &Builder<'a, 'll, 'tcx>, idx: &mut usize, dst: PlaceRef<'ll, 'tcx>) {
242 let val = llvm::get_param(bx.llfn(), *idx as c_uint);
247 PassMode::Ignore => {},
248 PassMode::Pair(..) => {
249 OperandValue::Pair(next(), next()).store(bx, dst);
251 PassMode::Indirect(_, Some(_)) => {
252 OperandValue::Ref(next(), Some(next()), self.layout.align).store(bx, dst);
254 PassMode::Direct(_) | PassMode::Indirect(_, None) | PassMode::Cast(_) => {
255 self.store(bx, next(), dst);
261 pub trait FnTypeExt<'tcx> {
262 fn of_instance(cx: &CodegenCx<'ll, 'tcx>, instance: &ty::Instance<'tcx>)
264 fn new(cx: &CodegenCx<'ll, 'tcx>,
265 sig: ty::FnSig<'tcx>,
266 extra_args: &[Ty<'tcx>]) -> Self;
267 fn new_vtable(cx: &CodegenCx<'ll, 'tcx>,
268 sig: ty::FnSig<'tcx>,
269 extra_args: &[Ty<'tcx>]) -> Self;
271 cx: &CodegenCx<'ll, 'tcx>,
272 sig: ty::FnSig<'tcx>,
273 extra_args: &[Ty<'tcx>],
274 mk_arg_type: impl Fn(Ty<'tcx>, Option<usize>) -> ArgType<'tcx, Ty<'tcx>>,
276 fn adjust_for_abi(&mut self,
277 cx: &CodegenCx<'ll, 'tcx>,
279 fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
280 fn llvm_cconv(&self) -> llvm::CallConv;
281 fn apply_attrs_llfn(&self, llfn: &'ll Value);
282 fn apply_attrs_callsite(&self, bx: &Builder<'a, 'll, 'tcx>, callsite: &'ll Value);
285 impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
286 fn of_instance(cx: &CodegenCx<'ll, 'tcx>, instance: &ty::Instance<'tcx>)
288 let fn_ty = instance.ty(cx.tcx);
289 let sig = ty_fn_sig(cx, fn_ty);
290 let sig = cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
291 FnType::new(cx, sig, &[])
294 fn new(cx: &CodegenCx<'ll, 'tcx>,
295 sig: ty::FnSig<'tcx>,
296 extra_args: &[Ty<'tcx>]) -> Self {
297 FnType::new_internal(cx, sig, extra_args, |ty, _| {
298 ArgType::new(cx.layout_of(ty))
302 fn new_vtable(cx: &CodegenCx<'ll, 'tcx>,
303 sig: ty::FnSig<'tcx>,
304 extra_args: &[Ty<'tcx>]) -> Self {
305 FnType::new_internal(cx, sig, extra_args, |ty, arg_idx| {
306 let mut layout = cx.layout_of(ty);
307 // Don't pass the vtable, it's not an argument of the virtual fn.
308 // Instead, pass just the (thin pointer) first field of `*dyn Trait`.
309 if arg_idx == Some(0) {
310 if layout.is_unsized() {
311 unimplemented!("by-value trait object is not \
312 yet implemented in #![feature(unsized_locals)]");
314 // FIXME(eddyb) `layout.field(cx, 0)` is not enough because e.g.
315 // `Box<dyn Trait>` has a few newtype wrappers around the raw
316 // pointer, so we'd have to "dig down" to find `*dyn Trait`.
317 let pointee = layout.ty.builtin_deref(true)
319 bug!("FnType::new_vtable: non-pointer self {:?}", layout)
321 let fat_ptr_ty = cx.tcx.mk_mut_ptr(pointee);
322 layout = cx.layout_of(fat_ptr_ty).field(cx, 0);
329 cx: &CodegenCx<'ll, 'tcx>,
330 sig: ty::FnSig<'tcx>,
331 extra_args: &[Ty<'tcx>],
332 mk_arg_type: impl Fn(Ty<'tcx>, Option<usize>) -> ArgType<'tcx, Ty<'tcx>>,
334 debug!("FnType::new_internal({:?}, {:?})", sig, extra_args);
337 let conv = match cx.sess().target.target.adjust_abi(sig.abi) {
338 RustIntrinsic | PlatformIntrinsic |
339 Rust | RustCall => Conv::C,
341 // It's the ABI's job to select this, not us.
342 System => bug!("system abi should be selected elsewhere"),
344 Stdcall => Conv::X86Stdcall,
345 Fastcall => Conv::X86Fastcall,
346 Vectorcall => Conv::X86VectorCall,
347 Thiscall => Conv::X86ThisCall,
349 Unadjusted => Conv::C,
350 Win64 => Conv::X86_64Win64,
351 SysV64 => Conv::X86_64SysV,
352 Aapcs => Conv::ArmAapcs,
353 PtxKernel => Conv::PtxKernel,
354 Msp430Interrupt => Conv::Msp430Intr,
355 X86Interrupt => Conv::X86Intr,
356 AmdGpuKernel => Conv::AmdGpuKernel,
358 // These API constants ought to be more specific...
362 let mut inputs = sig.inputs();
363 let extra_args = if sig.abi == RustCall {
364 assert!(!sig.variadic && extra_args.is_empty());
366 match sig.inputs().last().unwrap().sty {
367 ty::Tuple(ref tupled_arguments) => {
368 inputs = &sig.inputs()[0..sig.inputs().len() - 1];
372 bug!("argument to function with \"rust-call\" ABI \
377 assert!(sig.variadic || extra_args.is_empty());
381 let target = &cx.sess().target.target;
382 let win_x64_gnu = target.target_os == "windows"
383 && target.arch == "x86_64"
384 && target.target_env == "gnu";
385 let linux_s390x = target.target_os == "linux"
386 && target.arch == "s390x"
387 && target.target_env == "gnu";
388 let rust_abi = match sig.abi {
389 RustIntrinsic | PlatformIntrinsic | Rust | RustCall => true,
393 // Handle safe Rust thin and fat pointers.
394 let adjust_for_rust_scalar = |attrs: &mut ArgAttributes,
395 scalar: &layout::Scalar,
396 layout: TyLayout<'tcx, Ty<'tcx>>,
399 // Booleans are always an i1 that needs to be zero-extended.
400 if scalar.is_bool() {
401 attrs.set(ArgAttribute::ZExt);
405 // Only pointer types handled below.
406 if scalar.value != layout::Pointer {
410 if scalar.valid_range.start() < scalar.valid_range.end() {
411 if *scalar.valid_range.start() > 0 {
412 attrs.set(ArgAttribute::NonNull);
416 if let Some(pointee) = layout.pointee_info_at(cx, offset) {
417 if let Some(kind) = pointee.safe {
418 attrs.pointee_size = pointee.size;
419 attrs.pointee_align = Some(pointee.align);
421 // HACK(eddyb) LLVM inserts `llvm.assume` calls when inlining functions
422 // with align attributes, and those calls later block optimizations.
423 if !is_return && !cx.tcx.sess.opts.debugging_opts.arg_align_attributes {
424 attrs.pointee_align = None;
427 // `Box` pointer parameters never alias because ownership is transferred
428 // `&mut` pointer parameters never alias other parameters,
429 // or mutable global data
431 // `&T` where `T` contains no `UnsafeCell<U>` is immutable,
432 // and can be marked as both `readonly` and `noalias`, as
433 // LLVM's definition of `noalias` is based solely on memory
434 // dependencies rather than pointer equality
435 let no_alias = match kind {
436 PointerKind::Shared => false,
437 PointerKind::UniqueOwned => true,
438 PointerKind::Frozen |
439 PointerKind::UniqueBorrowed => !is_return
442 attrs.set(ArgAttribute::NoAlias);
445 if kind == PointerKind::Frozen && !is_return {
446 attrs.set(ArgAttribute::ReadOnly);
452 let arg_of = |ty: Ty<'tcx>, arg_idx: Option<usize>| {
453 let is_return = arg_idx.is_none();
454 let mut arg = mk_arg_type(ty, arg_idx);
455 if arg.layout.is_zst() {
456 // For some forsaken reason, x86_64-pc-windows-gnu
457 // doesn't ignore zero-sized struct arguments.
458 // The same is true for s390x-unknown-linux-gnu.
459 if is_return || rust_abi || (!win_x64_gnu && !linux_s390x) {
460 arg.mode = PassMode::Ignore;
464 // FIXME(eddyb) other ABIs don't have logic for scalar pairs.
465 if !is_return && rust_abi {
466 if let layout::Abi::ScalarPair(ref a, ref b) = arg.layout.abi {
467 let mut a_attrs = ArgAttributes::new();
468 let mut b_attrs = ArgAttributes::new();
469 adjust_for_rust_scalar(&mut a_attrs,
474 adjust_for_rust_scalar(&mut b_attrs,
477 a.value.size(cx).abi_align(b.value.align(cx)),
479 arg.mode = PassMode::Pair(a_attrs, b_attrs);
484 if let layout::Abi::Scalar(ref scalar) = arg.layout.abi {
485 if let PassMode::Direct(ref mut attrs) = arg.mode {
486 adjust_for_rust_scalar(attrs,
497 let mut fn_ty = FnType {
498 ret: arg_of(sig.output(), None),
499 args: inputs.iter().chain(extra_args).enumerate().map(|(i, ty)| {
502 variadic: sig.variadic,
505 fn_ty.adjust_for_abi(cx, sig.abi);
509 fn adjust_for_abi(&mut self,
510 cx: &CodegenCx<'ll, 'tcx>,
512 if abi == Abi::Unadjusted { return }
514 if abi == Abi::Rust || abi == Abi::RustCall ||
515 abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic {
516 let fixup = |arg: &mut ArgType<'tcx, Ty<'tcx>>| {
517 if arg.is_ignore() { return; }
519 match arg.layout.abi {
520 layout::Abi::Aggregate { .. } => {}
522 // This is a fun case! The gist of what this is doing is
523 // that we want callers and callees to always agree on the
524 // ABI of how they pass SIMD arguments. If we were to *not*
525 // make these arguments indirect then they'd be immediates
526 // in LLVM, which means that they'd used whatever the
527 // appropriate ABI is for the callee and the caller. That
528 // means, for example, if the caller doesn't have AVX
529 // enabled but the callee does, then passing an AVX argument
530 // across this boundary would cause corrupt data to show up.
532 // This problem is fixed by unconditionally passing SIMD
533 // arguments through memory between callers and callees
534 // which should get them all to agree on ABI regardless of
535 // target feature sets. Some more information about this
536 // issue can be found in #44367.
538 // Note that the platform intrinsic ABI is exempt here as
539 // that's how we connect up to LLVM and it's unstable
540 // anyway, we control all calls to it in libstd.
541 layout::Abi::Vector { .. } if abi != Abi::PlatformIntrinsic => {
549 let size = arg.layout.size;
550 if arg.layout.is_unsized() || size > layout::Pointer.size(cx) {
553 // We want to pass small aggregates as immediates, but using
554 // a LLVM aggregate type for this leads to bad optimizations,
555 // so we pick an appropriately sized integer type instead.
557 kind: RegKind::Integer,
562 fixup(&mut self.ret);
563 for arg in &mut self.args {
566 if let PassMode::Indirect(ref mut attrs, _) = self.ret.mode {
567 attrs.set(ArgAttribute::StructRet);
572 if let Err(msg) = self.adjust_for_cabi(cx, abi) {
573 cx.sess().fatal(&msg);
577 fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type {
578 let args_capacity: usize = self.args.iter().map(|arg|
579 if arg.pad.is_some() { 1 } else { 0 } +
580 if let PassMode::Pair(_, _) = arg.mode { 2 } else { 1 }
582 let mut llargument_tys = Vec::with_capacity(
583 if let PassMode::Indirect(..) = self.ret.mode { 1 } else { 0 } + args_capacity
586 let llreturn_ty = match self.ret.mode {
587 PassMode::Ignore => Type::void(cx),
588 PassMode::Direct(_) | PassMode::Pair(..) => {
589 self.ret.layout.immediate_llvm_type(cx)
591 PassMode::Cast(cast) => cast.llvm_type(cx),
592 PassMode::Indirect(..) => {
593 llargument_tys.push(self.ret.memory_ty(cx).ptr_to());
598 for arg in &self.args {
600 if let Some(ty) = arg.pad {
601 llargument_tys.push(ty.llvm_type(cx));
604 let llarg_ty = match arg.mode {
605 PassMode::Ignore => continue,
606 PassMode::Direct(_) => arg.layout.immediate_llvm_type(cx),
607 PassMode::Pair(..) => {
608 llargument_tys.push(arg.layout.scalar_pair_element_llvm_type(cx, 0, true));
609 llargument_tys.push(arg.layout.scalar_pair_element_llvm_type(cx, 1, true));
612 PassMode::Indirect(_, Some(_)) => {
613 let ptr_ty = cx.tcx.mk_mut_ptr(arg.layout.ty);
614 let ptr_layout = cx.layout_of(ptr_ty);
615 llargument_tys.push(ptr_layout.scalar_pair_element_llvm_type(cx, 0, true));
616 llargument_tys.push(ptr_layout.scalar_pair_element_llvm_type(cx, 1, true));
619 PassMode::Cast(cast) => cast.llvm_type(cx),
620 PassMode::Indirect(_, None) => arg.memory_ty(cx).ptr_to(),
622 llargument_tys.push(llarg_ty);
626 Type::variadic_func(&llargument_tys, llreturn_ty)
628 Type::func(&llargument_tys, llreturn_ty)
632 fn llvm_cconv(&self) -> llvm::CallConv {
634 Conv::C => llvm::CCallConv,
635 Conv::AmdGpuKernel => llvm::AmdGpuKernel,
636 Conv::ArmAapcs => llvm::ArmAapcsCallConv,
637 Conv::Msp430Intr => llvm::Msp430Intr,
638 Conv::PtxKernel => llvm::PtxKernel,
639 Conv::X86Fastcall => llvm::X86FastcallCallConv,
640 Conv::X86Intr => llvm::X86_Intr,
641 Conv::X86Stdcall => llvm::X86StdcallCallConv,
642 Conv::X86ThisCall => llvm::X86_ThisCall,
643 Conv::X86VectorCall => llvm::X86_VectorCall,
644 Conv::X86_64SysV => llvm::X86_64_SysV,
645 Conv::X86_64Win64 => llvm::X86_64_Win64,
649 fn apply_attrs_llfn(&self, llfn: &'ll Value) {
651 let mut apply = |attrs: &ArgAttributes| {
652 attrs.apply_llfn(llvm::AttributePlace::Argument(i), llfn);
655 match self.ret.mode {
656 PassMode::Direct(ref attrs) => {
657 attrs.apply_llfn(llvm::AttributePlace::ReturnValue, llfn);
659 PassMode::Indirect(ref attrs, _) => apply(attrs),
662 for arg in &self.args {
663 if arg.pad.is_some() {
664 apply(&ArgAttributes::new());
667 PassMode::Ignore => {}
668 PassMode::Direct(ref attrs) |
669 PassMode::Indirect(ref attrs, None) => apply(attrs),
670 PassMode::Indirect(ref attrs, Some(ref extra_attrs)) => {
674 PassMode::Pair(ref a, ref b) => {
678 PassMode::Cast(_) => apply(&ArgAttributes::new()),
683 fn apply_attrs_callsite(&self, bx: &Builder<'a, 'll, 'tcx>, callsite: &'ll Value) {
685 let mut apply = |attrs: &ArgAttributes| {
686 attrs.apply_callsite(llvm::AttributePlace::Argument(i), callsite);
689 match self.ret.mode {
690 PassMode::Direct(ref attrs) => {
691 attrs.apply_callsite(llvm::AttributePlace::ReturnValue, callsite);
693 PassMode::Indirect(ref attrs, _) => apply(attrs),
696 if let layout::Abi::Scalar(ref scalar) = self.ret.layout.abi {
697 // If the value is a boolean, the range is 0..2 and that ultimately
698 // become 0..0 when the type becomes i1, which would be rejected
699 // by the LLVM verifier.
701 layout::Int(..) if !scalar.is_bool() => {
702 let range = scalar.valid_range_exclusive(bx.cx);
703 if range.start != range.end {
704 bx.range_metadata(callsite, range);
710 for arg in &self.args {
711 if arg.pad.is_some() {
712 apply(&ArgAttributes::new());
715 PassMode::Ignore => {}
716 PassMode::Direct(ref attrs) |
717 PassMode::Indirect(ref attrs, None) => apply(attrs),
718 PassMode::Indirect(ref attrs, Some(ref extra_attrs)) => {
722 PassMode::Pair(ref a, ref b) => {
726 PassMode::Cast(_) => apply(&ArgAttributes::new()),
730 let cconv = self.llvm_cconv();
731 if cconv != llvm::CCallConv {
732 llvm::SetInstructionCallConv(callsite, cconv);