coverage: Restrict ExpressionUsed simplification to Code mappings · rust-lang/rust@d4f1f92 (original) (raw)

`@@ -25,7 +25,7 @@ use rustc_span::source_map::SourceMap;

`

25

25

`use rustc_span::{BytePos, Pos, RelativeBytePos, Span, Symbol};

`

26

26

``

27

27

`use crate::coverage::counters::{CounterIncrementSite, CoverageCounters};

`

28

``

`-

use crate::coverage::graph::{BasicCoverageBlock, CoverageGraph};

`

``

28

`+

use crate::coverage::graph::CoverageGraph;

`

29

29

`use crate::coverage::mappings::ExtractedMappings;

`

30

30

`use crate::MirPass;

`

31

31

``

`@@ -108,7 +108,7 @@ fn instrument_function_for_coverage<'tcx>(tcx: TyCtxt<'tcx>, mir_body: &mut mir:

`

108

108

`inject_coverage_statements(

`

109

109

` mir_body,

`

110

110

`&basic_coverage_blocks,

`

111

``

`-

bcb_has_counter_mappings,

`

``

111

`+

&extracted_mappings,

`

112

112

`&coverage_counters,

`

113

113

`);

`

114

114

``

`@@ -219,7 +219,7 @@ fn create_mappings<'tcx>(

`

219

219

`fn inject_coverage_statements<'tcx>(

`

220

220

`mir_body: &mut mir::Body<'tcx>,

`

221

221

`basic_coverage_blocks: &CoverageGraph,

`

222

``

`-

bcb_has_coverage_spans: impl Fn(BasicCoverageBlock) -> bool,

`

``

222

`+

extracted_mappings: &ExtractedMappings,

`

223

223

`coverage_counters: &CoverageCounters,

`

224

224

`) {

`

225

225

`// Inject counter-increment statements into MIR.

`

`@@ -252,11 +252,16 @@ fn inject_coverage_statements<'tcx>(

`

252

252

`// can check whether the injected statement survived MIR optimization.

`

253

253

`// (BCB edges can't have spans, so we only need to process BCB nodes here.)

`

254

254

`//

`

``

255

`` +

// We only do this for ordinary Code mappings, because branch and MC/DC

``

``

256

`+

// mappings might have expressions that don't correspond to any single

`

``

257

`+

// point in the control-flow graph.

`

``

258

`+

//

`

255

259

`` // See the code in rustc_codegen_llvm::coverageinfo::map_data that deals

``

256

260

`// with "expressions seen" and "zero terms".

`

``

261

`+

let eligible_bcbs = extracted_mappings.bcbs_with_ordinary_code_mappings();

`

257

262

`for (bcb, expression_id) in coverage_counters

`

258

263

`.bcb_nodes_with_coverage_expressions()

`

259

``

`-

.filter(|&(bcb, _)| bcb_has_coverage_spans(bcb))

`

``

264

`+

.filter(|&(bcb, _)| eligible_bcbs.contains(bcb))

`

260

265

`{

`

261

266

`inject_statement(

`

262

267

` mir_body,

`