remove an ineffective check in const_prop
This commit is contained in:
parent
4065b89b1e
commit
4173e971b8
5 changed files with 60 additions and 26 deletions
|
@ -6,6 +6,7 @@ use crate::const_prop::ConstPropMachine;
|
|||
use crate::const_prop::ConstPropMode;
|
||||
use crate::MirLint;
|
||||
use rustc_const_eval::const_eval::ConstEvalErr;
|
||||
use rustc_const_eval::interpret::Immediate;
|
||||
use rustc_const_eval::interpret::{
|
||||
self, InterpCx, InterpResult, LocalState, LocalValue, MemoryKind, OpTy, Scalar, StackPopCleanup,
|
||||
};
|
||||
|
@ -229,7 +230,13 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
|
||||
fn get_const(&self, place: Place<'tcx>) -> Option<OpTy<'tcx>> {
|
||||
let op = match self.ecx.eval_place_to_op(place, None) {
|
||||
Ok(op) => op,
|
||||
Ok(op) => {
|
||||
if matches!(*op, interpret::Operand::Immediate(Immediate::Uninit)) {
|
||||
// Make sure nobody accidentally uses this value.
|
||||
return None;
|
||||
}
|
||||
op
|
||||
}
|
||||
Err(e) => {
|
||||
trace!("get_const failed: {}", e);
|
||||
return None;
|
||||
|
@ -515,6 +522,14 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
if rvalue.needs_subst() {
|
||||
return None;
|
||||
}
|
||||
if !rvalue
|
||||
.ty(&self.ecx.frame().body.local_decls, *self.ecx.tcx)
|
||||
.is_sized(self.ecx.tcx, self.param_env)
|
||||
{
|
||||
// the interpreter doesn't support unsized locals (only unsized arguments),
|
||||
// but rustc does (in a kinda broken way), so we have to skip them here
|
||||
return None;
|
||||
}
|
||||
|
||||
self.use_ecx(source_info, |this| this.ecx.eval_rvalue_into_place(rvalue, place))
|
||||
}
|
||||
|
@ -624,7 +639,11 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
|||
if let Some(ref value) = self.eval_operand(&cond, source_info) {
|
||||
trace!("assertion on {:?} should be {:?}", value, expected);
|
||||
let expected = Scalar::from_bool(*expected);
|
||||
let value_const = self.ecx.read_scalar(&value).unwrap();
|
||||
let Ok(value_const) = self.ecx.read_scalar(&value) else {
|
||||
// FIXME should be used use_ecx rather than a local match... but we have
|
||||
// quite a few of these read_scalar/read_immediate that need fixing.
|
||||
return
|
||||
};
|
||||
if expected != value_const {
|
||||
enum DbgVal<T> {
|
||||
Val(T),
|
||||
|
@ -641,9 +660,9 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
|||
let mut eval_to_int = |op| {
|
||||
// This can be `None` if the lhs wasn't const propagated and we just
|
||||
// triggered the assert on the value of the rhs.
|
||||
self.eval_operand(op, source_info).map_or(DbgVal::Underscore, |op| {
|
||||
DbgVal::Val(self.ecx.read_immediate(&op).unwrap().to_const_int())
|
||||
})
|
||||
self.eval_operand(op, source_info)
|
||||
.and_then(|op| self.ecx.read_immediate(&op).ok())
|
||||
.map_or(DbgVal::Underscore, |op| DbgVal::Val(op.to_const_int()))
|
||||
};
|
||||
let msg = match msg {
|
||||
AssertKind::DivisionByZero(op) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue