diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2023-05-13 10:29:05 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2023-05-13 10:29:05 +0000 |
| commit | 13fb0794aca868c2b73493d7e008e1b395dacea4 (patch) | |
| tree | 69d878a53ce66e07b279816c7a06a6caa8067607 | |
| parent | 19652377c3f056aa0db32b8586e5a707b965a90d (diff) | |
| download | rust-13fb0794aca868c2b73493d7e008e1b395dacea4.tar.gz rust-13fb0794aca868c2b73493d7e008e1b395dacea4.zip | |
Do not ICE on deeply nested borrows.
| -rw-r--r-- | compiler/rustc_mir_transform/src/ref_prop.rs | 6 | ||||
| -rw-r--r-- | tests/mir-opt/reference_prop.rs | 13 |
2 files changed, 17 insertions, 2 deletions
diff --git a/compiler/rustc_mir_transform/src/ref_prop.rs b/compiler/rustc_mir_transform/src/ref_prop.rs index b0f89393989..bbd9f76ba5c 100644 --- a/compiler/rustc_mir_transform/src/ref_prop.rs +++ b/compiler/rustc_mir_transform/src/ref_prop.rs @@ -363,8 +363,10 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'tcx> { if let Some((&PlaceElem::Deref, rest)) = target.projection.split_last() { *place = Place::from(target.local).project_deeper(rest, self.tcx); self.any_replacement = true; - } else if self.fully_replacable_locals.contains(place.local) { - debuginfo.references += 1; + } else if self.fully_replacable_locals.contains(place.local) + && let Some(references) = debuginfo.references.checked_add(1) + { + debuginfo.references = references; *place = target; self.any_replacement = true; } diff --git a/tests/mir-opt/reference_prop.rs b/tests/mir-opt/reference_prop.rs index c8c29fb143e..eb573790daf 100644 --- a/tests/mir-opt/reference_prop.rs +++ b/tests/mir-opt/reference_prop.rs @@ -548,6 +548,18 @@ fn debuginfo() { } } +fn many_debuginfo() { + let a = 0; + + // Verify that we do not ICE on deeply nested borrows. + let many_borrow = + &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& + &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& + &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& + &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& + &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&a; +} + fn main() { let mut x = 5_usize; let mut y = 7_usize; @@ -562,6 +574,7 @@ fn main() { mut_raw_then_mut_shr(); unique_with_copies(); debuginfo(); + many_debuginfo(); } // EMIT_MIR reference_prop.reference_propagation.ReferencePropagation.diff |
