diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-03-06 16:41:58 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-06 16:41:58 +0100 |
| commit | 4bd6f7fe1611a1f903f29ce65a3231d5e37b0632 (patch) | |
| tree | 61ee2cb08083e24a08deb98864c6098412b21c04 | |
| parent | 1866ea136ce36ee780e1d59bcba9b34f7fd6f13d (diff) | |
| parent | cb4ebc1453a69145d6602de798dc704871a200da (diff) | |
| download | rust-4bd6f7fe1611a1f903f29ce65a3231d5e37b0632.tar.gz rust-4bd6f7fe1611a1f903f29ce65a3231d5e37b0632.zip | |
Rollup merge of #108786 - saethlin:free-regions-check, r=oli-obk
Check for free regions in MIR validation
This turns https://github.com/rust-lang/rust/issues/108720 into a MIR validation failure that will reproduce without debug-assertions enabled.
```
error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:296 ~ futures_util[3805]::future::future::remote_handle::{impl#3}::poll), const_param_did: None }) (after pass ScalarReplacementOfAggregates) at bb0[0]:
Free regions in optimized runtime-post-cleanup MIR
--> /home/ben/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.26/src/future/future/remote_handle.rs:96:13
|
96 | let this = self.project();
| ^^^^
```
| -rw-r--r-- | compiler/rustc_const_eval/src/transform/validate.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_mir_transform/src/lib.rs | 6 |
2 files changed, 11 insertions, 6 deletions
diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index fb37eb79a33..272fe3d1b31 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -72,6 +72,17 @@ impl<'tcx> MirPass<'tcx> for Validator { }; checker.visit_body(body); checker.check_cleanup_control_flow(); + + if let MirPhase::Runtime(_) = body.phase { + if let ty::InstanceDef::Item(_) = body.source.instance { + if body.has_free_regions() { + checker.fail( + Location::START, + format!("Free regions in optimized {} MIR", body.phase.name()), + ); + } + } + } } } diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index cdd28ae0c01..5fd923190ef 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -416,8 +416,6 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) - pm::run_passes(tcx, &mut body, &[&ctfe_limit::CtfeLimit], None); - debug_assert!(!body.has_free_regions(), "Free regions in MIR for CTFE"); - body } @@ -626,8 +624,6 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> { debug!("body: {:#?}", body); run_optimization_passes(tcx, &mut body); - debug_assert!(!body.has_free_regions(), "Free regions in optimized MIR"); - body } @@ -651,7 +647,5 @@ fn promoted_mir( run_analysis_to_runtime_passes(tcx, body); } - debug_assert!(!promoted.has_free_regions(), "Free regions in promoted MIR"); - tcx.arena.alloc(promoted) } |
