Remove old pointee_info_at body.
This commit is contained in:
parent
ed716d4c89
commit
f1f9343c3d
@ -7,13 +7,19 @@ use crate::value::Value;
|
||||
use rustc_codegen_ssa::MemFlags;
|
||||
use rustc_codegen_ssa::mir::place::PlaceRef;
|
||||
use rustc_codegen_ssa::mir::operand::OperandValue;
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
use type_::Type;
|
||||
use type_of::{LayoutLlvmExt};
|
||||
use value::Value;
|
||||
>>>>>>> Remove old pointee_info_at body.
|
||||
use rustc_target::abi::call::ArgType;
|
||||
|
||||
use rustc_codegen_ssa::traits::*;
|
||||
|
||||
use rustc_target::abi::{HasDataLayout, LayoutOf, Size, TyLayout, Abi as LayoutAbi};
|
||||
use rustc::ty::{self, Ty, Instance};
|
||||
use rustc::ty::layout;
|
||||
use rustc::ty::layout::{self, PointerKind};
|
||||
|
||||
use libc::c_uint;
|
||||
|
||||
|
@ -16,7 +16,7 @@ use rustc_data_structures::small_c_str::SmallCStr;
|
||||
use rustc::mir::mono::Stats;
|
||||
use rustc::session::config::{self, DebugInfo};
|
||||
use rustc::session::Session;
|
||||
use rustc::ty::layout::{LayoutError, LayoutOf, Size, TyLayout, VariantIdx};
|
||||
use rustc::ty::layout::{LayoutError, LayoutOf, PointeeInfo, Size, TyLayout, VariantIdx};
|
||||
use rustc::ty::{self, Ty, TyCtxt};
|
||||
use rustc::util::nodemap::FxHashMap;
|
||||
use rustc_target::spec::{HasTargetSpec, Target};
|
||||
|
@ -2,9 +2,11 @@ use crate::abi::{FnType, FnTypeExt};
|
||||
use crate::common::*;
|
||||
use crate::type_::Type;
|
||||
use rustc::hir;
|
||||
use abi::{FnType, FnTypeExt};
|
||||
use common::*;
|
||||
use rustc::ty::{self, Ty, TypeFoldable};
|
||||
use rustc::ty::layout::{self, Align, LayoutOf, Size, TyLayout};
|
||||
use rustc_target::abi::FloatTy;
|
||||
use rustc::ty::layout::{self, Align, LayoutOf, PointeeInfo, Size, TyLayout};
|
||||
use rustc_target::abi::{FloatTy, TyLayoutMethods};
|
||||
use rustc_mir::monomorphize::item::DefPathBasedNames;
|
||||
use rustc_codegen_ssa::traits::*;
|
||||
|
||||
@ -174,28 +176,6 @@ impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
pub enum PointerKind {
|
||||
/// Most general case, we know no restrictions to tell LLVM.
|
||||
Shared,
|
||||
|
||||
/// `&T` where `T` contains no `UnsafeCell`, is `noalias` and `readonly`.
|
||||
Frozen,
|
||||
|
||||
/// `&mut T`, when we know `noalias` is safe for LLVM.
|
||||
UniqueBorrowed,
|
||||
|
||||
/// `Box<T>`, unlike `UniqueBorrowed`, it also has `noalias` on returns.
|
||||
UniqueOwned
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PointeeInfo {
|
||||
pub size: Size,
|
||||
pub align: Align,
|
||||
pub safe: Option<PointerKind>,
|
||||
}
|
||||
|
||||
pub trait LayoutLlvmExt<'tcx> {
|
||||
fn is_llvm_immediate(&self) -> bool;
|
||||
fn is_llvm_scalar_pair<'a>(&self) -> bool;
|
||||
@ -406,112 +386,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
|
||||
return pointee;
|
||||
}
|
||||
|
||||
let mut result = None;
|
||||
match self.ty.sty {
|
||||
ty::RawPtr(mt) if offset.bytes() == 0 => {
|
||||
let (size, align) = cx.size_and_align_of(mt.ty);
|
||||
result = Some(PointeeInfo {
|
||||
size,
|
||||
align,
|
||||
safe: None
|
||||
});
|
||||
}
|
||||
|
||||
ty::Ref(_, ty, mt) if offset.bytes() == 0 => {
|
||||
let (size, align) = cx.size_and_align_of(ty);
|
||||
|
||||
let kind = match mt {
|
||||
hir::MutImmutable => if cx.type_is_freeze(ty) {
|
||||
PointerKind::Frozen
|
||||
} else {
|
||||
PointerKind::Shared
|
||||
},
|
||||
hir::MutMutable => {
|
||||
// Previously we would only emit noalias annotations for LLVM >= 6 or in
|
||||
// panic=abort mode. That was deemed right, as prior versions had many bugs
|
||||
// in conjunction with unwinding, but later versions didn’t seem to have
|
||||
// said issues. See issue #31681.
|
||||
//
|
||||
// Alas, later on we encountered a case where noalias would generate wrong
|
||||
// code altogether even with recent versions of LLVM in *safe* code with no
|
||||
// unwinding involved. See #54462.
|
||||
//
|
||||
// For now, do not enable mutable_noalias by default at all, while the
|
||||
// issue is being figured out.
|
||||
let mutable_noalias = cx.tcx.sess.opts.debugging_opts.mutable_noalias
|
||||
.unwrap_or(false);
|
||||
if mutable_noalias {
|
||||
PointerKind::UniqueBorrowed
|
||||
} else {
|
||||
PointerKind::Shared
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
result = Some(PointeeInfo {
|
||||
size,
|
||||
align,
|
||||
safe: Some(kind)
|
||||
});
|
||||
}
|
||||
|
||||
_ => {
|
||||
let mut data_variant = match self.variants {
|
||||
// Within the discriminant field, only the niche itself is
|
||||
// always initialized, so we only check for a pointer at its
|
||||
// offset.
|
||||
//
|
||||
// If the niche is a pointer, it's either valid (according
|
||||
// to its type), or null (which the niche field's scalar
|
||||
// validity range encodes). This allows using
|
||||
// `dereferenceable_or_null` for e.g., `Option<&T>`, and
|
||||
// this will continue to work as long as we don't start
|
||||
// using more niches than just null (e.g., the first page of
|
||||
// the address space, or unaligned pointers).
|
||||
layout::Variants::Multiple {
|
||||
discr_kind: layout::DiscriminantKind::Niche {
|
||||
dataful_variant,
|
||||
..
|
||||
},
|
||||
discr_index,
|
||||
..
|
||||
} if self.fields.offset(discr_index) == offset =>
|
||||
Some(self.for_variant(cx, dataful_variant)),
|
||||
_ => Some(*self),
|
||||
};
|
||||
|
||||
if let Some(variant) = data_variant {
|
||||
// We're not interested in any unions.
|
||||
if let layout::FieldPlacement::Union(_) = variant.fields {
|
||||
data_variant = None;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(variant) = data_variant {
|
||||
let ptr_end = offset + layout::Pointer.size(cx);
|
||||
for i in 0..variant.fields.count() {
|
||||
let field_start = variant.fields.offset(i);
|
||||
if field_start <= offset {
|
||||
let field = variant.field(cx, i);
|
||||
if ptr_end <= field_start + field.size {
|
||||
// We found the right field, look inside it.
|
||||
result = field.pointee_info_at(cx, offset - field_start);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(eddyb) This should be for `ptr::Unique<T>`, not `Box<T>`.
|
||||
if let Some(ref mut pointee) = result {
|
||||
if let ty::Adt(def, _) = self.ty.sty {
|
||||
if def.is_box() && offset.bytes() == 0 {
|
||||
pointee.safe = Some(PointerKind::UniqueOwned);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let result = Ty::pointee_info_at(*self, cx, offset);
|
||||
|
||||
cx.pointee_infos.borrow_mut().insert((self.ty, offset), result);
|
||||
result
|
||||
|
Loading…
x
Reference in New Issue
Block a user