Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions compiler/rustc_mir_transform/src/ssa_range_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,11 @@ impl<'tcx> MutVisitor<'tcx> for RangeSet<'tcx, '_, '_> {
{
let successor = Location { block: *target, statement_index: 0 };
if location.dominates(successor, &self.dominators) {
assert_ne!(location.block, successor.block);
let val = *expected as u128;
let range = WrappingRange { start: val, end: val };
self.insert_range(place, successor, range);
if location.block != successor.block {
let val = *expected as u128;
let range = WrappingRange { start: val, end: val };
self.insert_range(place, successor, range);
}
}
}
TerminatorKind::SwitchInt { discr, targets }
Expand All @@ -188,7 +189,9 @@ impl<'tcx> MutVisitor<'tcx> for RangeSet<'tcx, '_, '_> {
}
let successor = Location { block: target, statement_index: 0 };
if self.unique_predecessors.contains(successor.block) {
assert_ne!(location.block, successor.block);
if location.block == successor.block {
continue;
}
let range = WrappingRange { start: val, end: val };
self.insert_range(place, successor, range);
}
Expand All @@ -201,13 +204,14 @@ impl<'tcx> MutVisitor<'tcx> for RangeSet<'tcx, '_, '_> {
&& let [val] = targets.all_values()
&& self.unique_predecessors.contains(otherwise.block)
{
assert_ne!(location.block, otherwise.block);
let range = if val.get() == 0 {
WrappingRange { start: 1, end: 1 }
} else {
WrappingRange { start: 0, end: 0 }
};
self.insert_range(place, otherwise, range);
if location.block != otherwise.block {
let range = if val.get() == 0 {
WrappingRange { start: 1, end: 1 }
} else {
WrappingRange { start: 0, end: 0 }
};
self.insert_range(place, otherwise, range);
}
}
}
_ => {}
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/mir/ssa-range-prop-self-loop-155836.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Regression test for <https://github.com/rust-lang/rust/issues/155836>.
// Ensure SSA range propagation does not ICE on self-loops.
//@ compile-flags: -C opt-level=2
//@ check-pass

#![crate_type = "lib"]

pub fn trigger(b: usize) -> usize {
while 0 != 2 {
b % b;
}
b
}
Loading