|
10 | 10 |
|
11 | 11 | use llvm::{self, ValueRef};
|
12 | 12 | use rustc::ty::{self, Ty, TypeFoldable};
|
13 |
| -use rustc::ty::layout::{self, Align, FullLayout, Layout, LayoutOf}; |
| 13 | +use rustc::ty::layout::{self, Align, FullLayout, LayoutOf}; |
14 | 14 | use rustc::mir;
|
15 | 15 | use rustc::mir::tcx::LvalueTy;
|
16 | 16 | use rustc_data_structures::indexed_vec::Idx;
|
17 | 17 | use abi;
|
18 |
| -use adt; |
19 | 18 | use base;
|
20 | 19 | use builder::Builder;
|
21 | 20 | use common::{self, CrateContext, C_usize, C_u8, C_u32, C_uint, C_int, C_null, val_ty};
|
22 | 21 | use consts;
|
23 |
| -use type_of::LayoutLlvmExt; |
| 22 | +use type_of::{self, LayoutLlvmExt}; |
24 | 23 | use type_::Type;
|
25 | 24 | use value::Value;
|
26 | 25 | use glue;
|
@@ -206,52 +205,26 @@ impl<'a, 'tcx> LvalueRef<'tcx> {
|
206 | 205 | let alignment = self.alignment | Alignment::from(l);
|
207 | 206 |
|
208 | 207 | // Unions and newtypes only use an offset of 0.
|
209 |
| - match *l.layout { |
210 |
| - // FIXME(eddyb) The fields of a fat pointer aren't correct, especially |
211 |
| - // to unsized structs, we can't represent their pointee types in `Ty`. |
212 |
| - Layout::FatPointer { .. } => {} |
213 |
| - |
214 |
| - _ if offset == 0 => { |
215 |
| - let ty = ccx.llvm_type_of(field.ty); |
216 |
| - return LvalueRef { |
217 |
| - llval: bcx.pointercast(self.llval, ty.ptr_to()), |
218 |
| - llextra: if field.is_unsized() { |
219 |
| - self.llextra |
220 |
| - } else { |
221 |
| - ptr::null_mut() |
222 |
| - }, |
223 |
| - ty: LvalueTy::from_ty(field.ty), |
224 |
| - alignment, |
225 |
| - }; |
226 |
| - } |
227 |
| - |
228 |
| - _ => {} |
229 |
| - } |
230 |
| - |
231 |
| - // Discriminant field of enums. |
232 |
| - if let layout::NullablePointer { .. } = *l.layout { |
233 |
| - let ty = ccx.llvm_type_of(field.ty); |
234 |
| - let size = field.size(ccx).bytes(); |
235 |
| - |
236 |
| - // If the discriminant is not on a multiple of the primitive's size, |
237 |
| - // we need to go through i8*. Also assume the worst alignment. |
238 |
| - if offset % size != 0 { |
239 |
| - let byte_ptr = bcx.pointercast(self.llval, Type::i8p(ccx)); |
240 |
| - let byte_ptr = bcx.inbounds_gep(byte_ptr, &[C_usize(ccx, offset)]); |
241 |
| - let byte_align = Alignment::Packed(Align::from_bytes(1, 1).unwrap()); |
242 |
| - return LvalueRef::new_sized( |
243 |
| - bcx.pointercast(byte_ptr, ty.ptr_to()), field.ty, byte_align); |
| 208 | + let has_llvm_fields = match *l.fields { |
| 209 | + layout::FieldPlacement::Union(_) => false, |
| 210 | + layout::FieldPlacement::Array { .. } => true, |
| 211 | + layout::FieldPlacement::Arbitrary { .. } => { |
| 212 | + match l.abi { |
| 213 | + layout::Abi::Scalar(_) | layout::Abi::Vector { .. } => false, |
| 214 | + layout::Abi::Aggregate { .. } => true |
| 215 | + } |
244 | 216 | }
|
245 |
| - |
246 |
| - let discr_ptr = bcx.pointercast(self.llval, ty.ptr_to()); |
247 |
| - return LvalueRef::new_sized( |
248 |
| - bcx.inbounds_gep(discr_ptr, &[C_usize(ccx, offset / size)]), |
249 |
| - field.ty, alignment); |
250 |
| - } |
| 217 | + }; |
251 | 218 |
|
252 | 219 | let simple = || {
|
253 | 220 | LvalueRef {
|
254 |
| - llval: bcx.struct_gep(self.llval, l.llvm_field_index(ix)), |
| 221 | + llval: if has_llvm_fields { |
| 222 | + bcx.struct_gep(self.llval, l.llvm_field_index(ix)) |
| 223 | + } else { |
| 224 | + assert_eq!(offset, 0); |
| 225 | + let ty = ccx.llvm_type_of(field.ty); |
| 226 | + bcx.pointercast(self.llval, ty.ptr_to()) |
| 227 | + }, |
255 | 228 | llextra: if ccx.shared().type_has_metadata(field.ty) {
|
256 | 229 | self.llextra
|
257 | 230 | } else {
|
@@ -460,7 +433,7 @@ impl<'a, 'tcx> LvalueRef<'tcx> {
|
460 | 433 | layout::General { .. } => {
|
461 | 434 | let variant_layout = layout.for_variant(variant_index);
|
462 | 435 | let variant_ty = Type::struct_(bcx.ccx,
|
463 |
| - &adt::struct_llfields(bcx.ccx, variant_layout), |
| 436 | + &type_of::struct_llfields(bcx.ccx, variant_layout), |
464 | 437 | variant_layout.is_packed());
|
465 | 438 | downcast.llval = bcx.pointercast(downcast.llval, variant_ty.ptr_to());
|
466 | 439 | }
|
|
0 commit comments