Skip to content

Commit fa563c1

Browse files
RenjiSannZalathar
authored andcommitted
coverage: Add CLI support for -Zcoverage-options=condition
1 parent caa187f commit fa563c1

File tree

6 files changed

+34
-6
lines changed

6 files changed

+34
-6
lines changed

compiler/rustc_session/src/config.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,23 @@ pub enum CoverageLevel {
159159
Block,
160160
/// Also instrument branch points (includes block coverage).
161161
Branch,
162-
/// Instrument for MC/DC. Mostly a superset of branch coverage, but might
162+
/// Same as branch coverage, but also adds branch instrumentation for
163+
/// certain boolean expressions that are not directly used for branching.
164+
///
165+
/// For example, in the following code, `b` does not directly participate
166+
/// in a branch, but condition coverage will instrument it as its own
167+
/// artificial branch:
168+
/// ```
169+
/// # let (a, b) = (false, true);
170+
/// let x = a && b;
171+
/// // ^ last operand
172+
/// ```
173+
///
174+
/// This level is mainly intended to be a stepping-stone towards full MC/DC
175+
/// instrumentation, so it might be removed in the future when MC/DC is
176+
/// sufficiently complete, or if it is making MC/DC changes difficult.
177+
Condition,
178+
/// Instrument for MC/DC. Mostly a superset of condition coverage, but might
163179
/// differ in some corner cases.
164180
Mcdc,
165181
}

compiler/rustc_session/src/options.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ mod desc {
395395
pub const parse_optimization_fuel: &str = "crate=integer";
396396
pub const parse_dump_mono_stats: &str = "`markdown` (default) or `json`";
397397
pub const parse_instrument_coverage: &str = parse_bool;
398-
pub const parse_coverage_options: &str = "`block` | `branch` | `mcdc`";
398+
pub const parse_coverage_options: &str = "`block` | `branch` | `condition` | `mcdc`";
399399
pub const parse_instrument_xray: &str = "either a boolean (`yes`, `no`, `on`, `off`, etc), or a comma separated list of settings: `always` or `never` (mutually exclusive), `ignore-loops`, `instruction-threshold=N`, `skip-entry`, `skip-exit`";
400400
pub const parse_unpretty: &str = "`string` or `string=string`";
401401
pub const parse_treat_err_as_bug: &str = "either no value or a non-negative number";
@@ -961,6 +961,7 @@ mod parse {
961961
match option {
962962
"block" => slot.level = CoverageLevel::Block,
963963
"branch" => slot.level = CoverageLevel::Branch,
964+
"condition" => slot.level = CoverageLevel::Condition,
964965
"mcdc" => slot.level = CoverageLevel::Mcdc,
965966
_ => return false,
966967
}

compiler/rustc_session/src/session.rs

+5
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

src/doc/unstable-book/src/compiler-flags/coverage-options.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ This option controls details of the coverage instrumentation performed by
55

66
Multiple options can be passed, separated by commas. Valid options are:
77

8-
- `block`, `branch`, `mcdc`:
8+
- `block`, `branch`, `condition`, `mcdc`:
99
Sets the level of coverage instrumentation.
1010
Setting the level will override any previously-specified level.
1111
- `block` (default):
1212
Blocks in the control-flow graph will be instrumented for coverage.
1313
- `branch`:
1414
In addition to block coverage, also enables branch coverage instrumentation.
15+
- `condition`:
16+
In addition to branch coverage, also instruments some boolean expressions
17+
as branches, even if they are not directly used as branch conditions.
1518
- `mcdc`:
16-
In addition to block and branch coverage, also enables MC/DC instrumentation.
19+
In addition to condition coverage, also enables MC/DC instrumentation.
1720
(Branch coverage instrumentation may differ in some cases.)
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: incorrect value `bad` for unstable option `coverage-options` - `block` | `branch` | `mcdc` was expected
1+
error: incorrect value `bad` for unstable option `coverage-options` - `block` | `branch` | `condition` | `mcdc` was expected
22

tests/ui/instrument-coverage/coverage-options.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ needs-profiler-support
2-
//@ revisions: block branch mcdc bad
2+
//@ revisions: block branch condition mcdc bad
33
//@ compile-flags -Cinstrument-coverage
44

55
//@ [block] check-pass
@@ -8,6 +8,9 @@
88
//@ [branch] check-pass
99
//@ [branch] compile-flags: -Zcoverage-options=branch
1010

11+
//@ [condition] check-pass
12+
//@ [condition] compile-flags: -Zcoverage-options=condition
13+
1114
//@ [mcdc] check-pass
1215
//@ [mcdc] compile-flags: -Zcoverage-options=mcdc
1316

0 commit comments

Comments
 (0)