//! Handling of `static`s, `const`s and promoted allocations
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
-use rustc_errors::ErrorReported;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::interpret::{
- read_target_uint, AllocId, Allocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar,
+ read_target_uint, AllocId, ConstAllocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar,
};
use rustc_middle::ty::ConstKind;
use rustc_span::DUMMY_SP;
ConstantKind::Ty(ct) => ct,
ConstantKind::Val(..) => continue,
};
- match const_.val {
+ match const_.val() {
ConstKind::Value(_) => {}
ConstKind::Unevaluated(unevaluated) => {
if let Err(err) =
{
all_constants_ok = false;
match err {
- ErrorHandled::Reported(ErrorReported) | ErrorHandled::Linted => {
+ ErrorHandled::Reported(_) | ErrorHandled::Linted => {
fx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
}
ErrorHandled::TooGeneric => {
ConstantKind::Ty(ct) => ct,
ConstantKind::Val(val, ty) => return codegen_const_value(fx, val, ty),
};
- let const_val = match const_.val {
+ let const_val = match const_.val() {
ConstKind::Value(const_val) => const_val,
- ConstKind::Unevaluated(uv) if fx.tcx.is_static(uv.def.did) => {
- assert!(uv.substs(fx.tcx).is_empty());
- assert!(uv.promoted.is_none());
+ ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted })
+ if fx.tcx.is_static(def.did) =>
+ {
+ assert!(substs.is_empty());
+ assert!(promoted.is_none());
- return codegen_static_ref(fx, uv.def.did, fx.layout_of(const_.ty)).to_cvalue(fx);
+ return codegen_static_ref(fx, def.did, fx.layout_of(const_.ty())).to_cvalue(fx);
}
ConstKind::Unevaluated(unevaluated) => {
match fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None) {
| ConstKind::Error(_) => unreachable!("{:?}", const_),
};
- codegen_const_value(fx, const_val, const_.ty)
+ codegen_const_value(fx, const_val, const_.ty())
}
pub(crate) fn codegen_const_value<'tcx>(
&mut fx.constants_cx,
fx.module,
alloc_id,
- alloc.mutability,
+ alloc.inner().mutability,
);
let local_data_id =
fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
}
}
-pub(crate) fn pointer_for_allocation<'tcx>(
+fn pointer_for_allocation<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>,
- alloc: &'tcx Allocation,
+ alloc: ConstAllocation<'tcx>,
) -> crate::pointer::Pointer {
let alloc_id = fx.tcx.create_memory_alloc(alloc);
- let data_id =
- data_id_for_alloc_id(&mut fx.constants_cx, &mut *fx.module, alloc_id, alloc.mutability);
+ let data_id = data_id_for_alloc_id(
+ &mut fx.constants_cx,
+ &mut *fx.module,
+ alloc_id,
+ alloc.inner().mutability,
+ );
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
if fx.clif_comments.enabled() {
let data_id = *cx.anon_allocs.entry(alloc_id).or_insert_with(|| {
module
.declare_anonymous_data(
- alloc.mutability == rustc_hir::Mutability::Mut,
+ alloc.inner().mutability == rustc_hir::Mutability::Mut,
false,
)
.unwrap()
}
let mut data_ctx = DataContext::new();
+ let alloc = alloc.inner();
data_ctx.set_align(alloc.align.bytes());
if let Some(section_name) = section_name {
continue;
}
GlobalAlloc::Memory(target_alloc) => {
- data_id_for_alloc_id(cx, module, alloc_id, target_alloc.mutability)
+ data_id_for_alloc_id(cx, module, alloc_id, target_alloc.inner().mutability)
}
GlobalAlloc::Static(def_id) => {
if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::THREAD_LOCAL)
match operand {
Operand::Constant(const_) => match const_.literal {
ConstantKind::Ty(const_) => {
- fx.monomorphize(const_).eval(fx.tcx, ParamEnv::reveal_all()).val.try_to_value()
+ fx.monomorphize(const_).eval(fx.tcx, ParamEnv::reveal_all()).val().try_to_value()
}
ConstantKind::Val(val, _) => Some(val),
},
return None;
}
let const_val = mir_operand_get_const_val(fx, operand)?;
- if fx.layout_of(ty).size
+ if fx.layout_of(*ty).size
!= const_val.try_to_scalar_int()?.size()
{
return None;
StatementKind::Assign(_)
| StatementKind::FakeRead(_)
| StatementKind::SetDiscriminant { .. }
+ | StatementKind::Deinit(_)
| StatementKind::StorageLive(_)
| StatementKind::StorageDead(_)
| StatementKind::Retag(_, _)