Skip to content

Commit cddd476

Browse files
committed
coverage: Add CLI 'condition' coverage option
1 parent f973a15 commit cddd476

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,21 @@ pub enum CoverageLevel {
157157
Block,
158158
/// Also instrument branch points (includes block coverage).
159159
Branch,
160-
/// Instrument for MC/DC. Mostly a superset of branch coverage, but might
161-
/// differ in some corner cases.
160+
/// Same as branch condition, with a single different case:
161+
/// In boolean expressions that are not inside a control-flow decision,
162+
/// it will intentionally insert an instrumented branch for the last operand.
163+
///
164+
/// Example:
165+
/// ```
166+
/// let x = a && b;
167+
/// // ^ branch coverage does not track true/false coverage for `b`
168+
/// // but condition coverage does.
169+
/// ```
170+
/// The main purpose of this coverage level is to be reused by MCDC.
171+
Condition,
172+
/// Instrument for MC/DC. Enables condition coverage under the hood.
173+
/// Mostly a superset of branch coverage, but might differ in some
174+
/// corner cases.
162175
Mcdc,
163176
}
164177

compiler/rustc_session/src/options.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,7 @@ mod parse {
948948
match option {
949949
"block" => slot.level = CoverageLevel::Block,
950950
"branch" => slot.level = CoverageLevel::Branch,
951+
"condition" => slot.level = CoverageLevel::Condition,
951952
"mcdc" => slot.level = CoverageLevel::Mcdc,
952953
_ => return false,
953954
}

compiler/rustc_session/src/session.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,11 @@ impl Session {
353353
&& self.opts.unstable_opts.coverage_options.level >= CoverageLevel::Branch
354354
}
355355

356+
pub fn instrument_coverage_condition(&self) -> bool {
357+
self.instrument_coverage()
358+
&& self.opts.unstable_opts.coverage_options.level >= CoverageLevel::Condition
359+
}
360+
356361
pub fn instrument_coverage_mcdc(&self) -> bool {
357362
self.instrument_coverage()
358363
&& self.opts.unstable_opts.coverage_options.level >= CoverageLevel::Mcdc

0 commit comments

Comments
 (0)