Skip to content

Commit 316f7d6

Browse files
committed
coverage: Rename conditions_num to num_conditions
This field counts the number of conditions that contribute to a particular decision, but the name "conditions num" sounds like an ID instead of a count, so "num conditions" is clearer.
1 parent f066196 commit 316f7d6

File tree

10 files changed

+40
-35
lines changed

10 files changed

+40
-35
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub mod mcdc {
118118
#[derive(Clone, Copy, Debug, Default)]
119119
pub struct DecisionParameters {
120120
bitmap_idx: u32,
121-
conditions_num: u16,
121+
num_conditions: u16,
122122
}
123123

124124
// ConditionId in llvm is `unsigned int` at 18 while `int16_t` at [19](https://github.com/llvm/llvm-project/pull/81257)
@@ -178,7 +178,7 @@ pub mod mcdc {
178178

179179
impl From<DecisionInfo> for DecisionParameters {
180180
fn from(value: DecisionInfo) -> Self {
181-
Self { bitmap_idx: value.bitmap_idx, conditions_num: value.conditions_num }
181+
Self { bitmap_idx: value.bitmap_idx, num_conditions: value.num_conditions }
182182
}
183183
}
184184
}

compiler/rustc_middle/src/mir/coverage.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,14 @@ pub struct MCDCBranchSpan {
329329
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
330330
pub struct DecisionInfo {
331331
pub bitmap_idx: u32,
332-
pub conditions_num: u16,
332+
pub num_conditions: u16,
333333
}
334334

335335
#[derive(Clone, Debug)]
336336
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
337337
pub struct MCDCDecisionSpan {
338338
pub span: Span,
339-
pub conditions_num: usize,
339+
pub num_conditions: usize,
340340
pub end_markers: Vec<BlockMarkerId>,
341341
pub decision_depth: u16,
342342
}

compiler/rustc_middle/src/mir/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,12 @@ fn write_coverage_branch_info(
511511
)?;
512512
}
513513

514-
for coverage::MCDCDecisionSpan { span, conditions_num, end_markers, decision_depth } in
514+
for coverage::MCDCDecisionSpan { span, num_conditions, end_markers, decision_depth } in
515515
mcdc_decision_spans
516516
{
517517
writeln!(
518518
w,
519-
"{INDENT}coverage mcdc decision {{ conditions_num: {conditions_num:?}, end: {end_markers:?}, depth: {decision_depth:?} }} => {span:?}"
519+
"{INDENT}coverage mcdc decision {{ num_conditions: {num_conditions:?}, end: {end_markers:?}, depth: {decision_depth:?} }} => {span:?}"
520520
)?;
521521
}
522522

compiler/rustc_mir_build/messages.ftl

+3-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ mir_build_deref_raw_pointer_requires_unsafe_unsafe_op_in_unsafe_fn_allowed =
9797
.note = raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
9898
.label = dereference of raw pointer
9999
100-
mir_build_exceeds_mcdc_condition_num_limit = Conditions number of the decision ({$conditions_num}) exceeds limit ({$max_conditions_num}). MCDC analysis will not count this expression.
100+
mir_build_exceeds_mcdc_condition_limit =
101+
number of conditions in decision ({$num_conditions}) exceeds limit ({$limit})
102+
.note = this decision will not be instrumented for MC/DC coverage
101103
102104
mir_build_extern_static_requires_unsafe =
103105
use of extern static is unsafe and requires unsafe block

compiler/rustc_mir_build/src/build/coverageinfo/mcdc.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ use rustc_middle::ty::TyCtxt;
99
use rustc_span::Span;
1010

1111
use crate::build::Builder;
12-
use crate::errors::MCDCExceedsConditionNumLimit;
12+
use crate::errors::MCDCExceedsConditionLimit;
1313

1414
/// The MCDC bitmap scales exponentially (2^n) based on the number of conditions seen,
15-
/// So llvm sets a maximum value prevents the bitmap footprint from growing too large without the user's knowledge.
16-
/// This limit may be relaxed if the [upstream change](https://github.com/llvm/llvm-project/pull/82448) is merged.
17-
const MAX_CONDITIONS_NUM_IN_DECISION: usize = 6;
15+
/// So LLVM imposes a limit to prevent the bitmap footprint from growing too large without the user's knowledge.
16+
/// This limit may be relaxed if [upstream change #82448](https://github.com/llvm/llvm-project/pull/82448) is merged.
17+
const MAX_CONDITIONS_IN_DECISION: usize = 6;
1818

1919
#[derive(Default)]
2020
struct MCDCDecisionCtx {
@@ -99,22 +99,22 @@ impl MCDCState {
9999
}
100100
None => decision_ctx.processing_decision.insert(MCDCDecisionSpan {
101101
span,
102-
conditions_num: 0,
102+
num_conditions: 0,
103103
end_markers: vec![],
104104
decision_depth,
105105
}),
106106
};
107107

108108
let parent_condition = decision_ctx.decision_stack.pop_back().unwrap_or_default();
109109
let lhs_id = if parent_condition.condition_id == ConditionId::NONE {
110-
decision.conditions_num += 1;
111-
ConditionId::from(decision.conditions_num)
110+
decision.num_conditions += 1;
111+
ConditionId::from(decision.num_conditions)
112112
} else {
113113
parent_condition.condition_id
114114
};
115115

116-
decision.conditions_num += 1;
117-
let rhs_condition_id = ConditionId::from(decision.conditions_num);
116+
decision.num_conditions += 1;
117+
let rhs_condition_id = ConditionId::from(decision.num_conditions);
118118

119119
let (lhs, rhs) = match op {
120120
LogicalOp::And => {
@@ -207,27 +207,27 @@ impl MCDCInfoBuilder {
207207
// is empty, i.e. when all the conditions of the decision were instrumented,
208208
// and the decision is "complete".
209209
if let Some(decision) = decision_result {
210-
match decision.conditions_num {
210+
match decision.num_conditions {
211211
0 => {
212212
unreachable!("Decision with no condition is not expected");
213213
}
214-
1..=MAX_CONDITIONS_NUM_IN_DECISION => {
214+
1..=MAX_CONDITIONS_IN_DECISION => {
215215
self.decision_spans.push(decision);
216216
}
217217
_ => {
218218
// Do not generate mcdc mappings and statements for decisions with too many conditions.
219-
let rebase_idx = self.branch_spans.len() - decision.conditions_num + 1;
219+
let rebase_idx = self.branch_spans.len() - decision.num_conditions + 1;
220220
for branch in &mut self.branch_spans[rebase_idx..] {
221221
branch.condition_info = None;
222222
}
223223

224224
// ConditionInfo of this branch shall also be reset.
225225
condition_info = None;
226226

227-
tcx.dcx().emit_warn(MCDCExceedsConditionNumLimit {
227+
tcx.dcx().emit_warn(MCDCExceedsConditionLimit {
228228
span: decision.span,
229-
conditions_num: decision.conditions_num,
230-
max_conditions_num: MAX_CONDITIONS_NUM_IN_DECISION,
229+
num_conditions: decision.num_conditions,
230+
limit: MAX_CONDITIONS_IN_DECISION,
231231
});
232232
}
233233
}

compiler/rustc_mir_build/src/errors.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -819,12 +819,13 @@ pub struct NontrivialStructuralMatch<'tcx> {
819819
}
820820

821821
#[derive(Diagnostic)]
822-
#[diag(mir_build_exceeds_mcdc_condition_num_limit)]
823-
pub(crate) struct MCDCExceedsConditionNumLimit {
822+
#[diag(mir_build_exceeds_mcdc_condition_limit)]
823+
#[note]
824+
pub(crate) struct MCDCExceedsConditionLimit {
824825
#[primary_span]
825826
pub span: Span,
826-
pub conditions_num: usize,
827-
pub max_conditions_num: usize,
827+
pub num_conditions: usize,
828+
pub limit: usize,
828829
}
829830

830831
#[derive(Diagnostic)]

compiler/rustc_mir_transform/src/coverage/mappings.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub(super) enum BcbMappingKind {
3636
MCDCDecision {
3737
end_bcbs: BTreeSet<BasicCoverageBlock>,
3838
bitmap_idx: u32,
39-
conditions_num: u16,
39+
num_conditions: u16,
4040
decision_depth: u16,
4141
},
4242
}
@@ -119,12 +119,12 @@ pub(super) fn generate_coverage_spans(
119119
insert(true_bcb);
120120
insert(false_bcb);
121121
}
122-
BcbMappingKind::MCDCDecision { bitmap_idx, conditions_num, .. } => {
122+
BcbMappingKind::MCDCDecision { bitmap_idx, num_conditions, .. } => {
123123
// `bcb_has_mappings` is used for inject coverage counters
124124
// but they are not needed for decision BCBs.
125125
// While the length of test vector bitmap should be calculated here.
126126
test_vector_bitmap_bytes = test_vector_bitmap_bytes
127-
.max(bitmap_idx + (1_u32 << conditions_num as u32).div_ceil(8));
127+
.max(bitmap_idx + (1_u32 << num_conditions as u32).div_ceil(8));
128128
}
129129
}
130130
}
@@ -255,13 +255,13 @@ pub(super) fn extract_mcdc_mappings(
255255
.collect::<Option<_>>()?;
256256

257257
let bitmap_idx = next_bitmap_idx;
258-
next_bitmap_idx += (1_u32 << decision.conditions_num).div_ceil(8);
258+
next_bitmap_idx += (1_u32 << decision.num_conditions).div_ceil(8);
259259

260260
Some(BcbMapping {
261261
kind: BcbMappingKind::MCDCDecision {
262262
end_bcbs,
263263
bitmap_idx,
264-
conditions_num: decision.conditions_num as u16,
264+
num_conditions: decision.num_conditions as u16,
265265
decision_depth: decision.decision_depth,
266266
},
267267
span,

compiler/rustc_mir_transform/src/coverage/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ fn create_mappings<'tcx>(
172172
false_term: term_for_bcb(false_bcb),
173173
mcdc_params,
174174
},
175-
BcbMappingKind::MCDCDecision { bitmap_idx, conditions_num, .. } => {
176-
MappingKind::MCDCDecision(DecisionInfo { bitmap_idx, conditions_num })
175+
BcbMappingKind::MCDCDecision { bitmap_idx, num_conditions, .. } => {
176+
MappingKind::MCDCDecision(DecisionInfo { bitmap_idx, num_conditions })
177177
}
178178
};
179179
let code_region = make_code_region(source_map, file_name, *span, body_span)?;
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
warning: Conditions number of the decision (7) exceeds limit (6). MCDC analysis will not count this expression.
1+
warning: number of conditions in decision (7) exceeds limit (6)
22
--> $DIR/mcdc-condition-limit.rs:18:8
33
|
44
LL | if a && b && c && d && e && f && g {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: this decision will not be instrumented for MC/DC coverage
68

79
warning: 1 warning emitted
810

tests/ui/instrument-coverage/mcdc-condition-limit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn main() {
1515
#[cfg(bad)]
1616
fn main() {
1717
let [a, b, c, d, e, f, g] = <[bool; 7]>::default();
18-
if a && b && c && d && e && f && g { //[bad]~ WARNING Conditions number of the decision
18+
if a && b && c && d && e && f && g { //[bad]~ WARNING number of conditions in decision
1919
core::hint::black_box("hello");
2020
}
2121
}

0 commit comments

Comments
 (0)