about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-02-04 18:42:13 +0100
committerGitHub <noreply@github.com>2022-02-04 18:42:13 +0100
commit2fe9a32ed209b93ddd08cab174dfffefc1409a9c (patch)
treea7fc0622808fb70456c12277e3c236972453cf5f /src
parentcb18e83e8512be69b26fcb67ae66d81e5b7a4383 (diff)
parent3187f4136a82e51d524c55a29489c48d6d78b606 (diff)
Rollup merge of #90132 - joshtriplett:stabilize-instrument-coverage, r=wesleywiser
Stabilize `-Z instrument-coverage` as `-C instrument-coverage`

(Tracking issue for `instrument-coverage`: https://github.com/rust-lang/rust/issues/79121)

This PR stabilizes support for instrumentation-based code coverage, previously provided via the `-Z instrument-coverage` option. (Continue supporting `-Z instrument-coverage` for compatibility for now, but show a deprecation warning for it.)

Many, many people have tested this support, and there are numerous reports of it working as expected.

Move the documentation from the unstable book to stable rustc documentation. Update uses and documentation to use the `-C` option.

Addressing questions raised in the tracking issue:

> If/when stabilized, will the compiler flag be updated to -C instrument-coverage? (If so, the -Z variant could also be supported for some time, to ease migrations for existing users and scripts.)

This stabilization PR updates the option to `-C` and keeps the `-Z` variant to ease migration.

> The Rust coverage implementation depends on (and automatically turns on) -Z symbol-mangling-version=v0. Will stabilizing this feature depend on stabilizing v0 symbol-mangling first? If so, what is the current status and timeline?

This stabilization PR depends on https://github.com/rust-lang/rust/pull/90128 , which stabilizes `-C symbol-mangling-version=v0` (but does not change the default symbol-mangling-version).

> The Rust coverage implementation implements the latest version of LLVM's Coverage Mapping Format (version 4), which forces a dependency on LLVM 11 or later. A compiler error is generated if attempting to compile with coverage, and using an older version of LLVM.

Given that LLVM 13 has now been released, requiring LLVM 11 for coverage support seems like a reasonable requirement. If people don't have at least LLVM 11, nothing else breaks; they just can't use coverage support. Given that coverage support currently requires a nightly compiler and LLVM 11 or newer, allowing it on a stable compiler built with LLVM 11 or newer seems like an improvement.

The [tracking issue](https://github.com/rust-lang/rust/issues/79121) and the [issue label A-code-coverage](https://github.com/rust-lang/rust/labels/A-code-coverage) link to a few open issues related to `instrument-coverage`, but none of them seem like showstoppers. All of them seem like improvements and refinements we can make after stabilization.

The original `-Z instrument-coverage` support went through a compiler-team MCP at https://github.com/rust-lang/compiler-team/issues/278 . Based on that, `@pnkfelix` suggested that this needed a stabilization PR and a compiler-team FCP.
Diffstat (limited to 'src')
-rw-r--r--src/doc/rustc/src/SUMMARY.md1
-rw-r--r--src/doc/rustc/src/codegen-options/index.md10
-rw-r--r--src/doc/rustc/src/instrument-coverage.md (renamed from src/doc/unstable-book/src/compiler-flags/instrument-coverage.md)96
-rw-r--r--src/doc/unstable-book/src/compiler-flags/source-based-code-coverage.md5
-rw-r--r--src/librustdoc/doctest.rs4
-rw-r--r--src/test/mir-opt/coverage_graphviz.rs4
-rw-r--r--src/test/mir-opt/instrument_coverage.rs4
-rw-r--r--src/test/run-make-fulldeps/coverage-llvmir/Makefile2
-rw-r--r--src/test/run-make-fulldeps/coverage-llvmir/filecheck.testprog.txt2
-rw-r--r--src/test/run-make-fulldeps/coverage-reports/Makefile6
-rw-r--r--src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-85461.txt2
-rw-r--r--src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.uses_crate.txt2
-rw-r--r--src/test/run-make-fulldeps/coverage/lib/inline_always_with_dead_code.rs2
-rw-r--r--src/test/run-make-fulldeps/coverage/lib/used_crate.rs2
-rw-r--r--src/test/ui/issues/issue-85461.rs2
15 files changed, 67 insertions, 77 deletions
diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md
index 146408900ab..2fc94005b80 100644
--- a/src/doc/rustc/src/SUMMARY.md
+++ b/src/doc/rustc/src/SUMMARY.md
@@ -26,6 +26,7 @@
     - [Custom Targets](targets/custom.md)
     - [Known Issues](targets/known-issues.md)
 - [Profile-guided Optimization](profile-guided-optimization.md)
+- [Instrumentation-based Code Coverage](instrument-coverage.md)
 - [Linker-plugin based LTO](linker-plugin-lto.md)
 - [Exploit Mitigations](exploit-mitigations.md)
 - [Contributing to `rustc`](contributing.md)
diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md
index 0201b88417a..3b0cf92bbb7 100644
--- a/src/doc/rustc/src/codegen-options/index.md
+++ b/src/doc/rustc/src/codegen-options/index.md
@@ -177,6 +177,15 @@ The default depends on the [opt-level](#opt-level):
 | s         | 75 |
 | z         | 25 |
 
+## instrument-coverage
+
+This option enables instrumentation-based code coverage support. See the
+chapter on [instrumentation-based code coverage] for more information.
+
+Note that while the `-C instrument-coverage` option is stable, the profile data
+format produced by the resulting instrumentation may change, and may not work
+with coverage tools other than those built and shipped with the compiler.
+
 ## link-arg
 
 This flag lets you append a single extra argument to the linker invocation.
@@ -597,5 +606,6 @@ effective only for x86 targets.
 
 [option-emit]: ../command-line-arguments.md#option-emit
 [option-o-optimize]: ../command-line-arguments.md#option-o-optimize
+[instrumentation-based code coverage]: ../instrument-coverage.md
 [profile-guided optimization]: ../profile-guided-optimization.md
 [option-g-debug]: ../command-line-arguments.md#option-g-debug
diff --git a/src/doc/unstable-book/src/compiler-flags/instrument-coverage.md b/src/doc/rustc/src/instrument-coverage.md
index 39eb407269c..b94989161cc 100644
--- a/src/doc/unstable-book/src/compiler-flags/instrument-coverage.md
+++ b/src/doc/rustc/src/instrument-coverage.md
@@ -1,23 +1,17 @@
 # `instrument-coverage`
 
-The tracking issue for this feature is: [#79121].
-
-[#79121]: https://github.com/rust-lang/rust/issues/79121
-
----
-
 ## Introduction
 
 The Rust compiler includes two code coverage implementations:
 
 -   A GCC-compatible, gcov-based coverage implementation, enabled with `-Z profile`, which derives coverage data based on DebugInfo.
--   A source-based code coverage implementation, enabled with `-Z instrument-coverage`, which uses LLVM's native, efficient coverage instrumentation to generate very precise coverage data.
+-   A source-based code coverage implementation, enabled with `-C instrument-coverage`, which uses LLVM's native, efficient coverage instrumentation to generate very precise coverage data.
 
-This document describes how to enable and use the LLVM instrumentation-based coverage, via the `-Z instrument-coverage` compiler flag.
+This document describes how to enable and use the LLVM instrumentation-based coverage, via the `-C instrument-coverage` compiler flag.
 
 ## How it works
 
-When `-Z instrument-coverage` is enabled, the Rust compiler enhances rust-based libraries and binaries by:
+When `-C instrument-coverage` is enabled, the Rust compiler enhances rust-based libraries and binaries by:
 
 -   Automatically injecting calls to an LLVM intrinsic ([`llvm.instrprof.increment`]), at functions and branches in compiled code, to increment counters when conditional sections of code are executed.
 -   Embedding additional information in the data section of each library and binary (using the [LLVM Code Coverage Mapping Format] _Version 5_, if compiling with LLVM 12, or _Version 6_, if compiling with LLVM 13 or higher), to define the code regions (start and end positions in the source code) being counted.
@@ -27,13 +21,13 @@ When running a coverage-instrumented program, the counter values are written to
 [`llvm.instrprof.increment`]: https://llvm.org/docs/LangRef.html#llvm-instrprof-increment-intrinsic
 [llvm code coverage mapping format]: https://llvm.org/docs/CoverageMappingFormat.html
 
-> **Note**: `-Z instrument-coverage` also automatically enables `-C symbol-mangling-version=v0` (tracking issue [#60705]). The `v0` symbol mangler is strongly recommended, but be aware that this demangler is also experimental. The `v0` demangler can be overridden by explicitly adding `-Z unstable-options -C symbol-mangling-version=legacy`.
+> **Note**: `-C instrument-coverage` also automatically enables `-C symbol-mangling-version=v0` (tracking issue [#60705]). The `v0` symbol mangler is strongly recommended. The `v0` demangler can be overridden by explicitly adding `-Z unstable-options -C symbol-mangling-version=legacy`.
 
 [#60705]: https://github.com/rust-lang/rust/issues/60705
 
 ## Enable coverage profiling in the Rust compiler
 
-Rust's source-based code coverage requires the Rust "profiler runtime". Without it, compiling with `-Z instrument-coverage` generates an error that the profiler runtime is missing.
+Rust's source-based code coverage requires the Rust "profiler runtime". Without it, compiling with `-C instrument-coverage` generates an error that the profiler runtime is missing.
 
 The Rust `nightly` distribution channel includes the profiler runtime, by default.
 
@@ -41,7 +35,7 @@ The Rust `nightly` distribution channel includes the profiler runtime, by defaul
 >
 > ```toml
 > # Build the profiler runtime (required when compiling with options that depend
-> # on this runtime, such as `-C profile-generate` or `-Z  instrument-coverage`).
+> # on this runtime, such as `-C profile-generate` or `-C instrument-coverage`).
 > profiler = true
 > ```
 
@@ -65,9 +59,9 @@ $ ./x.py build rust-demangler
 
 ## Compiling with coverage enabled
 
-Set the `-Z instrument-coverage` compiler flag in order to enable LLVM source-based code coverage profiling.
+Set the `-C instrument-coverage` compiler flag in order to enable LLVM source-based code coverage profiling.
 
-The default option generates coverage for all functions, including unused (never called) functions and generics. The compiler flag supports an optional value to tailor this behavior. (See [`-Z instrument-coverage=<options>`](#-z-instrument-coverageoptions), below.)
+The default option generates coverage for all functions, including unused (never called) functions and generics. The compiler flag supports an optional value to tailor this behavior. (See [`-C instrument-coverage=<options>`](#-c-instrument-coverageoptions), below.)
 
 With `cargo`, you can instrument your program binary _and_ dependencies at the same time.
 
@@ -76,18 +70,18 @@ For example (if your project's Cargo.toml builds a binary by default):
 ```shell
 $ cd your-project
 $ cargo clean
-$ RUSTFLAGS="-Z instrument-coverage" cargo build
+$ RUSTFLAGS="-C instrument-coverage" cargo build
 ```
 
 If `cargo` is not configured to use your `profiler`-enabled version of `rustc`, set the path explicitly via the `RUSTC` environment variable. Here is another example, using a `stage1` build of `rustc` to compile an `example` binary (from the [`json5format`] crate):
 
 ```shell
 $ RUSTC=$HOME/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc \
-    RUSTFLAGS="-Z instrument-coverage" \
+    RUSTFLAGS="-C instrument-coverage" \
     cargo build --example formatjson5
 ```
 
-> **Note**: that some compiler options, combined with `-Z instrument-coverage`, can produce LLVM IR and/or linked binaries that are incompatible with LLVM coverage maps. For example, coverage requires references to actual functions in LLVM IR. If any covered function is optimized out, the coverage tools may not be able to process the coverage results. If you need to pass additional options, with coverage enabled, test them early, to confirm you will get the coverage results you expect.
+> **Note**: that some compiler options, combined with `-C instrument-coverage`, can produce LLVM IR and/or linked binaries that are incompatible with LLVM coverage maps. For example, coverage requires references to actual functions in LLVM IR. If any covered function is optimized out, the coverage tools may not be able to process the coverage results. If you need to pass additional options, with coverage enabled, test them early, to confirm you will get the coverage results you expect.
 
 ## Running the instrumented binary to generate raw coverage profiling data
 
@@ -123,31 +117,23 @@ If `LLVM_PROFILE_FILE` contains a path to a non-existent directory, the missing
 
 ## Installing LLVM coverage tools
 
-LLVM's supplies two tools—`llvm-profdata` and `llvm-cov`—that process coverage data and generate reports. There are several ways to find and/or install these tools, but note that the coverage mapping data generated by the Rust compiler requires LLVM version 12 or higher. (`llvm-cov --version` typically shows the tool's LLVM version number.):
+LLVM's supplies two tools—`llvm-profdata` and `llvm-cov`—that process coverage data and generate reports. There are several ways to find and/or install these tools, but note that the coverage mapping data generated by the Rust compiler requires LLVM version 12 or higher, and processing the *raw* data may require exactly the LLVM version used by the compiler. (`llvm-cov --version` typically shows the tool's LLVM version number, and `rustc --verbose --version` shows the version of LLVM used by the Rust compiler.)
 
--   The LLVM tools may be installed (or installable) directly to your OS (such as via `apt-get`, for Linux).
+-   You can install compatible versions of these tools via the `rustup` component `llvm-tools-preview`. This component is the recommended path, though the specific tools available and their interface is not currently subject to Rust's usual stability guarantees. In this case, you may also find `cargo-binutils` useful as a wrapper around these tools.
+-   You can install a compatible version of LLVM tools from your operating system distribution, or from your distribution of LLVM.
 -   If you are building the Rust compiler from source, you can optionally use the bundled LLVM tools, built from source. Those tool binaries can typically be found in your build platform directory at something like: `rust/build/x86_64-unknown-linux-gnu/llvm/bin/llvm-*`.
--   You can install compatible versions of these tools via `rustup`.
-
-The `rustup` option is guaranteed to install a compatible version of the LLVM tools, but they can be hard to find. We recommend [`cargo-binutils`], which installs Rust-specific wrappers around these and other LLVM tools, so you can invoke them via `cargo` commands!
-
-```shell
-$ rustup component add llvm-tools-preview
-$ cargo install cargo-binutils
-$ cargo profdata -- --help  # note the additional "--" preceding the tool-specific arguments
-```
 
-[`cargo-binutils`]: https://crates.io/crates/cargo-binutils
+The examples in this document show how to use the llvm tools directly.
 
 ## Creating coverage reports
 
-Raw profiles have to be indexed before they can be used to generate coverage reports. This is done using [`llvm-profdata merge`] (or `cargo profdata -- merge`), which can combine multiple raw profiles and index them at the same time:
+Raw profiles have to be indexed before they can be used to generate coverage reports. This is done using [`llvm-profdata merge`], which can combine multiple raw profiles and index them at the same time:
 
 ```shell
 $ llvm-profdata merge -sparse formatjson5.profraw -o formatjson5.profdata
 ```
 
-Finally, the `.profdata` file is used, in combination with the coverage map (from the program binary) to generate coverage reports using [`llvm-cov report`] (or `cargo cov -- report`), for a coverage summaries; and [`llvm-cov show`] (or `cargo cov -- show`), to see detailed coverage of lines and regions (character ranges) overlaid on the original source code.
+Finally, the `.profdata` file is used, in combination with the coverage map (from the program binary) to generate coverage reports using [`llvm-cov report`], for a coverage summaries; and [`llvm-cov show`], to see detailed coverage of lines and regions (character ranges) overlaid on the original source code.
 
 These commands have several display and filtering options. For example:
 
@@ -176,7 +162,7 @@ Some of the more notable options in this example include:
 
 > **Note**: Coverage can also be disabled on an individual function by annotating the function with the [`no_coverage` attribute] (which requires the feature flag `#![feature(no_coverage)]`).
 
-[`no_coverage` attribute]: ../language-features/no-coverage.md
+[`no_coverage` attribute]: ../unstable-book/language-features/no-coverage.html
 
 ## Interpreting reports
 
@@ -195,10 +181,10 @@ A typical use case for coverage analysis is test coverage. Rust's source-based c
 
 The following example (using the [`json5format`] crate, for demonstration purposes) show how to generate and analyze coverage results for all tests in a crate.
 
-Since `cargo test` both builds and runs the tests, we set both the additional `RUSTFLAGS`, to add the `-Z instrument-coverage` flag, and `LLVM_PROFILE_FILE`, to set a custom filename for the raw profiling data generated during the test runs. Since there may be more than one test binary, apply `%m` in the filename pattern. This generates unique names for each test binary. (Otherwise, each executed test binary would overwrite the coverage results from the previous binary.)
+Since `cargo test` both builds and runs the tests, we set both the additional `RUSTFLAGS`, to add the `-C instrument-coverage` flag, and `LLVM_PROFILE_FILE`, to set a custom filename for the raw profiling data generated during the test runs. Since there may be more than one test binary, apply `%m` in the filename pattern. This generates unique names for each test binary. (Otherwise, each executed test binary would overwrite the coverage results from the previous binary.)
 
 ```shell
-$ RUSTFLAGS="-Z instrument-coverage" \
+$ RUSTFLAGS="-C instrument-coverage" \
     LLVM_PROFILE_FILE="json5format-%m.profraw" \
     cargo test --tests
 ```
@@ -224,19 +210,18 @@ test result: ok. 31 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
 You should have one or more `.profraw` files now, one for each test binary. Run the `profdata` tool to merge them:
 
 ```shell
-$ cargo profdata -- merge \
-    -sparse json5format-*.profraw -o json5format.profdata
+$ llvm-profdata merge -sparse json5format-*.profraw -o json5format.profdata
 ```
 
 Then run the `cov` tool, with the `profdata` file and all test binaries:
 
 ```shell
-$ cargo cov -- report \
+$ llvm-cov report \
     --use-color --ignore-filename-regex='/.cargo/registry' \
     --instr-profile=json5format.profdata \
     --object target/debug/deps/lib-30768f9c53506dc5 \
     --object target/debug/deps/json5format-fececd4653271682
-$ cargo cov -- show \
+$ llvm-cov show \
     --use-color --ignore-filename-regex='/.cargo/registry' \
     --instr-profile=json5format.profdata \
     --object target/debug/deps/lib-30768f9c53506dc5 \
@@ -252,11 +237,11 @@ $ cargo cov -- show \
 For `bash` users, one suggested way to automatically complete the `cov` command with the list of binaries is with a command like:
 
 ```bash
-$ cargo cov -- report \
+$ llvm-cov report \
     $( \
       for file in \
         $( \
-          RUSTFLAGS="-Z instrument-coverage" \
+          RUSTFLAGS="-C instrument-coverage" \
             cargo test --tests --no-run --message-format=json \
               | jq -r "select(.profile.test == true) | .filenames[]" \
               | grep -v dSYM - \
@@ -280,28 +265,27 @@ for each listed test binary.
 The previous examples run `cargo test` with `--tests`, which excludes doc tests.[^79417]
 
 To include doc tests in the coverage results, drop the `--tests` flag, and apply the
-`-Z instrument-coverage` flag, and some doc-test-specific options in the
-`RUSTDOCFLAGS` environment variable. (The `cargo profdata` command does not change.)
+`-C instrument-coverage` flag, and some doc-test-specific options in the
+`RUSTDOCFLAGS` environment variable. (The `llvm-profdata` command does not change.)
 
 ```bash
-$ RUSTFLAGS="-Z instrument-coverage" \
-  RUSTDOCFLAGS="-Z instrument-coverage -Z unstable-options --persist-doctests target/debug/doctestbins" \
+$ RUSTFLAGS="-C instrument-coverage" \
+  RUSTDOCFLAGS="-C instrument-coverage -Z unstable-options --persist-doctests target/debug/doctestbins" \
   LLVM_PROFILE_FILE="json5format-%m.profraw" \
     cargo test
-$ cargo profdata -- merge \
-    -sparse json5format-*.profraw -o json5format.profdata
+$ llvm-profdata merge -sparse json5format-*.profraw -o json5format.profdata
 ```
 
 The `-Z unstable-options --persist-doctests` flag is required, to save the test binaries
 (with their coverage maps) for `llvm-cov`.
 
 ```bash
-$ cargo cov -- report \
+$ llvm-cov report \
     $( \
       for file in \
         $( \
-          RUSTFLAGS="-Z instrument-coverage" \
-          RUSTDOCFLAGS="-Z instrument-coverage -Z unstable-options --persist-doctests target/debug/doctestbins" \
+          RUSTFLAGS="-C instrument-coverage" \
+          RUSTDOCFLAGS="-C instrument-coverage -Z unstable-options --persist-doctests target/debug/doctestbins" \
             cargo test --no-run --message-format=json \
               | jq -r "select(.profile.test == true) | .filenames[]" \
               | grep -v dSYM - \
@@ -314,8 +298,8 @@ $ cargo cov -- report \
   --instr-profile=json5format.profdata --summary-only # and/or other options
 ```
 
-> **Note**: The differences in this `cargo cov` command, compared with the version without
-> doc tests, include:
+> **Note**: The differences in this `llvm-cov` invocation, compared with the
+> version without doc tests, include:
 
 -   The `cargo test ... --no-run` command is updated with the same environment variables
     and flags used to _build_ the tests, _including_ the doc tests. (`LLVM_PROFILE_FILE`
@@ -331,12 +315,12 @@ $ cargo cov -- report \
     [(#79417)](https://github.com/rust-lang/rust/issues/79417) that doc test coverage
     generates incorrect source line numbers in `llvm-cov show` results.
 
-## `-Z instrument-coverage=<options>`
+## `-C instrument-coverage=<options>`
 
--   `-Z instrument-coverage=all`: Instrument all functions, including unused functions and unused generics. (This is the same as `-Z instrument-coverage`, with no value.)
--   `-Z instrument-coverage=except-unused-generics`: Instrument all functions except unused generics.
--   `-Z instrument-coverage=except-unused-functions`: Instrument only used (called) functions and instantiated generic functions.
--   `-Z instrument-coverage=off`: Do not instrument any functions. (This is the same as simply not including the `-Z instrument-coverage` option.)
+-   `-C instrument-coverage=all`: Instrument all functions, including unused functions and unused generics. (This is the same as `-C instrument-coverage`, with no value.)
+-   `-C instrument-coverage=off`: Do not instrument any functions. (This is the same as simply not including the `-C instrument-coverage` option.)
+-   `-Zunstable-options -C instrument-coverage=except-unused-generics`: Instrument all functions except unused generics.
+-   `-Zunstable-options -C instrument-coverage=except-unused-functions`: Instrument only used (called) functions and instantiated generic functions.
 
 ## Other references
 
diff --git a/src/doc/unstable-book/src/compiler-flags/source-based-code-coverage.md b/src/doc/unstable-book/src/compiler-flags/source-based-code-coverage.md
deleted file mode 100644
index cb65978e0a0..00000000000
--- a/src/doc/unstable-book/src/compiler-flags/source-based-code-coverage.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# `source-based-code-coverage`
-
-See compiler flag [`-Z instrument-coverage`].
-
-[`-z instrument-coverage`]: ./instrument-coverage.html
diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs
index 024fe6345d2..d16383723f5 100644
--- a/src/librustdoc/doctest.rs
+++ b/src/librustdoc/doctest.rs
@@ -659,7 +659,7 @@ crate fn make_test(
     } else {
         let returns_result = everything_else.trim_end().ends_with("(())");
         // Give each doctest main function a unique name.
-        // This is for example needed for the tooling around `-Z instrument-coverage`.
+        // This is for example needed for the tooling around `-C instrument-coverage`.
         let inner_fn_name = if let Some(test_id) = test_id {
             format!("_doctest_main_{}", test_id)
         } else {
@@ -684,7 +684,7 @@ crate fn make_test(
         };
         // Note on newlines: We insert a line/newline *before*, and *after*
         // the doctest and adjust the `line_offset` accordingly.
-        // In the case of `-Z instrument-coverage`, this means that the generated
+        // In the case of `-C instrument-coverage`, this means that the generated
         // inner `main` function spans from the doctest opening codeblock to the
         // closing one. For example
         // /// ``` <- start of the inner main
diff --git a/src/test/mir-opt/coverage_graphviz.rs b/src/test/mir-opt/coverage_graphviz.rs
index b3c90c52837..09403bb3a79 100644
--- a/src/test/mir-opt/coverage_graphviz.rs
+++ b/src/test/mir-opt/coverage_graphviz.rs
@@ -1,9 +1,9 @@
-// Test that `-Z instrument-coverage` with `-Z dump-mir-graphviz` generates a graphviz (.dot file)
+// Test that `-C instrument-coverage` with `-Z dump-mir-graphviz` generates a graphviz (.dot file)
 // rendering of the `BasicCoverageBlock` coverage control flow graph, with counters and
 // expressions.
 
 // needs-profiler-support
-// compile-flags: -Z instrument-coverage -Z dump-mir-graphviz
+// compile-flags: -C instrument-coverage -Z dump-mir-graphviz
 // EMIT_MIR coverage_graphviz.main.InstrumentCoverage.0.dot
 // EMIT_MIR coverage_graphviz.bar.InstrumentCoverage.0.dot
 fn main() {
diff --git a/src/test/mir-opt/instrument_coverage.rs b/src/test/mir-opt/instrument_coverage.rs
index 18863edac97..a748f2c5ccc 100644
--- a/src/test/mir-opt/instrument_coverage.rs
+++ b/src/test/mir-opt/instrument_coverage.rs
@@ -1,9 +1,9 @@
-// Test that `-Z instrument-coverage` injects Coverage statements. The Coverage Counter statements
+// Test that `-C instrument-coverage` injects Coverage statements. The Coverage Counter statements
 // are later converted into LLVM instrprof.increment intrinsics, during codegen.
 
 // needs-profiler-support
 // ignore-windows
-// compile-flags: -Z instrument-coverage --remap-path-prefix={{src-base}}=/the/src
+// compile-flags: -C instrument-coverage --remap-path-prefix={{src-base}}=/the/src
 
 // EMIT_MIR instrument_coverage.main.InstrumentCoverage.diff
 // EMIT_MIR instrument_coverage.bar.InstrumentCoverage.diff
diff --git a/src/test/run-make-fulldeps/coverage-llvmir/Makefile b/src/test/run-make-fulldeps/coverage-llvmir/Makefile
index 3c4df3533e1..fbe0a5cb1bb 100644
--- a/src/test/run-make-fulldeps/coverage-llvmir/Makefile
+++ b/src/test/run-make-fulldeps/coverage-llvmir/Makefile
@@ -57,7 +57,7 @@ all: test_llvm_ir
 test_llvm_ir:
 	# Compile the test program with non-experimental coverage instrumentation, and generate LLVM IR
 	$(RUSTC) $(BASEDIR)/testprog.rs \
-			-Zinstrument-coverage \
+			-Cinstrument-coverage \
 			--emit=llvm-ir
 
 	cat "$(TMPDIR)"/testprog.ll | \
diff --git a/src/test/run-make-fulldeps/coverage-llvmir/filecheck.testprog.txt b/src/test/run-make-fulldeps/coverage-llvmir/filecheck.testprog.txt
index 8e5f2104687..1e2ecc2fbb1 100644
--- a/src/test/run-make-fulldeps/coverage-llvmir/filecheck.testprog.txt
+++ b/src/test/run-make-fulldeps/coverage-llvmir/filecheck.testprog.txt
@@ -1,5 +1,5 @@
 # Check for metadata, variables, declarations, and function definitions injected
-# into LLVM IR when compiling with -Zinstrument-coverage.
+# into LLVM IR when compiling with -Cinstrument-coverage.
 
 WINDOWS:      $__llvm_profile_runtime_user = comdat any
 
diff --git a/src/test/run-make-fulldeps/coverage-reports/Makefile b/src/test/run-make-fulldeps/coverage-reports/Makefile
index 094d6b3ebf5..78723e78e77 100644
--- a/src/test/run-make-fulldeps/coverage-reports/Makefile
+++ b/src/test/run-make-fulldeps/coverage-reports/Makefile
@@ -81,13 +81,13 @@ endif
 	# Compile the test library with coverage instrumentation
 	$(RUSTC) $(SOURCEDIR)/lib/$@.rs \
 			$$( sed -n 's/^\/\/ compile-flags: \([^#]*\).*/\1/p' $(SOURCEDIR)/lib/$@.rs ) \
-			--crate-type rlib -Zinstrument-coverage
+			--crate-type rlib -Cinstrument-coverage
 
 %: $(SOURCEDIR)/%.rs
 	# Compile the test program with coverage instrumentation
 	$(RUSTC) $(SOURCEDIR)/$@.rs \
 			$$( sed -n 's/^\/\/ compile-flags: \([^#]*\).*/\1/p' $(SOURCEDIR)/$@.rs ) \
-			-L "$(TMPDIR)" -Zinstrument-coverage
+			-L "$(TMPDIR)" -Cinstrument-coverage
 
 	# Run it in order to generate some profiling data,
 	# with `LLVM_PROFILE_FILE=<profdata_file>` environment variable set to
@@ -109,7 +109,7 @@ endif
 	LLVM_PROFILE_FILE="$(TMPDIR)"/$@-%p-%m.profraw \
 			$(RUSTDOC) --crate-name workaround_for_79771 --test $(SOURCEDIR)/$@.rs \
 			$$( sed -n 's/^\/\/ compile-flags: \([^#]*\).*/\1/p' $(SOURCEDIR)/$@.rs ) \
-			-L "$(TMPDIR)" -Zinstrument-coverage \
+			-L "$(TMPDIR)" -Cinstrument-coverage \
 			-Z unstable-options --persist-doctests=$(TMPDIR)/rustdoc-$@
 
 	# Postprocess the profiling data so it can be used by the llvm-cov tool
diff --git a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-85461.txt b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-85461.txt
index 2831e9b532a..1aa4a22c33e 100644
--- a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-85461.txt
+++ b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-85461.txt
@@ -11,7 +11,7 @@
    10|      1|}
 
 ../coverage/lib/inline_always_with_dead_code.rs:
-    1|       |// compile-flags: -Zinstrument-coverage -Ccodegen-units=4 -Copt-level=0
+    1|       |// compile-flags: -Cinstrument-coverage -Ccodegen-units=4 -Copt-level=0
     2|       |
     3|       |#![allow(dead_code)]
     4|       |
diff --git a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.uses_crate.txt b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.uses_crate.txt
index c2d5143a618..55a49548cb5 100644
--- a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.uses_crate.txt
+++ b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.uses_crate.txt
@@ -125,7 +125,7 @@
    78|       |// generic functions with:
    79|       |//
    80|       |// ```shell
-   81|       |// $ `rustc -Z instrument-coverage=except-unused-generics ...`
+   81|       |// $ `rustc -Zunstable-options -C instrument-coverage=except-unused-generics ...`
    82|       |// ```
    83|       |//
    84|       |// Even though this function is used by `uses_crate.rs` (and
diff --git a/src/test/run-make-fulldeps/coverage/lib/inline_always_with_dead_code.rs b/src/test/run-make-fulldeps/coverage/lib/inline_always_with_dead_code.rs
index b567916aea0..2b21dee6ccf 100644
--- a/src/test/run-make-fulldeps/coverage/lib/inline_always_with_dead_code.rs
+++ b/src/test/run-make-fulldeps/coverage/lib/inline_always_with_dead_code.rs
@@ -1,4 +1,4 @@
-// compile-flags: -Zinstrument-coverage -Ccodegen-units=4 -Copt-level=0
+// compile-flags: -Cinstrument-coverage -Ccodegen-units=4 -Copt-level=0
 
 #![allow(dead_code)]
 
diff --git a/src/test/run-make-fulldeps/coverage/lib/used_crate.rs b/src/test/run-make-fulldeps/coverage/lib/used_crate.rs
index eaa93115ae8..8b8b1f7f351 100644
--- a/src/test/run-make-fulldeps/coverage/lib/used_crate.rs
+++ b/src/test/run-make-fulldeps/coverage/lib/used_crate.rs
@@ -78,7 +78,7 @@ fn use_this_lib_crate() {
 // generic functions with:
 //
 // ```shell
-// $ `rustc -Z instrument-coverage=except-unused-generics ...`
+// $ `rustc -Zunstable-options -C instrument-coverage=except-unused-generics ...`
 // ```
 //
 // Even though this function is used by `uses_crate.rs` (and
diff --git a/src/test/ui/issues/issue-85461.rs b/src/test/ui/issues/issue-85461.rs
index 4c6c83f2612..9655108876f 100644
--- a/src/test/ui/issues/issue-85461.rs
+++ b/src/test/ui/issues/issue-85461.rs
@@ -1,4 +1,4 @@
-// compile-flags: -Zinstrument-coverage -Ccodegen-units=4 --crate-type dylib -Copt-level=0
+// compile-flags: -Cinstrument-coverage -Ccodegen-units=4 --crate-type dylib -Copt-level=0
 // build-pass
 // needs-profiler-support