Skip to content

Commit a5c017c

Browse files
committed
Introduce -C instrument-coverage=branch to gate branch coverage
This flag has to be used in combination with `-Zunstable-options`, and is added in advance of adding branch coverage instrumentation.
1 parent 249624b commit a5c017c

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

compiler/rustc_session/src/config.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ pub enum MirSpanview {
169169
pub enum InstrumentCoverage {
170170
/// Default `-C instrument-coverage` or `-C instrument-coverage=statement`
171171
All,
172+
/// Additionally, instrument branches and output branch coverage.
173+
/// `-Zunstable-options -C instrument-coverage=branch`
174+
Branch,
172175
/// `-Zunstable-options -C instrument-coverage=except-unused-generics`
173176
ExceptUnusedGenerics,
174177
/// `-Zunstable-options -C instrument-coverage=except-unused-functions`
@@ -2747,7 +2750,10 @@ pub fn build_session_options(
27472750
}
27482751
(Some(InstrumentCoverage::Off | InstrumentCoverage::All), _) => {}
27492752
(Some(_), _) if !unstable_opts.unstable_options => {
2750-
handler.early_error("`-C instrument-coverage=except-*` requires `-Z unstable-options`");
2753+
handler.early_error(
2754+
"`-C instrument-coverage=branch` and `-C instrument-coverage=except-*` \
2755+
require `-Z unstable-options`",
2756+
);
27512757
}
27522758
(None, None) => {}
27532759
(None, ic) => {

compiler/rustc_session/src/options.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ mod desc {
389389
pub const parse_mir_spanview: &str = "`statement` (default), `terminator`, or `block`";
390390
pub const parse_dump_mono_stats: &str = "`markdown` (default) or `json`";
391391
pub const parse_instrument_coverage: &str =
392-
"`all` (default), `except-unused-generics`, `except-unused-functions`, or `off`";
392+
"`all` (default), `branch`, `except-unused-generics`, `except-unused-functions`, or `off`";
393393
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`";
394394
pub const parse_unpretty: &str = "`string` or `string=string`";
395395
pub const parse_treat_err_as_bug: &str = "either no value or a non-negative number";
@@ -931,6 +931,7 @@ mod parse {
931931

932932
*slot = Some(match v {
933933
"all" => InstrumentCoverage::All,
934+
"branch" => InstrumentCoverage::Branch,
934935
"except-unused-generics" | "except_unused_generics" => {
935936
InstrumentCoverage::ExceptUnusedGenerics
936937
}
@@ -1356,6 +1357,7 @@ options! {
13561357
reports (note, the compiler build config must include `profiler = true`); \
13571358
implies `-C symbol-mangling-version=v0`. Optional values are:
13581359
`=all` (implicit value)
1360+
`=branch`
13591361
`=except-unused-generics`
13601362
`=except-unused-functions`
13611363
`=off` (default)"),
@@ -1597,6 +1599,7 @@ options! {
15971599
reports (note, the compiler build config must include `profiler = true`); \
15981600
implies `-C symbol-mangling-version=v0`. Optional values are:
15991601
`=all` (implicit value)
1602+
`=branch`
16001603
`=except-unused-generics`
16011604
`=except-unused-functions`
16021605
`=off` (default)"),

compiler/rustc_session/src/session.rs

+4
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,10 @@ impl Session {
702702
self.opts.cg.instrument_coverage() != InstrumentCoverage::Off
703703
}
704704

705+
pub fn instrument_coverage_branch(&self) -> bool {
706+
self.opts.cg.instrument_coverage() == InstrumentCoverage::Branch
707+
}
708+
705709
pub fn instrument_coverage_except_unused_generics(&self) -> bool {
706710
self.opts.cg.instrument_coverage() == InstrumentCoverage::ExceptUnusedGenerics
707711
}

0 commit comments

Comments
 (0)