rustc_trans: do not introspect LLVM aggregate field types.

This commit is contained in:
Eduard-Mihai Burtescu 2017-06-18 17:42:03 +03:00
parent b8671bef97
commit 260c41b4b8
5 changed files with 14 additions and 50 deletions

View File

@ -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)

View File

@ -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")

View File

@ -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

View File

@ -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 {

View File

@ -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;