about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEduard-Mihai Burtescu <edy.burt@gmail.com>2017-06-18 17:42:03 +0300
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2017-11-19 02:14:28 +0200
commit260c41b4b808fd9995f23ce1eb7d820f49254c85 (patch)
treea59bd048e170b942de78d36a8b7c5028f0263437 /src
parentb8671bef977723bd5983fc3130910d2e5a8b6cd9 (diff)
rustc_trans: do not introspect LLVM aggregate field types.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_llvm/ffi.rs2
-rw-r--r--src/librustc_trans/mir/constant.rs15
-rw-r--r--src/librustc_trans/mir/operand.rs19
-rw-r--r--src/librustc_trans/mir/rvalue.rs15
-rw-r--r--src/librustc_trans/type_.rs13
5 files changed, 14 insertions, 50 deletions
diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs
index 4d02274eadd..0f96a22f897 100644
--- a/src/librustc_llvm/ffi.rs
+++ b/src/librustc_llvm/ffi.rs
@@ -575,8 +575,6 @@ extern "C" {
                                    ElementCount: c_uint,
                                    Packed: Bool)
                                    -> TypeRef;
-    pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
-    pub fn LLVMGetStructElementTypes(StructTy: TypeRef, Dest: *mut TypeRef);
     pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
 
     // Operations on array, pointer, and vector types (sequence types)
diff --git a/src/librustc_trans/mir/constant.rs b/src/librustc_trans/mir/constant.rs
index fa0558faad2..d4289363ecf 100644
--- a/src/librustc_trans/mir/constant.rs
+++ b/src/librustc_trans/mir/constant.rs
@@ -736,20 +736,17 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
                         }
                     }
                     mir::CastKind::Misc => { // Casts from a fat-ptr.
-                        let ll_cast_ty = type_of::immediate_type_of(self.ccx, cast_ty);
-                        let ll_from_ty = type_of::immediate_type_of(self.ccx, operand.ty);
                         if common::type_is_fat_ptr(self.ccx, operand.ty) {
-                            let (data_ptr, meta_ptr) = operand.get_fat_ptr(self.ccx);
+                            let (data_ptr, meta) = operand.get_fat_ptr(self.ccx);
                             if common::type_is_fat_ptr(self.ccx, cast_ty) {
-                                let ll_cft = ll_cast_ty.field_types();
-                                let ll_fft = ll_from_ty.field_types();
-                                let data_cast = consts::ptrcast(data_ptr, ll_cft[0]);
-                                assert_eq!(ll_cft[1].kind(), ll_fft[1].kind());
-                                C_struct(self.ccx, &[data_cast, meta_ptr], false)
+                                let llcast_ty = type_of::fat_ptr_base_ty(self.ccx, cast_ty);
+                                let data_cast = consts::ptrcast(data_ptr, llcast_ty);
+                                C_struct(self.ccx, &[data_cast, meta], false)
                             } else { // cast to thin-ptr
                                 // Cast of fat-ptr to thin-ptr is an extraction of data-ptr and
                                 // pointer-cast of that pointer to desired pointer type.
-                                consts::ptrcast(data_ptr, ll_cast_ty)
+                                let llcast_ty = type_of::immediate_type_of(self.ccx, cast_ty);
+                                consts::ptrcast(data_ptr, llcast_ty)
                             }
                         } else {
                             bug!("Unexpected non-fat-pointer operand")
diff --git a/src/librustc_trans/mir/operand.rs b/src/librustc_trans/mir/operand.rs
index 60f585f4bd9..f4285c2ad0a 100644
--- a/src/librustc_trans/mir/operand.rs
+++ b/src/librustc_trans/mir/operand.rs
@@ -27,6 +27,7 @@ use std::fmt;
 use std::ptr;
 
 use super::{MirContext, LocalRef};
+use super::constant::Const;
 use super::lvalue::{Alignment, LvalueRef};
 
 /// The representation of a Rust value. The enum variant is in fact
@@ -84,23 +85,7 @@ impl<'a, 'tcx> OperandRef<'tcx> {
                    ty: Ty<'tcx>) -> OperandRef<'tcx> {
         assert!(common::type_is_zero_size(ccx, ty));
         let llty = type_of::type_of(ccx, ty);
-        let val = if common::type_is_imm_pair(ccx, ty) {
-            let layout = ccx.layout_of(ty);
-            let (ix0, ix1) = if let Layout::Univariant { ref variant, .. } = *layout {
-                (adt::struct_llfields_index(variant, 0),
-                adt::struct_llfields_index(variant, 1))
-            } else {
-                (0, 1)
-            };
-            let fields = llty.field_types();
-            OperandValue::Pair(C_undef(fields[ix0]), C_undef(fields[ix1]))
-        } else {
-            OperandValue::Immediate(C_undef(llty))
-        };
-        OperandRef {
-            val,
-            ty,
-        }
+        Const::new(C_undef(llty), ty).to_operand(ccx)
     }
 
     /// Asserts that this operand refers to a scalar and returns
diff --git a/src/librustc_trans/mir/rvalue.rs b/src/librustc_trans/mir/rvalue.rs
index 7e4b7235750..d975ed8cda4 100644
--- a/src/librustc_trans/mir/rvalue.rs
+++ b/src/librustc_trans/mir/rvalue.rs
@@ -263,19 +263,16 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
                         }
                     }
                     mir::CastKind::Misc if common::type_is_fat_ptr(bcx.ccx, operand.ty) => {
-                        let ll_cast_ty = type_of::immediate_type_of(bcx.ccx, cast_ty);
-                        let ll_from_ty = type_of::immediate_type_of(bcx.ccx, operand.ty);
-                        if let OperandValue::Pair(data_ptr, meta_ptr) = operand.val {
+                        if let OperandValue::Pair(data_ptr, meta) = operand.val {
                             if common::type_is_fat_ptr(bcx.ccx, cast_ty) {
-                                let ll_cft = ll_cast_ty.field_types();
-                                let ll_fft = ll_from_ty.field_types();
-                                let data_cast = bcx.pointercast(data_ptr, ll_cft[0]);
-                                assert_eq!(ll_cft[1].kind(), ll_fft[1].kind());
-                                OperandValue::Pair(data_cast, meta_ptr)
+                                let llcast_ty = type_of::fat_ptr_base_ty(bcx.ccx, cast_ty);
+                                let data_cast = bcx.pointercast(data_ptr, llcast_ty);
+                                OperandValue::Pair(data_cast, meta)
                             } else { // cast to thin-ptr
                                 // Cast of fat-ptr to thin-ptr is an extraction of data-ptr and
                                 // pointer-cast of that pointer to desired pointer type.
-                                let llval = bcx.pointercast(data_ptr, ll_cast_ty);
+                                let llcast_ty = type_of::immediate_type_of(bcx.ccx, cast_ty);
+                                let llval = bcx.pointercast(data_ptr, llcast_ty);
                                 OperandValue::Immediate(llval)
                             }
                         } else {
diff --git a/src/librustc_trans/type_.rs b/src/librustc_trans/type_.rs
index 098c5b2d957..bb8f3f23108 100644
--- a/src/librustc_trans/type_.rs
+++ b/src/librustc_trans/type_.rs
@@ -249,19 +249,6 @@ impl Type {
         }
     }
 
-    pub fn field_types(&self) -> Vec<Type> {
-        unsafe {
-            let n_elts = llvm::LLVMCountStructElementTypes(self.to_ref()) as usize;
-            if n_elts == 0 {
-                return Vec::new();
-            }
-            let mut elts = vec![Type { rf: ptr::null_mut() }; n_elts];
-            llvm::LLVMGetStructElementTypes(self.to_ref(),
-                                            elts.as_mut_ptr() as *mut TypeRef);
-            elts
-        }
-    }
-
     pub fn func_params(&self) -> Vec<Type> {
         unsafe {
             let n_args = llvm::LLVMCountParamTypes(self.to_ref()) as usize;