Rollup merge of #129608 - RalfJung:const-eval-ub-checks, r=saethlin

const-eval: do not make UbChecks behavior depend on current crate's flags

Fixes https://github.com/rust-lang/rust/issues/129552

Let's see if we can get away with just always enabling these checks.
This commit is contained in:
Matthias Krüger 2024-08-28 17:12:17 +02:00 committed by GitHub
commit 3456b1d245
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 1 deletions

View File

@ -280,6 +280,9 @@ pub trait Machine<'tcx>: Sized {
Ok(()) Ok(())
} }
/// Determines the result of a `NullaryOp::UbChecks` invocation.
fn ub_checks(_ecx: &InterpCx<'tcx, Self>) -> InterpResult<'tcx, bool>;
/// Called when the interpreter encounters a `StatementKind::ConstEvalCounter` instruction. /// Called when the interpreter encounters a `StatementKind::ConstEvalCounter` instruction.
/// You can use this to detect long or endlessly running programs. /// You can use this to detect long or endlessly running programs.
#[inline] #[inline]
@ -627,6 +630,13 @@ pub macro compile_time_machine(<$tcx: lifetime>) {
match fn_val {} match fn_val {}
} }
#[inline(always)]
fn ub_checks(_ecx: &InterpCx<$tcx, Self>) -> InterpResult<$tcx, bool> {
// We can't look at `tcx.sess` here as that can differ across crates, which can lead to
// unsound differences in evaluating the same constant at different instantiation sites.
Ok(true)
}
#[inline(always)] #[inline(always)]
fn adjust_global_allocation<'b>( fn adjust_global_allocation<'b>(
_ecx: &InterpCx<$tcx, Self>, _ecx: &InterpCx<$tcx, Self>,

View File

@ -512,7 +512,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
self.tcx.offset_of_subfield(self.param_env, layout, fields.iter()).bytes(); self.tcx.offset_of_subfield(self.param_env, layout, fields.iter()).bytes();
ImmTy::from_uint(val, usize_layout()) ImmTy::from_uint(val, usize_layout())
} }
UbChecks => ImmTy::from_bool(self.tcx.sess.ub_checks(), *self.tcx), UbChecks => ImmTy::from_bool(M::ub_checks(self)?, *self.tcx),
}) })
} }
} }

View File

@ -1060,6 +1060,10 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
ecx.generate_nan(inputs) ecx.generate_nan(inputs)
} }
fn ub_checks(ecx: &InterpCx<'tcx, Self>) -> InterpResult<'tcx, bool> {
Ok(ecx.tcx.sess.ub_checks())
}
fn thread_local_static_pointer( fn thread_local_static_pointer(
ecx: &mut MiriInterpCx<'tcx>, ecx: &mut MiriInterpCx<'tcx>,
def_id: DefId, def_id: DefId,