diff options
| author | bors <bors@rust-lang.org> | 2021-09-19 01:38:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-09-19 01:38:17 +0000 |
| commit | 10967a1dcc9847a6fa616e58a788efdf32cadf98 (patch) | |
| tree | 29637ca23c6b7675e49d55947b129d511299f6df /compiler/rustc_mir_transform/src/simplify.rs | |
| parent | e20a4ec1340f538296b4c81c4b00ef8fa64b7350 (diff) | |
| parent | f1f1c8fa505b8b7e2cab75c30e6f7f8a62b5ca7a (diff) | |
| download | rust-10967a1dcc9847a6fa616e58a788efdf32cadf98.tar.gz rust-10967a1dcc9847a6fa616e58a788efdf32cadf98.zip | |
Auto merge of #88968 - tmiasko:start-block-no-predecessors, r=davidtwco
Start block is not allowed to have basic block predecessors * The MIR validator is extended to detect potential violations. * The start block has no predecessors after building MIR, so no changes are required there. * The SimplifyCfg could previously violate this requirement when collapsing goto chains, so transformation is disabled for the start block, which also substantially simplifies the implementation. * The LLVM function entry block also must not have basic block predecessors. Previously, to ensure that code generation had to perform necessary adjustments. This now became unnecessary. The motivation behind the change is to align with analogous requirement in LLVM, and to avoid potential latent bugs like the one reported in #88043.
Diffstat (limited to 'compiler/rustc_mir_transform/src/simplify.rs')
| -rw-r--r-- | compiler/rustc_mir_transform/src/simplify.rs | 25 |
1 files changed, 0 insertions, 25 deletions
diff --git a/compiler/rustc_mir_transform/src/simplify.rs b/compiler/rustc_mir_transform/src/simplify.rs index e3cfd1d0afc..d6cd505cbb5 100644 --- a/compiler/rustc_mir_transform/src/simplify.rs +++ b/compiler/rustc_mir_transform/src/simplify.rs @@ -95,8 +95,6 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> { pub fn simplify(mut self) { self.strip_nops(); - let mut start = START_BLOCK; - // Vec of the blocks that should be merged. We store the indices here, instead of the // statements itself to avoid moving the (relatively) large statements twice. // We do not push the statements directly into the target block (`bb`) as that is slower @@ -105,8 +103,6 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> { loop { let mut changed = false; - self.collapse_goto_chain(&mut start, &mut changed); - for bb in self.basic_blocks.indices() { if self.pred_count[bb] == 0 { continue; @@ -149,27 +145,6 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> { break; } } - - if start != START_BLOCK { - debug_assert!(self.pred_count[START_BLOCK] == 0); - self.basic_blocks.swap(START_BLOCK, start); - self.pred_count.swap(START_BLOCK, start); - - // pred_count == 1 if the start block has no predecessor _blocks_. - if self.pred_count[START_BLOCK] > 1 { - for (bb, data) in self.basic_blocks.iter_enumerated_mut() { - if self.pred_count[bb] == 0 { - continue; - } - - for target in data.terminator_mut().successors_mut() { - if *target == start { - *target = START_BLOCK; - } - } - } - } - } } /// This function will return `None` if |
