@@ -29,18 +29,12 @@ pub(crate) fn provide(providers: &mut Providers) {
29
29
/// calls may not work; but computing the number of counters or expressions by adding `1` to the
30
30
/// highest ID (for a given instrumented function) is valid.
31
31
///
32
- /// This visitor runs twice, first with `add_missing_operands` set to `false`, to find the maximum
33
- /// counter ID and maximum expression ID based on their enum variant `id` fields; then, as a
34
- /// safeguard, with `add_missing_operands` set to `true`, to find any other counter or expression
35
- /// IDs referenced by expression operands, if not already seen.
36
- ///
37
- /// Ideally, each operand ID in a MIR `CoverageKind::Expression` will have a separate MIR `Coverage`
38
- /// statement for the `Counter` or `Expression` with the referenced ID. but since current or future
39
- /// MIR optimizations can theoretically optimize out segments of a MIR, it may not be possible to
40
- /// guarantee this, so the second pass ensures the `CoverageInfo` counts include all referenced IDs.
32
+ /// It's possible for a coverage expression to remain in MIR while one or both of its operands
33
+ /// have been optimized away. To avoid problems in codegen, we include those operands' IDs when
34
+ /// determining the maximum counter/expression ID, even if the underlying counter/expression is
35
+ /// no longer present.
41
36
struct CoverageVisitor {
42
37
info : CoverageInfo ,
43
- add_missing_operands : bool ,
44
38
}
45
39
46
40
impl CoverageVisitor {
@@ -73,35 +67,24 @@ impl CoverageVisitor {
73
67
}
74
68
75
69
fn visit_coverage ( & mut self , coverage : & Coverage ) {
76
- if self . add_missing_operands {
77
- match coverage. kind {
78
- CoverageKind :: Expression { lhs, rhs, .. } => {
79
- self . update_from_expression_operand ( lhs) ;
80
- self . update_from_expression_operand ( rhs) ;
81
- }
82
- _ => { }
83
- }
84
- } else {
85
- match coverage. kind {
86
- CoverageKind :: Counter { id, .. } => self . update_num_counters ( id) ,
87
- CoverageKind :: Expression { id, .. } => self . update_num_expressions ( id) ,
88
- _ => { }
70
+ match coverage. kind {
71
+ CoverageKind :: Counter { id, .. } => self . update_num_counters ( id) ,
72
+ CoverageKind :: Expression { id, lhs, rhs, .. } => {
73
+ self . update_num_expressions ( id) ;
74
+ self . update_from_expression_operand ( lhs) ;
75
+ self . update_from_expression_operand ( rhs) ;
89
76
}
77
+ CoverageKind :: Unreachable => { }
90
78
}
91
79
}
92
80
}
93
81
94
82
fn coverageinfo < ' tcx > ( tcx : TyCtxt < ' tcx > , instance_def : ty:: InstanceDef < ' tcx > ) -> CoverageInfo {
95
83
let mir_body = tcx. instance_mir ( instance_def) ;
96
84
97
- let mut coverage_visitor = CoverageVisitor {
98
- info : CoverageInfo { num_counters : 0 , num_expressions : 0 } ,
99
- add_missing_operands : false ,
100
- } ;
101
-
102
- coverage_visitor. visit_body ( mir_body) ;
85
+ let mut coverage_visitor =
86
+ CoverageVisitor { info : CoverageInfo { num_counters : 0 , num_expressions : 0 } } ;
103
87
104
- coverage_visitor. add_missing_operands = true ;
105
88
coverage_visitor. visit_body ( mir_body) ;
106
89
107
90
coverage_visitor. info
0 commit comments