Skip to content

Commit c671eaa

Browse files
committed
coverage: Rename MC/DC conditions_num to num_conditions
This value represents a quantity of conditions, not an ID, so the new spelling is more appropriate.
1 parent 23ea77b commit c671eaa

File tree

10 files changed

+34
-33
lines changed

10 files changed

+34
-33
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs

+4-3
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)
@@ -177,8 +177,9 @@ pub mod mcdc {
177177
}
178178

179179
impl From<DecisionInfo> for DecisionParameters {
180-
fn from(value: DecisionInfo) -> Self {
181-
Self { bitmap_idx: value.bitmap_idx, conditions_num: value.conditions_num }
180+
fn from(info: DecisionInfo) -> Self {
181+
let DecisionInfo { bitmap_idx, num_conditions } = info;
182+
Self { bitmap_idx, num_conditions }
182183
}
183184
}
184185
}

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
@@ -512,12 +512,12 @@ fn write_coverage_branch_info(
512512
)?;
513513
}
514514

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

compiler/rustc_mir_build/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ 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 = Number of conditions in decision ({$num_conditions}) exceeds limit ({$max_conditions}). MC/DC analysis will not count this expression.
101101
102102
mir_build_extern_static_requires_unsafe =
103103
use of extern static is unsafe and requires unsafe block

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

+13-13
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ use rustc_middle::ty::TyCtxt;
1010
use rustc_span::Span;
1111

1212
use crate::build::Builder;
13-
use crate::errors::MCDCExceedsConditionNumLimit;
13+
use crate::errors::MCDCExceedsConditionLimit;
1414

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

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

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

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

120120
let (lhs, rhs) = match op {
121121
LogicalOp::And => {
@@ -208,28 +208,28 @@ impl MCDCInfoBuilder {
208208
// is empty, i.e. when all the conditions of the decision were instrumented,
209209
// and the decision is "complete".
210210
if let Some(decision) = decision_result {
211-
match decision.conditions_num {
211+
match decision.num_conditions {
212212
0 => {
213213
unreachable!("Decision with no condition is not expected");
214214
}
215-
1..=MAX_CONDITIONS_NUM_IN_DECISION => {
215+
1..=MAX_CONDITIONS_IN_DECISION => {
216216
self.decision_spans.push(decision);
217217
}
218218
_ => {
219219
// Do not generate mcdc mappings and statements for decisions with too many conditions.
220220
// Therefore, first erase the condition info of the (N-1) previous branch spans.
221-
let rebase_idx = self.branch_spans.len() - (decision.conditions_num - 1);
221+
let rebase_idx = self.branch_spans.len() - (decision.num_conditions - 1);
222222
for branch in &mut self.branch_spans[rebase_idx..] {
223223
branch.condition_info = None;
224224
}
225225

226226
// Then, erase this last branch span's info too, for a total of N.
227227
condition_info = None;
228228

229-
tcx.dcx().emit_warn(MCDCExceedsConditionNumLimit {
229+
tcx.dcx().emit_warn(MCDCExceedsConditionLimit {
230230
span: decision.span,
231-
conditions_num: decision.conditions_num,
232-
max_conditions_num: MAX_CONDITIONS_NUM_IN_DECISION,
231+
num_conditions: decision.num_conditions,
232+
max_conditions: MAX_CONDITIONS_IN_DECISION,
233233
});
234234
}
235235
}

compiler/rustc_mir_build/src/errors.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -812,12 +812,12 @@ pub struct NonEmptyNeverPattern<'tcx> {
812812
}
813813

814814
#[derive(Diagnostic)]
815-
#[diag(mir_build_exceeds_mcdc_condition_num_limit)]
816-
pub(crate) struct MCDCExceedsConditionNumLimit {
815+
#[diag(mir_build_exceeds_mcdc_condition_limit)]
816+
pub(crate) struct MCDCExceedsConditionLimit {
817817
#[primary_span]
818818
pub span: Span,
819-
pub conditions_num: usize,
820-
pub max_conditions_num: usize,
819+
pub num_conditions: usize,
820+
pub max_conditions: usize,
821821
}
822822

823823
#[derive(Diagnostic)]

compiler/rustc_mir_transform/src/coverage/mappings.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub(super) struct MCDCDecision {
4848
pub(super) span: Span,
4949
pub(super) end_bcbs: BTreeSet<BasicCoverageBlock>,
5050
pub(super) bitmap_idx: u32,
51-
pub(super) conditions_num: u16,
51+
pub(super) num_conditions: u16,
5252
pub(super) decision_depth: u16,
5353
}
5454

@@ -268,13 +268,13 @@ pub(super) fn extract_mcdc_mappings(
268268
// the bitmap, rounded up to a whole number of bytes.
269269
// The decision's "bitmap index" points to its first byte in the bitmap.
270270
let bitmap_idx = *mcdc_bitmap_bytes;
271-
*mcdc_bitmap_bytes += (1_u32 << decision.conditions_num).div_ceil(8);
271+
*mcdc_bitmap_bytes += (1_u32 << decision.num_conditions).div_ceil(8);
272272

273273
Some(MCDCDecision {
274274
span,
275275
end_bcbs,
276276
bitmap_idx,
277-
conditions_num: decision.conditions_num as u16,
277+
num_conditions: decision.num_conditions as u16,
278278
decision_depth: decision.decision_depth,
279279
})
280280
},

compiler/rustc_mir_transform/src/coverage/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ fn create_mappings<'tcx>(
195195
));
196196

197197
mappings.extend(mcdc_decisions.iter().filter_map(
198-
|&mappings::MCDCDecision { span, bitmap_idx, conditions_num, .. }| {
198+
|&mappings::MCDCDecision { span, bitmap_idx, num_conditions, .. }| {
199199
let code_region = region_for_span(span)?;
200-
let kind = MappingKind::MCDCDecision(DecisionInfo { bitmap_idx, conditions_num });
200+
let kind = MappingKind::MCDCDecision(DecisionInfo { bitmap_idx, num_conditions });
201201
Some(Mapping { kind, code_region })
202202
},
203203
));
@@ -269,7 +269,7 @@ fn inject_mcdc_statements<'tcx>(
269269
span: _,
270270
ref end_bcbs,
271271
bitmap_idx,
272-
conditions_num: _,
272+
num_conditions: _,
273273
decision_depth,
274274
} in &extracted_mappings.mcdc_decisions
275275
{

tests/ui/instrument-coverage/mcdc-condition-limit.bad.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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). MC/DC analysis will not count this expression.
22
--> $DIR/mcdc-condition-limit.rs:29:8
33
|
44
LL | if a && b && c && d && e && f && g {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() {
2626
fn main() {
2727
// 7 conditions is too many, so issue a diagnostic.
2828
let [a, b, c, d, e, f, g] = <[bool; 7]>::default();
29-
if a && b && c && d && e && f && g { //[bad]~ WARNING Conditions number of the decision
29+
if a && b && c && d && e && f && g { //[bad]~ WARNING Number of conditions in decision
3030
core::hint::black_box("hello");
3131
}
3232
}

0 commit comments

Comments
 (0)