Auto merge of #131201 - compiler-errors:unop-not, r=cjgillot
Disable jump threading `UnOp::Not` for non-bool Fix #131195, where jumpthreading was optimizing `!a == b` into `a != b` for non-bool, where this is definitely not true.
This commit is contained in:
commit
11ee3a830b
4 changed files with 111 additions and 0 deletions
|
@ -494,8 +494,16 @@ impl<'a, 'tcx> TOFinder<'a, 'tcx> {
|
|||
}
|
||||
// Transfer the conditions on the copy rhs, after inversing polarity.
|
||||
Rvalue::UnaryOp(UnOp::Not, Operand::Move(place) | Operand::Copy(place)) => {
|
||||
if !place.ty(self.body, self.tcx).ty.is_bool() {
|
||||
// Constructing the conditions by inverting the polarity
|
||||
// of equality is only correct for bools. That is to say,
|
||||
// `!a == b` is not `a != b` for integers greater than 1 bit.
|
||||
return;
|
||||
}
|
||||
let Some(conditions) = state.try_get_idx(lhs, &self.map) else { return };
|
||||
let Some(place) = self.map.find(place.as_ref()) else { return };
|
||||
// FIXME: I think This could be generalized to not bool if we
|
||||
// actually perform a logical not on the condition's value.
|
||||
let conds = conditions.map(self.arena, Condition::inv);
|
||||
state.insert_value_idx(place, conds, &self.map);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue