Address review comments
This commit is contained in:
@@ -469,7 +469,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
|
||||
// Notice that every static has two `AllocId` that will resolve to the same
|
||||
// thing here: one maps to `GlobalAlloc::Static`, this is the "lazy" ID,
|
||||
// and the other one is maps to `GlobalAlloc::Memory`, this is returned by
|
||||
// `const_eval` and it is the "resolved" ID.
|
||||
// `eval_static_initializer` and it is the "resolved" ID.
|
||||
// The resolved ID is never used by the interpreted program, it is hidden.
|
||||
// This is relied upon for soundness of const-patterns; a pointer to the resolved
|
||||
// ID would "sidestep" the checks that make sure consts do not point to statics!
|
||||
|
||||
@@ -13,9 +13,9 @@ use rustc_target::abi::{Abi, Align, FieldsShape, TagEncoding};
|
||||
use rustc_target::abi::{HasDataLayout, LayoutOf, Size, VariantIdx, Variants};
|
||||
|
||||
use super::{
|
||||
mir_assign_valid_types, truncate, AllocId, AllocMap, Allocation, AllocationExtra, ImmTy,
|
||||
Immediate, InterpCx, InterpResult, LocalValue, Machine, MemoryKind, OpTy, Operand, Pointer,
|
||||
PointerArithmetic, RawConst, Scalar, ScalarMaybeUninit,
|
||||
mir_assign_valid_types, truncate, AllocId, AllocMap, Allocation, AllocationExtra, ConstAlloc,
|
||||
ImmTy, Immediate, InterpCx, InterpResult, LocalValue, Machine, MemoryKind, OpTy, Operand,
|
||||
Pointer, PointerArithmetic, Scalar, ScalarMaybeUninit,
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable)]
|
||||
@@ -1122,7 +1122,7 @@ where
|
||||
|
||||
pub fn raw_const_to_mplace(
|
||||
&self,
|
||||
raw: RawConst<'tcx>,
|
||||
raw: ConstAlloc<'tcx>,
|
||||
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
|
||||
// This must be an allocation in `tcx`
|
||||
let _ = self.tcx.global_alloc(raw.alloc_id);
|
||||
|
||||
@@ -426,27 +426,27 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
|
||||
if let Some(GlobalAlloc::Static(did)) = alloc_kind {
|
||||
assert!(!self.ecx.tcx.is_thread_local_static(did));
|
||||
assert!(self.ecx.tcx.is_static(did));
|
||||
// See const_eval::machine::MemoryExtra::can_access_statics for why
|
||||
// this check is so important.
|
||||
// This check is reachable when the const just referenced the static,
|
||||
// but never read it (so we never entered `before_access_global`).
|
||||
// We also need to do it here instead of going on to avoid running
|
||||
// into the `before_access_global` check during validation.
|
||||
if !self.may_ref_to_static {
|
||||
if self.may_ref_to_static {
|
||||
// We skip checking other statics. These statics must be sound by
|
||||
// themselves, and the only way to get broken statics here is by using
|
||||
// unsafe code.
|
||||
// The reasons we don't check other statics is twofold. For one, in all
|
||||
// sound cases, the static was already validated on its own, and second, we
|
||||
// trigger cycle errors if we try to compute the value of the other static
|
||||
// and that static refers back to us.
|
||||
// We might miss const-invalid data,
|
||||
// but things are still sound otherwise (in particular re: consts
|
||||
// referring to statics).
|
||||
return Ok(());
|
||||
} else {
|
||||
// See const_eval::machine::MemoryExtra::can_access_statics for why
|
||||
// this check is so important.
|
||||
// This check is reachable when the const just referenced the static,
|
||||
// but never read it (so we never entered `before_access_global`).
|
||||
throw_validation_failure!(self.path,
|
||||
{ "a {} pointing to a static variable", kind }
|
||||
);
|
||||
}
|
||||
// We skip checking other statics. These statics must be sound by themselves,
|
||||
// and the only way to get broken statics here is by using unsafe code.
|
||||
// The reasons we don't check other statics is twofold. For one, in all sound
|
||||
// cases, the static was already validated on its own, and second, we trigger
|
||||
// cycle errors if we try to compute the value of the other static and that
|
||||
// static refers back to us.
|
||||
// We might miss const-invalid data,
|
||||
// but things are still sound otherwise (in particular re: consts
|
||||
// referring to statics).
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
// Proceed recursively even for ZST, no reason to skip them!
|
||||
|
||||
Reference in New Issue
Block a user