Skip to content

Commit 15f5e50

Browse files
committed
!! (WIP) insert a goto after the branch marker
1 parent 30d8f39 commit 15f5e50

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

compiler/rustc_mir_build/src/build/coverageinfo.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_middle::mir::coverage::{BlockMarkerId, BranchSpan, CoverageKind};
44
use rustc_middle::mir::{self, BasicBlock, SourceInfo, Statement, StatementKind};
55
use rustc_middle::ty::TyCtxt;
66
use rustc_span::def_id::LocalDefId;
7-
use rustc_span::{ExpnKind, Span};
7+
use rustc_span::{ExpnKind, Span, DUMMY_SP};
88

99
use crate::build::Builder;
1010

@@ -151,13 +151,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
151151
pub(crate) fn coverage_add_branch(
152152
&mut self,
153153
cond_source_info: SourceInfo,
154-
then_blk: BasicBlock,
155-
else_blk: BasicBlock,
154+
then_blk: &mut BasicBlock,
155+
else_blk: &mut BasicBlock,
156156
) {
157157
let hir_info_builder = self.coverage.as_mut().unwrap();
158158
assert!(hir_info_builder.branch_coverage_enabled);
159159

160-
let mut inject_branch_marker = |bb: BasicBlock| {
160+
let mut inject_branch_marker = |bb: &mut BasicBlock| {
161161
let id = hir_info_builder.next_block_marker_id();
162162

163163
let statement = Statement {
@@ -167,7 +167,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
167167
})),
168168
};
169169

170-
self.cfg.push(bb, statement);
170+
self.cfg.push(*bb, statement);
171+
let successor_block = self.cfg.start_new_block();
172+
self.cfg.goto(*bb, SourceInfo::outermost(DUMMY_SP), successor_block);
173+
*bb = successor_block;
171174
id
172175
};
173176

compiler/rustc_mir_build/src/build/matches/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
136136
unpack!(block = this.as_temp(block, Some(temp_scope), expr, mutability));
137137
let operand = Operand::Move(Place::from(place));
138138

139-
let then_block = this.cfg.start_new_block();
140-
let else_block = this.cfg.start_new_block();
139+
let mut then_block = this.cfg.start_new_block();
140+
let mut else_block = this.cfg.start_new_block();
141141
let term = TerminatorKind::if_(operand, then_block, else_block);
142142

143143
let source_info = this.source_info(expr_span);
144144

145145
if let Some(coverage) = &this.coverage
146146
&& coverage.branch_coverage_enabled
147147
{
148-
this.coverage_add_branch(source_info, then_block, else_block);
148+
this.coverage_add_branch(source_info, &mut then_block, &mut else_block);
149149
}
150150

151151
this.cfg.terminate(block, source_info, term);

0 commit comments

Comments
 (0)