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_codegen_ssa/src | |
| 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_codegen_ssa/src')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/mir/mod.rs | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs index e2edd448267..581860ee8b5 100644 --- a/compiler/rustc_codegen_ssa/src/mir/mod.rs +++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs @@ -152,20 +152,11 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( } let cleanup_kinds = analyze::cleanup_kinds(&mir); - // Allocate a `Block` for every basic block, except - // the start block, if nothing loops back to it. - let reentrant_start_block = !mir.predecessors()[mir::START_BLOCK].is_empty(); - let cached_llbbs: IndexVec<mir::BasicBlock, Option<Bx::BasicBlock>> = - mir.basic_blocks() - .indices() - .map(|bb| { - if bb == mir::START_BLOCK && !reentrant_start_block { - Some(start_llbb) - } else { - None - } - }) - .collect(); + let cached_llbbs: IndexVec<mir::BasicBlock, Option<Bx::BasicBlock>> = mir + .basic_blocks() + .indices() + .map(|bb| if bb == mir::START_BLOCK { Some(start_llbb) } else { None }) + .collect(); let mut fx = FunctionCx { instance, @@ -247,11 +238,6 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( // Apply debuginfo to the newly allocated locals. fx.debug_introduce_locals(&mut bx); - // Branch to the START block, if it's not the entry block. - if reentrant_start_block { - bx.br(fx.llbb(mir::START_BLOCK)); - } - // Codegen the body of each block using reverse postorder // FIXME(eddyb) reuse RPO iterator between `analysis` and this. for (bb, _) in traversal::reverse_postorder(&mir) { |
