]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_llvm/context.rs
Rollup merge of #68597 - ollie27:skip_nth_last, r=Amanieu
[rust.git] / src / librustc_codegen_llvm / context.rs
1 use crate::abi::FnAbi;
2 use crate::attributes;
3 use crate::debuginfo;
4 use crate::llvm;
5 use crate::llvm_util;
6 use crate::value::Value;
7 use rustc::dep_graph::DepGraphSafe;
8
9 use crate::type_::Type;
10 use rustc_codegen_ssa::traits::*;
11
12 use crate::callee::get_fn;
13 use rustc::bug;
14 use rustc::mir::mono::CodegenUnit;
15 use rustc::session::config::{self, CFGuard, DebugInfo};
16 use rustc::session::Session;
17 use rustc::ty::layout::{
18     FnAbiExt, HasParamEnv, LayoutError, LayoutOf, PointeeInfo, Size, TyLayout, VariantIdx,
19 };
20 use rustc::ty::{self, Instance, Ty, TyCtxt};
21 use rustc_codegen_ssa::base::wants_msvc_seh;
22 use rustc_data_structures::base_n;
23 use rustc_data_structures::const_cstr;
24 use rustc_data_structures::fx::FxHashMap;
25 use rustc_data_structures::small_c_str::SmallCStr;
26 use rustc_hir::Unsafety;
27 use rustc_target::spec::{HasTargetSpec, Target};
28
29 use crate::abi::Abi;
30 use rustc_span::source_map::{Span, DUMMY_SP};
31 use rustc_span::symbol::Symbol;
32 use std::cell::{Cell, RefCell};
33 use std::ffi::CStr;
34 use std::iter;
35 use std::str;
36 use std::sync::Arc;
37
38 /// There is one `CodegenCx` per compilation unit. Each one has its own LLVM
39 /// `llvm::Context` so that several compilation units may be optimized in parallel.
40 /// All other LLVM data structures in the `CodegenCx` are tied to that `llvm::Context`.
41 pub struct CodegenCx<'ll, 'tcx> {
42     pub tcx: TyCtxt<'tcx>,
43     pub check_overflow: bool,
44     pub use_dll_storage_attrs: bool,
45     pub tls_model: llvm::ThreadLocalMode,
46
47     pub llmod: &'ll llvm::Module,
48     pub llcx: &'ll llvm::Context,
49     pub codegen_unit: Arc<CodegenUnit<'tcx>>,
50
51     /// Cache instances of monomorphic and polymorphic items
52     pub instances: RefCell<FxHashMap<Instance<'tcx>, &'ll Value>>,
53     /// Cache generated vtables
54     pub vtables:
55         RefCell<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), &'ll Value>>,
56     /// Cache of constant strings,
57     pub const_cstr_cache: RefCell<FxHashMap<Symbol, &'ll Value>>,
58
59     /// Reverse-direction for const ptrs cast from globals.
60     /// Key is a Value holding a *T,
61     /// Val is a Value holding a *[T].
62     ///
63     /// Needed because LLVM loses pointer->pointee association
64     /// when we ptrcast, and we have to ptrcast during codegen
65     /// of a [T] const because we form a slice, a (*T,usize) pair, not
66     /// a pointer to an LLVM array type. Similar for trait objects.
67     pub const_unsized: RefCell<FxHashMap<&'ll Value, &'ll Value>>,
68
69     /// Cache of emitted const globals (value -> global)
70     pub const_globals: RefCell<FxHashMap<&'ll Value, &'ll Value>>,
71
72     /// List of globals for static variables which need to be passed to the
73     /// LLVM function ReplaceAllUsesWith (RAUW) when codegen is complete.
74     /// (We have to make sure we don't invalidate any Values referring
75     /// to constants.)
76     pub statics_to_rauw: RefCell<Vec<(&'ll Value, &'ll Value)>>,
77
78     /// Statics that will be placed in the llvm.used variable
79     /// See <http://llvm.org/docs/LangRef.html#the-llvm-used-global-variable> for details
80     pub used_statics: RefCell<Vec<&'ll Value>>,
81
82     pub lltypes: RefCell<FxHashMap<(Ty<'tcx>, Option<VariantIdx>), &'ll Type>>,
83     pub scalar_lltypes: RefCell<FxHashMap<Ty<'tcx>, &'ll Type>>,
84     pub pointee_infos: RefCell<FxHashMap<(Ty<'tcx>, Size), Option<PointeeInfo>>>,
85     pub isize_ty: &'ll Type,
86
87     pub dbg_cx: Option<debuginfo::CrateDebugContext<'ll, 'tcx>>,
88
89     eh_personality: Cell<Option<&'ll Value>>,
90     eh_unwind_resume: Cell<Option<&'ll Value>>,
91     pub rust_try_fn: Cell<Option<&'ll Value>>,
92
93     intrinsics: RefCell<FxHashMap<&'static str, &'ll Value>>,
94
95     /// A counter that is used for generating local symbol names
96     local_gen_sym_counter: Cell<usize>,
97 }
98
99 impl<'ll, 'tcx> DepGraphSafe for CodegenCx<'ll, 'tcx> {}
100
101 pub fn get_reloc_model(sess: &Session) -> llvm::RelocMode {
102     let reloc_model_arg = match sess.opts.cg.relocation_model {
103         Some(ref s) => &s[..],
104         None => &sess.target.target.options.relocation_model[..],
105     };
106
107     match crate::back::write::RELOC_MODEL_ARGS.iter().find(|&&arg| arg.0 == reloc_model_arg) {
108         Some(x) => x.1,
109         _ => {
110             sess.err(&format!("{:?} is not a valid relocation mode", reloc_model_arg));
111             sess.abort_if_errors();
112             bug!();
113         }
114     }
115 }
116
117 fn get_tls_model(sess: &Session) -> llvm::ThreadLocalMode {
118     let tls_model_arg = match sess.opts.debugging_opts.tls_model {
119         Some(ref s) => &s[..],
120         None => &sess.target.target.options.tls_model[..],
121     };
122
123     match crate::back::write::TLS_MODEL_ARGS.iter().find(|&&arg| arg.0 == tls_model_arg) {
124         Some(x) => x.1,
125         _ => {
126             sess.err(&format!("{:?} is not a valid TLS model", tls_model_arg));
127             sess.abort_if_errors();
128             bug!();
129         }
130     }
131 }
132
133 fn is_any_library(sess: &Session) -> bool {
134     sess.crate_types.borrow().iter().any(|ty| *ty != config::CrateType::Executable)
135 }
136
137 pub fn is_pie_binary(sess: &Session) -> bool {
138     !is_any_library(sess) && get_reloc_model(sess) == llvm::RelocMode::PIC
139 }
140
141 fn strip_function_ptr_alignment(data_layout: String) -> String {
142     // FIXME: Make this more general.
143     data_layout.replace("-Fi8-", "-")
144 }
145
146 fn strip_x86_address_spaces(data_layout: String) -> String {
147     data_layout.replace("-p270:32:32-p271:32:32-p272:64:64-", "-")
148 }
149
150 pub unsafe fn create_module(
151     tcx: TyCtxt<'_>,
152     llcx: &'ll llvm::Context,
153     mod_name: &str,
154 ) -> &'ll llvm::Module {
155     let sess = tcx.sess;
156     let mod_name = SmallCStr::new(mod_name);
157     let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx);
158
159     let mut target_data_layout = sess.target.target.data_layout.clone();
160     if llvm_util::get_major_version() < 9 {
161         target_data_layout = strip_function_ptr_alignment(target_data_layout);
162     }
163     if llvm_util::get_major_version() < 10 {
164         if sess.target.target.arch == "x86" || sess.target.target.arch == "x86_64" {
165             target_data_layout = strip_x86_address_spaces(target_data_layout);
166         }
167     }
168
169     // Ensure the data-layout values hardcoded remain the defaults.
170     if sess.target.target.options.is_builtin {
171         let tm = crate::back::write::create_informational_target_machine(&tcx.sess, false);
172         llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm);
173         llvm::LLVMRustDisposeTargetMachine(tm);
174
175         let llvm_data_layout = llvm::LLVMGetDataLayout(llmod);
176         let llvm_data_layout = str::from_utf8(CStr::from_ptr(llvm_data_layout).to_bytes())
177             .ok()
178             .expect("got a non-UTF8 data-layout from LLVM");
179
180         // Unfortunately LLVM target specs change over time, and right now we
181         // don't have proper support to work with any more than one
182         // `data_layout` than the one that is in the rust-lang/rust repo. If
183         // this compiler is configured against a custom LLVM, we may have a
184         // differing data layout, even though we should update our own to use
185         // that one.
186         //
187         // As an interim hack, if CFG_LLVM_ROOT is not an empty string then we
188         // disable this check entirely as we may be configured with something
189         // that has a different target layout.
190         //
191         // Unsure if this will actually cause breakage when rustc is configured
192         // as such.
193         //
194         // FIXME(#34960)
195         let cfg_llvm_root = option_env!("CFG_LLVM_ROOT").unwrap_or("");
196         let custom_llvm_used = cfg_llvm_root.trim() != "";
197
198         if !custom_llvm_used && target_data_layout != llvm_data_layout {
199             bug!(
200                 "data-layout for builtin `{}` target, `{}`, \
201                   differs from LLVM default, `{}`",
202                 sess.target.target.llvm_target,
203                 target_data_layout,
204                 llvm_data_layout
205             );
206         }
207     }
208
209     let data_layout = SmallCStr::new(&target_data_layout);
210     llvm::LLVMSetDataLayout(llmod, data_layout.as_ptr());
211
212     let llvm_target = SmallCStr::new(&sess.target.target.llvm_target);
213     llvm::LLVMRustSetNormalizedTarget(llmod, llvm_target.as_ptr());
214
215     if get_reloc_model(sess) == llvm::RelocMode::PIC {
216         llvm::LLVMRustSetModulePICLevel(llmod);
217     }
218
219     if is_pie_binary(sess) {
220         llvm::LLVMRustSetModulePIELevel(llmod);
221     }
222
223     // If skipping the PLT is enabled, we need to add some module metadata
224     // to ensure intrinsic calls don't use it.
225     if !sess.needs_plt() {
226         let avoid_plt = "RtLibUseGOT\0".as_ptr().cast();
227         llvm::LLVMRustAddModuleFlag(llmod, avoid_plt, 1);
228     }
229
230     // Set module flags to enable Windows Control Flow Guard (/guard:cf) metadata
231     // only (`cfguard=1`) or metadata and checks (`cfguard=2`).
232     match sess.opts.debugging_opts.control_flow_guard {
233         CFGuard::Disabled => {}
234         CFGuard::NoChecks => {
235             llvm::LLVMRustAddModuleFlag(llmod, "cfguard\0".as_ptr() as *const _, 1)
236         }
237         CFGuard::Checks => llvm::LLVMRustAddModuleFlag(llmod, "cfguard\0".as_ptr() as *const _, 2),
238     }
239
240     llmod
241 }
242
243 impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
244     crate fn new(
245         tcx: TyCtxt<'tcx>,
246         codegen_unit: Arc<CodegenUnit<'tcx>>,
247         llvm_module: &'ll crate::ModuleLlvm,
248     ) -> Self {
249         // An interesting part of Windows which MSVC forces our hand on (and
250         // apparently MinGW didn't) is the usage of `dllimport` and `dllexport`
251         // attributes in LLVM IR as well as native dependencies (in C these
252         // correspond to `__declspec(dllimport)`).
253         //
254         // Whenever a dynamic library is built by MSVC it must have its public
255         // interface specified by functions tagged with `dllexport` or otherwise
256         // they're not available to be linked against. This poses a few problems
257         // for the compiler, some of which are somewhat fundamental, but we use
258         // the `use_dll_storage_attrs` variable below to attach the `dllexport`
259         // attribute to all LLVM functions that are exported e.g., they're
260         // already tagged with external linkage). This is suboptimal for a few
261         // reasons:
262         //
263         // * If an object file will never be included in a dynamic library,
264         //   there's no need to attach the dllexport attribute. Most object
265         //   files in Rust are not destined to become part of a dll as binaries
266         //   are statically linked by default.
267         // * If the compiler is emitting both an rlib and a dylib, the same
268         //   source object file is currently used but with MSVC this may be less
269         //   feasible. The compiler may be able to get around this, but it may
270         //   involve some invasive changes to deal with this.
271         //
272         // The flipside of this situation is that whenever you link to a dll and
273         // you import a function from it, the import should be tagged with
274         // `dllimport`. At this time, however, the compiler does not emit
275         // `dllimport` for any declarations other than constants (where it is
276         // required), which is again suboptimal for even more reasons!
277         //
278         // * Calling a function imported from another dll without using
279         //   `dllimport` causes the linker/compiler to have extra overhead (one
280         //   `jmp` instruction on x86) when calling the function.
281         // * The same object file may be used in different circumstances, so a
282         //   function may be imported from a dll if the object is linked into a
283         //   dll, but it may be just linked against if linked into an rlib.
284         // * The compiler has no knowledge about whether native functions should
285         //   be tagged dllimport or not.
286         //
287         // For now the compiler takes the perf hit (I do not have any numbers to
288         // this effect) by marking very little as `dllimport` and praying the
289         // linker will take care of everything. Fixing this problem will likely
290         // require adding a few attributes to Rust itself (feature gated at the
291         // start) and then strongly recommending static linkage on MSVC!
292         let use_dll_storage_attrs = tcx.sess.target.target.options.is_like_msvc;
293
294         let check_overflow = tcx.sess.overflow_checks();
295
296         let tls_model = get_tls_model(&tcx.sess);
297
298         let (llcx, llmod) = (&*llvm_module.llcx, llvm_module.llmod());
299
300         let dbg_cx = if tcx.sess.opts.debuginfo != DebugInfo::None {
301             let dctx = debuginfo::CrateDebugContext::new(llmod);
302             debuginfo::metadata::compile_unit_metadata(tcx, &codegen_unit.name().as_str(), &dctx);
303             Some(dctx)
304         } else {
305             None
306         };
307
308         let isize_ty = Type::ix_llcx(llcx, tcx.data_layout.pointer_size.bits());
309
310         CodegenCx {
311             tcx,
312             check_overflow,
313             use_dll_storage_attrs,
314             tls_model,
315             llmod,
316             llcx,
317             codegen_unit,
318             instances: Default::default(),
319             vtables: Default::default(),
320             const_cstr_cache: Default::default(),
321             const_unsized: Default::default(),
322             const_globals: Default::default(),
323             statics_to_rauw: RefCell::new(Vec::new()),
324             used_statics: RefCell::new(Vec::new()),
325             lltypes: Default::default(),
326             scalar_lltypes: Default::default(),
327             pointee_infos: Default::default(),
328             isize_ty,
329             dbg_cx,
330             eh_personality: Cell::new(None),
331             eh_unwind_resume: Cell::new(None),
332             rust_try_fn: Cell::new(None),
333             intrinsics: Default::default(),
334             local_gen_sym_counter: Cell::new(0),
335         }
336     }
337
338     crate fn statics_to_rauw(&self) -> &RefCell<Vec<(&'ll Value, &'ll Value)>> {
339         &self.statics_to_rauw
340     }
341 }
342
343 impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
344     fn vtables(
345         &self,
346     ) -> &RefCell<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), &'ll Value>>
347     {
348         &self.vtables
349     }
350
351     fn get_fn(&self, instance: Instance<'tcx>) -> &'ll Value {
352         get_fn(self, instance)
353     }
354
355     fn get_fn_addr(&self, instance: Instance<'tcx>) -> &'ll Value {
356         get_fn(self, instance)
357     }
358
359     fn eh_personality(&self) -> &'ll Value {
360         // The exception handling personality function.
361         //
362         // If our compilation unit has the `eh_personality` lang item somewhere
363         // within it, then we just need to codegen that. Otherwise, we're
364         // building an rlib which will depend on some upstream implementation of
365         // this function, so we just codegen a generic reference to it. We don't
366         // specify any of the types for the function, we just make it a symbol
367         // that LLVM can later use.
368         //
369         // Note that MSVC is a little special here in that we don't use the
370         // `eh_personality` lang item at all. Currently LLVM has support for
371         // both Dwarf and SEH unwind mechanisms for MSVC targets and uses the
372         // *name of the personality function* to decide what kind of unwind side
373         // tables/landing pads to emit. It looks like Dwarf is used by default,
374         // injecting a dependency on the `_Unwind_Resume` symbol for resuming
375         // an "exception", but for MSVC we want to force SEH. This means that we
376         // can't actually have the personality function be our standard
377         // `rust_eh_personality` function, but rather we wired it up to the
378         // CRT's custom personality function, which forces LLVM to consider
379         // landing pads as "landing pads for SEH".
380         if let Some(llpersonality) = self.eh_personality.get() {
381             return llpersonality;
382         }
383         let tcx = self.tcx;
384         let llfn = match tcx.lang_items().eh_personality() {
385             Some(def_id) if !wants_msvc_seh(self.sess()) => self.get_fn_addr(
386                 ty::Instance::resolve(
387                     tcx,
388                     ty::ParamEnv::reveal_all(),
389                     def_id,
390                     tcx.intern_substs(&[]),
391                 )
392                 .unwrap(),
393             ),
394             _ => {
395                 let name = if wants_msvc_seh(self.sess()) {
396                     "__CxxFrameHandler3"
397                 } else {
398                     "rust_eh_personality"
399                 };
400                 let fty = self.type_variadic_func(&[], self.type_i32());
401                 self.declare_cfn(name, fty)
402             }
403         };
404         attributes::apply_target_cpu_attr(self, llfn);
405         self.eh_personality.set(Some(llfn));
406         llfn
407     }
408
409     // Returns a Value of the "eh_unwind_resume" lang item if one is defined,
410     // otherwise declares it as an external function.
411     fn eh_unwind_resume(&self) -> &'ll Value {
412         let unwresume = &self.eh_unwind_resume;
413         if let Some(llfn) = unwresume.get() {
414             return llfn;
415         }
416
417         let tcx = self.tcx;
418         assert!(self.sess().target.target.options.custom_unwind_resume);
419         if let Some(def_id) = tcx.lang_items().eh_unwind_resume() {
420             let llfn = self.get_fn_addr(
421                 ty::Instance::resolve(
422                     tcx,
423                     ty::ParamEnv::reveal_all(),
424                     def_id,
425                     tcx.intern_substs(&[]),
426                 )
427                 .unwrap(),
428             );
429             unwresume.set(Some(llfn));
430             return llfn;
431         }
432
433         let sig = ty::Binder::bind(tcx.mk_fn_sig(
434             iter::once(tcx.mk_mut_ptr(tcx.types.u8)),
435             tcx.types.never,
436             false,
437             Unsafety::Unsafe,
438             Abi::C,
439         ));
440
441         let fn_abi = FnAbi::of_fn_ptr(self, sig, &[]);
442         let llfn = self.declare_fn("rust_eh_unwind_resume", &fn_abi);
443         attributes::apply_target_cpu_attr(self, llfn);
444         unwresume.set(Some(llfn));
445         llfn
446     }
447
448     fn sess(&self) -> &Session {
449         &self.tcx.sess
450     }
451
452     fn check_overflow(&self) -> bool {
453         self.check_overflow
454     }
455
456     fn codegen_unit(&self) -> &Arc<CodegenUnit<'tcx>> {
457         &self.codegen_unit
458     }
459
460     fn used_statics(&self) -> &RefCell<Vec<&'ll Value>> {
461         &self.used_statics
462     }
463
464     fn set_frame_pointer_elimination(&self, llfn: &'ll Value) {
465         attributes::set_frame_pointer_elimination(self, llfn)
466     }
467
468     fn apply_target_cpu_attr(&self, llfn: &'ll Value) {
469         attributes::apply_target_cpu_attr(self, llfn)
470     }
471
472     fn create_used_variable(&self) {
473         let name = const_cstr!("llvm.used");
474         let section = const_cstr!("llvm.metadata");
475         let array =
476             self.const_array(&self.type_ptr_to(self.type_i8()), &*self.used_statics.borrow());
477
478         unsafe {
479             let g = llvm::LLVMAddGlobal(self.llmod, self.val_ty(array), name.as_ptr());
480             llvm::LLVMSetInitializer(g, array);
481             llvm::LLVMRustSetLinkage(g, llvm::Linkage::AppendingLinkage);
482             llvm::LLVMSetSection(g, section.as_ptr());
483         }
484     }
485 }
486
487 impl CodegenCx<'b, 'tcx> {
488     crate fn get_intrinsic(&self, key: &str) -> &'b Value {
489         if let Some(v) = self.intrinsics.borrow().get(key).cloned() {
490             return v;
491         }
492
493         self.declare_intrinsic(key).unwrap_or_else(|| bug!("unknown intrinsic '{}'", key))
494     }
495
496     fn insert_intrinsic(
497         &self,
498         name: &'static str,
499         args: Option<&[&'b llvm::Type]>,
500         ret: &'b llvm::Type,
501     ) -> &'b llvm::Value {
502         let fn_ty = if let Some(args) = args {
503             self.type_func(args, ret)
504         } else {
505             self.type_variadic_func(&[], ret)
506         };
507         let f = self.declare_cfn(name, fn_ty);
508         llvm::SetUnnamedAddr(f, false);
509         self.intrinsics.borrow_mut().insert(name, f);
510         f
511     }
512
513     fn declare_intrinsic(&self, key: &str) -> Option<&'b Value> {
514         macro_rules! ifn {
515             ($name:expr, fn() -> $ret:expr) => (
516                 if key == $name {
517                     return Some(self.insert_intrinsic($name, Some(&[]), $ret));
518                 }
519             );
520             ($name:expr, fn(...) -> $ret:expr) => (
521                 if key == $name {
522                     return Some(self.insert_intrinsic($name, None, $ret));
523                 }
524             );
525             ($name:expr, fn($($arg:expr),*) -> $ret:expr) => (
526                 if key == $name {
527                     return Some(self.insert_intrinsic($name, Some(&[$($arg),*]), $ret));
528                 }
529             );
530         }
531         macro_rules! mk_struct {
532             ($($field_ty:expr),*) => (self.type_struct( &[$($field_ty),*], false))
533         }
534
535         let i8p = self.type_i8p();
536         let void = self.type_void();
537         let i1 = self.type_i1();
538         let t_i8 = self.type_i8();
539         let t_i16 = self.type_i16();
540         let t_i32 = self.type_i32();
541         let t_i64 = self.type_i64();
542         let t_i128 = self.type_i128();
543         let t_f32 = self.type_f32();
544         let t_f64 = self.type_f64();
545
546         macro_rules! vector_types {
547             ($id_out:ident: $elem_ty:ident, $len:expr) => {
548                 let $id_out = self.type_vector($elem_ty, $len);
549             };
550             ($($id_out:ident: $elem_ty:ident, $len:expr;)*) => {
551                 $(vector_types!($id_out: $elem_ty, $len);)*
552             }
553         }
554         vector_types! {
555             t_v2f32: t_f32, 2;
556             t_v4f32: t_f32, 4;
557             t_v8f32: t_f32, 8;
558             t_v16f32: t_f32, 16;
559
560             t_v2f64: t_f64, 2;
561             t_v4f64: t_f64, 4;
562             t_v8f64: t_f64, 8;
563         }
564
565         ifn!("llvm.trap", fn() -> void);
566         ifn!("llvm.debugtrap", fn() -> void);
567         ifn!("llvm.frameaddress", fn(t_i32) -> i8p);
568         ifn!("llvm.sideeffect", fn() -> void);
569
570         ifn!("llvm.powi.f32", fn(t_f32, t_i32) -> t_f32);
571         ifn!("llvm.powi.v2f32", fn(t_v2f32, t_i32) -> t_v2f32);
572         ifn!("llvm.powi.v4f32", fn(t_v4f32, t_i32) -> t_v4f32);
573         ifn!("llvm.powi.v8f32", fn(t_v8f32, t_i32) -> t_v8f32);
574         ifn!("llvm.powi.v16f32", fn(t_v16f32, t_i32) -> t_v16f32);
575         ifn!("llvm.powi.f64", fn(t_f64, t_i32) -> t_f64);
576         ifn!("llvm.powi.v2f64", fn(t_v2f64, t_i32) -> t_v2f64);
577         ifn!("llvm.powi.v4f64", fn(t_v4f64, t_i32) -> t_v4f64);
578         ifn!("llvm.powi.v8f64", fn(t_v8f64, t_i32) -> t_v8f64);
579
580         ifn!("llvm.pow.f32", fn(t_f32, t_f32) -> t_f32);
581         ifn!("llvm.pow.v2f32", fn(t_v2f32, t_v2f32) -> t_v2f32);
582         ifn!("llvm.pow.v4f32", fn(t_v4f32, t_v4f32) -> t_v4f32);
583         ifn!("llvm.pow.v8f32", fn(t_v8f32, t_v8f32) -> t_v8f32);
584         ifn!("llvm.pow.v16f32", fn(t_v16f32, t_v16f32) -> t_v16f32);
585         ifn!("llvm.pow.f64", fn(t_f64, t_f64) -> t_f64);
586         ifn!("llvm.pow.v2f64", fn(t_v2f64, t_v2f64) -> t_v2f64);
587         ifn!("llvm.pow.v4f64", fn(t_v4f64, t_v4f64) -> t_v4f64);
588         ifn!("llvm.pow.v8f64", fn(t_v8f64, t_v8f64) -> t_v8f64);
589
590         ifn!("llvm.sqrt.f32", fn(t_f32) -> t_f32);
591         ifn!("llvm.sqrt.v2f32", fn(t_v2f32) -> t_v2f32);
592         ifn!("llvm.sqrt.v4f32", fn(t_v4f32) -> t_v4f32);
593         ifn!("llvm.sqrt.v8f32", fn(t_v8f32) -> t_v8f32);
594         ifn!("llvm.sqrt.v16f32", fn(t_v16f32) -> t_v16f32);
595         ifn!("llvm.sqrt.f64", fn(t_f64) -> t_f64);
596         ifn!("llvm.sqrt.v2f64", fn(t_v2f64) -> t_v2f64);
597         ifn!("llvm.sqrt.v4f64", fn(t_v4f64) -> t_v4f64);
598         ifn!("llvm.sqrt.v8f64", fn(t_v8f64) -> t_v8f64);
599
600         ifn!("llvm.sin.f32", fn(t_f32) -> t_f32);
601         ifn!("llvm.sin.v2f32", fn(t_v2f32) -> t_v2f32);
602         ifn!("llvm.sin.v4f32", fn(t_v4f32) -> t_v4f32);
603         ifn!("llvm.sin.v8f32", fn(t_v8f32) -> t_v8f32);
604         ifn!("llvm.sin.v16f32", fn(t_v16f32) -> t_v16f32);
605         ifn!("llvm.sin.f64", fn(t_f64) -> t_f64);
606         ifn!("llvm.sin.v2f64", fn(t_v2f64) -> t_v2f64);
607         ifn!("llvm.sin.v4f64", fn(t_v4f64) -> t_v4f64);
608         ifn!("llvm.sin.v8f64", fn(t_v8f64) -> t_v8f64);
609
610         ifn!("llvm.cos.f32", fn(t_f32) -> t_f32);
611         ifn!("llvm.cos.v2f32", fn(t_v2f32) -> t_v2f32);
612         ifn!("llvm.cos.v4f32", fn(t_v4f32) -> t_v4f32);
613         ifn!("llvm.cos.v8f32", fn(t_v8f32) -> t_v8f32);
614         ifn!("llvm.cos.v16f32", fn(t_v16f32) -> t_v16f32);
615         ifn!("llvm.cos.f64", fn(t_f64) -> t_f64);
616         ifn!("llvm.cos.v2f64", fn(t_v2f64) -> t_v2f64);
617         ifn!("llvm.cos.v4f64", fn(t_v4f64) -> t_v4f64);
618         ifn!("llvm.cos.v8f64", fn(t_v8f64) -> t_v8f64);
619
620         ifn!("llvm.exp.f32", fn(t_f32) -> t_f32);
621         ifn!("llvm.exp.v2f32", fn(t_v2f32) -> t_v2f32);
622         ifn!("llvm.exp.v4f32", fn(t_v4f32) -> t_v4f32);
623         ifn!("llvm.exp.v8f32", fn(t_v8f32) -> t_v8f32);
624         ifn!("llvm.exp.v16f32", fn(t_v16f32) -> t_v16f32);
625         ifn!("llvm.exp.f64", fn(t_f64) -> t_f64);
626         ifn!("llvm.exp.v2f64", fn(t_v2f64) -> t_v2f64);
627         ifn!("llvm.exp.v4f64", fn(t_v4f64) -> t_v4f64);
628         ifn!("llvm.exp.v8f64", fn(t_v8f64) -> t_v8f64);
629
630         ifn!("llvm.exp2.f32", fn(t_f32) -> t_f32);
631         ifn!("llvm.exp2.v2f32", fn(t_v2f32) -> t_v2f32);
632         ifn!("llvm.exp2.v4f32", fn(t_v4f32) -> t_v4f32);
633         ifn!("llvm.exp2.v8f32", fn(t_v8f32) -> t_v8f32);
634         ifn!("llvm.exp2.v16f32", fn(t_v16f32) -> t_v16f32);
635         ifn!("llvm.exp2.f64", fn(t_f64) -> t_f64);
636         ifn!("llvm.exp2.v2f64", fn(t_v2f64) -> t_v2f64);
637         ifn!("llvm.exp2.v4f64", fn(t_v4f64) -> t_v4f64);
638         ifn!("llvm.exp2.v8f64", fn(t_v8f64) -> t_v8f64);
639
640         ifn!("llvm.log.f32", fn(t_f32) -> t_f32);
641         ifn!("llvm.log.v2f32", fn(t_v2f32) -> t_v2f32);
642         ifn!("llvm.log.v4f32", fn(t_v4f32) -> t_v4f32);
643         ifn!("llvm.log.v8f32", fn(t_v8f32) -> t_v8f32);
644         ifn!("llvm.log.v16f32", fn(t_v16f32) -> t_v16f32);
645         ifn!("llvm.log.f64", fn(t_f64) -> t_f64);
646         ifn!("llvm.log.v2f64", fn(t_v2f64) -> t_v2f64);
647         ifn!("llvm.log.v4f64", fn(t_v4f64) -> t_v4f64);
648         ifn!("llvm.log.v8f64", fn(t_v8f64) -> t_v8f64);
649
650         ifn!("llvm.log10.f32", fn(t_f32) -> t_f32);
651         ifn!("llvm.log10.v2f32", fn(t_v2f32) -> t_v2f32);
652         ifn!("llvm.log10.v4f32", fn(t_v4f32) -> t_v4f32);
653         ifn!("llvm.log10.v8f32", fn(t_v8f32) -> t_v8f32);
654         ifn!("llvm.log10.v16f32", fn(t_v16f32) -> t_v16f32);
655         ifn!("llvm.log10.f64", fn(t_f64) -> t_f64);
656         ifn!("llvm.log10.v2f64", fn(t_v2f64) -> t_v2f64);
657         ifn!("llvm.log10.v4f64", fn(t_v4f64) -> t_v4f64);
658         ifn!("llvm.log10.v8f64", fn(t_v8f64) -> t_v8f64);
659
660         ifn!("llvm.log2.f32", fn(t_f32) -> t_f32);
661         ifn!("llvm.log2.v2f32", fn(t_v2f32) -> t_v2f32);
662         ifn!("llvm.log2.v4f32", fn(t_v4f32) -> t_v4f32);
663         ifn!("llvm.log2.v8f32", fn(t_v8f32) -> t_v8f32);
664         ifn!("llvm.log2.v16f32", fn(t_v16f32) -> t_v16f32);
665         ifn!("llvm.log2.f64", fn(t_f64) -> t_f64);
666         ifn!("llvm.log2.v2f64", fn(t_v2f64) -> t_v2f64);
667         ifn!("llvm.log2.v4f64", fn(t_v4f64) -> t_v4f64);
668         ifn!("llvm.log2.v8f64", fn(t_v8f64) -> t_v8f64);
669
670         ifn!("llvm.fma.f32", fn(t_f32, t_f32, t_f32) -> t_f32);
671         ifn!("llvm.fma.v2f32", fn(t_v2f32, t_v2f32, t_v2f32) -> t_v2f32);
672         ifn!("llvm.fma.v4f32", fn(t_v4f32, t_v4f32, t_v4f32) -> t_v4f32);
673         ifn!("llvm.fma.v8f32", fn(t_v8f32, t_v8f32, t_v8f32) -> t_v8f32);
674         ifn!("llvm.fma.v16f32", fn(t_v16f32, t_v16f32, t_v16f32) -> t_v16f32);
675         ifn!("llvm.fma.f64", fn(t_f64, t_f64, t_f64) -> t_f64);
676         ifn!("llvm.fma.v2f64", fn(t_v2f64, t_v2f64, t_v2f64) -> t_v2f64);
677         ifn!("llvm.fma.v4f64", fn(t_v4f64, t_v4f64, t_v4f64) -> t_v4f64);
678         ifn!("llvm.fma.v8f64", fn(t_v8f64, t_v8f64, t_v8f64) -> t_v8f64);
679
680         ifn!("llvm.fabs.f32", fn(t_f32) -> t_f32);
681         ifn!("llvm.fabs.v2f32", fn(t_v2f32) -> t_v2f32);
682         ifn!("llvm.fabs.v4f32", fn(t_v4f32) -> t_v4f32);
683         ifn!("llvm.fabs.v8f32", fn(t_v8f32) -> t_v8f32);
684         ifn!("llvm.fabs.v16f32", fn(t_v16f32) -> t_v16f32);
685         ifn!("llvm.fabs.f64", fn(t_f64) -> t_f64);
686         ifn!("llvm.fabs.v2f64", fn(t_v2f64) -> t_v2f64);
687         ifn!("llvm.fabs.v4f64", fn(t_v4f64) -> t_v4f64);
688         ifn!("llvm.fabs.v8f64", fn(t_v8f64) -> t_v8f64);
689
690         ifn!("llvm.minnum.f32", fn(t_f32, t_f32) -> t_f32);
691         ifn!("llvm.minnum.f64", fn(t_f64, t_f64) -> t_f64);
692         ifn!("llvm.maxnum.f32", fn(t_f32, t_f32) -> t_f32);
693         ifn!("llvm.maxnum.f64", fn(t_f64, t_f64) -> t_f64);
694
695         ifn!("llvm.floor.f32", fn(t_f32) -> t_f32);
696         ifn!("llvm.floor.v2f32", fn(t_v2f32) -> t_v2f32);
697         ifn!("llvm.floor.v4f32", fn(t_v4f32) -> t_v4f32);
698         ifn!("llvm.floor.v8f32", fn(t_v8f32) -> t_v8f32);
699         ifn!("llvm.floor.v16f32", fn(t_v16f32) -> t_v16f32);
700         ifn!("llvm.floor.f64", fn(t_f64) -> t_f64);
701         ifn!("llvm.floor.v2f64", fn(t_v2f64) -> t_v2f64);
702         ifn!("llvm.floor.v4f64", fn(t_v4f64) -> t_v4f64);
703         ifn!("llvm.floor.v8f64", fn(t_v8f64) -> t_v8f64);
704
705         ifn!("llvm.ceil.f32", fn(t_f32) -> t_f32);
706         ifn!("llvm.ceil.v2f32", fn(t_v2f32) -> t_v2f32);
707         ifn!("llvm.ceil.v4f32", fn(t_v4f32) -> t_v4f32);
708         ifn!("llvm.ceil.v8f32", fn(t_v8f32) -> t_v8f32);
709         ifn!("llvm.ceil.v16f32", fn(t_v16f32) -> t_v16f32);
710         ifn!("llvm.ceil.f64", fn(t_f64) -> t_f64);
711         ifn!("llvm.ceil.v2f64", fn(t_v2f64) -> t_v2f64);
712         ifn!("llvm.ceil.v4f64", fn(t_v4f64) -> t_v4f64);
713         ifn!("llvm.ceil.v8f64", fn(t_v8f64) -> t_v8f64);
714
715         ifn!("llvm.trunc.f32", fn(t_f32) -> t_f32);
716         ifn!("llvm.trunc.f64", fn(t_f64) -> t_f64);
717
718         ifn!("llvm.copysign.f32", fn(t_f32, t_f32) -> t_f32);
719         ifn!("llvm.copysign.f64", fn(t_f64, t_f64) -> t_f64);
720         ifn!("llvm.round.f32", fn(t_f32) -> t_f32);
721         ifn!("llvm.round.f64", fn(t_f64) -> t_f64);
722
723         ifn!("llvm.rint.f32", fn(t_f32) -> t_f32);
724         ifn!("llvm.rint.f64", fn(t_f64) -> t_f64);
725         ifn!("llvm.nearbyint.f32", fn(t_f32) -> t_f32);
726         ifn!("llvm.nearbyint.f64", fn(t_f64) -> t_f64);
727
728         ifn!("llvm.ctpop.i8", fn(t_i8) -> t_i8);
729         ifn!("llvm.ctpop.i16", fn(t_i16) -> t_i16);
730         ifn!("llvm.ctpop.i32", fn(t_i32) -> t_i32);
731         ifn!("llvm.ctpop.i64", fn(t_i64) -> t_i64);
732         ifn!("llvm.ctpop.i128", fn(t_i128) -> t_i128);
733
734         ifn!("llvm.ctlz.i8", fn(t_i8, i1) -> t_i8);
735         ifn!("llvm.ctlz.i16", fn(t_i16, i1) -> t_i16);
736         ifn!("llvm.ctlz.i32", fn(t_i32, i1) -> t_i32);
737         ifn!("llvm.ctlz.i64", fn(t_i64, i1) -> t_i64);
738         ifn!("llvm.ctlz.i128", fn(t_i128, i1) -> t_i128);
739
740         ifn!("llvm.cttz.i8", fn(t_i8, i1) -> t_i8);
741         ifn!("llvm.cttz.i16", fn(t_i16, i1) -> t_i16);
742         ifn!("llvm.cttz.i32", fn(t_i32, i1) -> t_i32);
743         ifn!("llvm.cttz.i64", fn(t_i64, i1) -> t_i64);
744         ifn!("llvm.cttz.i128", fn(t_i128, i1) -> t_i128);
745
746         ifn!("llvm.bswap.i16", fn(t_i16) -> t_i16);
747         ifn!("llvm.bswap.i32", fn(t_i32) -> t_i32);
748         ifn!("llvm.bswap.i64", fn(t_i64) -> t_i64);
749         ifn!("llvm.bswap.i128", fn(t_i128) -> t_i128);
750
751         ifn!("llvm.bitreverse.i8", fn(t_i8) -> t_i8);
752         ifn!("llvm.bitreverse.i16", fn(t_i16) -> t_i16);
753         ifn!("llvm.bitreverse.i32", fn(t_i32) -> t_i32);
754         ifn!("llvm.bitreverse.i64", fn(t_i64) -> t_i64);
755         ifn!("llvm.bitreverse.i128", fn(t_i128) -> t_i128);
756
757         ifn!("llvm.fshl.i8", fn(t_i8, t_i8, t_i8) -> t_i8);
758         ifn!("llvm.fshl.i16", fn(t_i16, t_i16, t_i16) -> t_i16);
759         ifn!("llvm.fshl.i32", fn(t_i32, t_i32, t_i32) -> t_i32);
760         ifn!("llvm.fshl.i64", fn(t_i64, t_i64, t_i64) -> t_i64);
761         ifn!("llvm.fshl.i128", fn(t_i128, t_i128, t_i128) -> t_i128);
762
763         ifn!("llvm.fshr.i8", fn(t_i8, t_i8, t_i8) -> t_i8);
764         ifn!("llvm.fshr.i16", fn(t_i16, t_i16, t_i16) -> t_i16);
765         ifn!("llvm.fshr.i32", fn(t_i32, t_i32, t_i32) -> t_i32);
766         ifn!("llvm.fshr.i64", fn(t_i64, t_i64, t_i64) -> t_i64);
767         ifn!("llvm.fshr.i128", fn(t_i128, t_i128, t_i128) -> t_i128);
768
769         ifn!("llvm.sadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct! {t_i8, i1});
770         ifn!("llvm.sadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct! {t_i16, i1});
771         ifn!("llvm.sadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct! {t_i32, i1});
772         ifn!("llvm.sadd.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct! {t_i64, i1});
773         ifn!("llvm.sadd.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct! {t_i128, i1});
774
775         ifn!("llvm.uadd.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct! {t_i8, i1});
776         ifn!("llvm.uadd.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct! {t_i16, i1});
777         ifn!("llvm.uadd.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct! {t_i32, i1});
778         ifn!("llvm.uadd.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct! {t_i64, i1});
779         ifn!("llvm.uadd.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct! {t_i128, i1});
780
781         ifn!("llvm.ssub.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct! {t_i8, i1});
782         ifn!("llvm.ssub.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct! {t_i16, i1});
783         ifn!("llvm.ssub.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct! {t_i32, i1});
784         ifn!("llvm.ssub.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct! {t_i64, i1});
785         ifn!("llvm.ssub.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct! {t_i128, i1});
786
787         ifn!("llvm.usub.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct! {t_i8, i1});
788         ifn!("llvm.usub.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct! {t_i16, i1});
789         ifn!("llvm.usub.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct! {t_i32, i1});
790         ifn!("llvm.usub.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct! {t_i64, i1});
791         ifn!("llvm.usub.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct! {t_i128, i1});
792
793         ifn!("llvm.smul.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct! {t_i8, i1});
794         ifn!("llvm.smul.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct! {t_i16, i1});
795         ifn!("llvm.smul.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct! {t_i32, i1});
796         ifn!("llvm.smul.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct! {t_i64, i1});
797         ifn!("llvm.smul.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct! {t_i128, i1});
798
799         ifn!("llvm.umul.with.overflow.i8", fn(t_i8, t_i8) -> mk_struct! {t_i8, i1});
800         ifn!("llvm.umul.with.overflow.i16", fn(t_i16, t_i16) -> mk_struct! {t_i16, i1});
801         ifn!("llvm.umul.with.overflow.i32", fn(t_i32, t_i32) -> mk_struct! {t_i32, i1});
802         ifn!("llvm.umul.with.overflow.i64", fn(t_i64, t_i64) -> mk_struct! {t_i64, i1});
803         ifn!("llvm.umul.with.overflow.i128", fn(t_i128, t_i128) -> mk_struct! {t_i128, i1});
804
805         ifn!("llvm.sadd.sat.i8", fn(t_i8, t_i8) -> t_i8);
806         ifn!("llvm.sadd.sat.i16", fn(t_i16, t_i16) -> t_i16);
807         ifn!("llvm.sadd.sat.i32", fn(t_i32, t_i32) -> t_i32);
808         ifn!("llvm.sadd.sat.i64", fn(t_i64, t_i64) -> t_i64);
809         ifn!("llvm.sadd.sat.i128", fn(t_i128, t_i128) -> t_i128);
810
811         ifn!("llvm.uadd.sat.i8", fn(t_i8, t_i8) -> t_i8);
812         ifn!("llvm.uadd.sat.i16", fn(t_i16, t_i16) -> t_i16);
813         ifn!("llvm.uadd.sat.i32", fn(t_i32, t_i32) -> t_i32);
814         ifn!("llvm.uadd.sat.i64", fn(t_i64, t_i64) -> t_i64);
815         ifn!("llvm.uadd.sat.i128", fn(t_i128, t_i128) -> t_i128);
816
817         ifn!("llvm.ssub.sat.i8", fn(t_i8, t_i8) -> t_i8);
818         ifn!("llvm.ssub.sat.i16", fn(t_i16, t_i16) -> t_i16);
819         ifn!("llvm.ssub.sat.i32", fn(t_i32, t_i32) -> t_i32);
820         ifn!("llvm.ssub.sat.i64", fn(t_i64, t_i64) -> t_i64);
821         ifn!("llvm.ssub.sat.i128", fn(t_i128, t_i128) -> t_i128);
822
823         ifn!("llvm.usub.sat.i8", fn(t_i8, t_i8) -> t_i8);
824         ifn!("llvm.usub.sat.i16", fn(t_i16, t_i16) -> t_i16);
825         ifn!("llvm.usub.sat.i32", fn(t_i32, t_i32) -> t_i32);
826         ifn!("llvm.usub.sat.i64", fn(t_i64, t_i64) -> t_i64);
827         ifn!("llvm.usub.sat.i128", fn(t_i128, t_i128) -> t_i128);
828
829         ifn!("llvm.lifetime.start.p0i8", fn(t_i64, i8p) -> void);
830         ifn!("llvm.lifetime.end.p0i8", fn(t_i64, i8p) -> void);
831
832         ifn!("llvm.expect.i1", fn(i1, i1) -> i1);
833         ifn!("llvm.eh.typeid.for", fn(i8p) -> t_i32);
834         ifn!("llvm.localescape", fn(...) -> void);
835         ifn!("llvm.localrecover", fn(i8p, i8p, t_i32) -> i8p);
836         ifn!("llvm.x86.seh.recoverfp", fn(i8p, i8p) -> i8p);
837
838         ifn!("llvm.assume", fn(i1) -> void);
839         ifn!("llvm.prefetch", fn(i8p, t_i32, t_i32, t_i32) -> void);
840
841         // variadic intrinsics
842         ifn!("llvm.va_start", fn(i8p) -> void);
843         ifn!("llvm.va_end", fn(i8p) -> void);
844         ifn!("llvm.va_copy", fn(i8p, i8p) -> void);
845
846         if self.sess().opts.debuginfo != DebugInfo::None {
847             ifn!("llvm.dbg.declare", fn(self.type_metadata(), self.type_metadata()) -> void);
848             ifn!("llvm.dbg.value", fn(self.type_metadata(), t_i64, self.type_metadata()) -> void);
849         }
850         return None;
851     }
852 }
853
854 impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
855     /// Generates a new symbol name with the given prefix. This symbol name must
856     /// only be used for definitions with `internal` or `private` linkage.
857     pub fn generate_local_symbol_name(&self, prefix: &str) -> String {
858         let idx = self.local_gen_sym_counter.get();
859         self.local_gen_sym_counter.set(idx + 1);
860         // Include a '.' character, so there can be no accidental conflicts with
861         // user defined names
862         let mut name = String::with_capacity(prefix.len() + 6);
863         name.push_str(prefix);
864         name.push_str(".");
865         base_n::push_str(idx as u128, base_n::ALPHANUMERIC_ONLY, &mut name);
866         name
867     }
868 }
869
870 impl ty::layout::HasDataLayout for CodegenCx<'ll, 'tcx> {
871     fn data_layout(&self) -> &ty::layout::TargetDataLayout {
872         &self.tcx.data_layout
873     }
874 }
875
876 impl HasTargetSpec for CodegenCx<'ll, 'tcx> {
877     fn target_spec(&self) -> &Target {
878         &self.tcx.sess.target.target
879     }
880 }
881
882 impl ty::layout::HasTyCtxt<'tcx> for CodegenCx<'ll, 'tcx> {
883     fn tcx(&self) -> TyCtxt<'tcx> {
884         self.tcx
885     }
886 }
887
888 impl LayoutOf for CodegenCx<'ll, 'tcx> {
889     type Ty = Ty<'tcx>;
890     type TyLayout = TyLayout<'tcx>;
891
892     fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
893         self.spanned_layout_of(ty, DUMMY_SP)
894     }
895
896     fn spanned_layout_of(&self, ty: Ty<'tcx>, span: Span) -> Self::TyLayout {
897         self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)).unwrap_or_else(|e| {
898             if let LayoutError::SizeOverflow(_) = e {
899                 self.sess().span_fatal(span, &e.to_string())
900             } else {
901                 bug!("failed to get layout for `{}`: {}", ty, e)
902             }
903         })
904     }
905 }
906
907 impl<'tcx, 'll> HasParamEnv<'tcx> for CodegenCx<'ll, 'tcx> {
908     fn param_env(&self) -> ty::ParamEnv<'tcx> {
909         ty::ParamEnv::reveal_all()
910     }
911 }