Skip to content

Commit 9f5a933

Browse files
committed
Remove backwards compat for LLVM 12 coverage format
1 parent e94fab6 commit 9f5a933

File tree

3 files changed

+17
-35
lines changed

3 files changed

+17
-35
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+17-28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::common::CodegenCx;
22
use crate::coverageinfo;
3-
use crate::errors::InstrumentCoverageRequiresLLVM12;
43
use crate::llvm;
54

65
use llvm::coverageinfo::CounterMappingRegion;
@@ -19,8 +18,8 @@ use std::ffi::CString;
1918

2019
/// Generates and exports the Coverage Map.
2120
///
22-
/// Rust Coverage Map generation supports LLVM Coverage Mapping Format versions
23-
/// 5 (LLVM 12, only) and 6 (zero-based encoded as 4 and 5, respectively), as defined at
21+
/// Rust Coverage Map generation supports LLVM Coverage Mapping Format version
22+
/// 6 (zero-based encoded as 5), as defined at
2423
/// [LLVM Code Coverage Mapping Format](https://github.com/rust-lang/llvm-project/blob/rustc/13.0-2021-09-30/llvm/docs/CoverageMappingFormat.rst#llvm-code-coverage-mapping-format).
2524
/// These versions are supported by the LLVM coverage tools (`llvm-profdata` and `llvm-cov`)
2625
/// bundled with Rust's fork of LLVM.
@@ -33,13 +32,10 @@ use std::ffi::CString;
3332
pub fn finalize(cx: &CodegenCx<'_, '_>) {
3433
let tcx = cx.tcx;
3534

36-
// Ensure the installed version of LLVM supports at least Coverage Map
37-
// Version 5 (encoded as a zero-based value: 4), which was introduced with
38-
// LLVM 12.
35+
// Ensure the installed version of LLVM supports Coverage Map Version 6
36+
// (encoded as a zero-based value: 5), which was introduced with LLVM 13.
3937
let version = coverageinfo::mapping_version();
40-
if version < 4 {
41-
tcx.sess.emit_fatal(InstrumentCoverageRequiresLLVM12);
42-
}
38+
assert_eq!(version, 5, "The `CoverageMappingVersion` exposed by `llvm-wrapper` is out of sync");
4339

4440
debug!("Generating coverage map for CodegenUnit: `{}`", cx.codegen_unit.name());
4541

@@ -61,7 +57,7 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
6157
return;
6258
}
6359

64-
let mut mapgen = CoverageMapGenerator::new(tcx, version);
60+
let mut mapgen = CoverageMapGenerator::new(tcx);
6561

6662
// Encode coverage mappings and generate function records
6763
let mut function_data = Vec::new();
@@ -124,25 +120,18 @@ struct CoverageMapGenerator {
124120
}
125121

126122
impl CoverageMapGenerator {
127-
fn new(tcx: TyCtxt<'_>, version: u32) -> Self {
123+
fn new(tcx: TyCtxt<'_>) -> Self {
128124
let mut filenames = FxIndexSet::default();
129-
if version >= 5 {
130-
// LLVM Coverage Mapping Format version 6 (zero-based encoded as 5)
131-
// requires setting the first filename to the compilation directory.
132-
// Since rustc generates coverage maps with relative paths, the
133-
// compilation directory can be combined with the relative paths
134-
// to get absolute paths, if needed.
135-
let working_dir = tcx
136-
.sess
137-
.opts
138-
.working_dir
139-
.remapped_path_if_available()
140-
.to_string_lossy()
141-
.to_string();
142-
let c_filename =
143-
CString::new(working_dir).expect("null error converting filename to C string");
144-
filenames.insert(c_filename);
145-
}
125+
// LLVM Coverage Mapping Format version 6 (zero-based encoded as 5)
126+
// requires setting the first filename to the compilation directory.
127+
// Since rustc generates coverage maps with relative paths, the
128+
// compilation directory can be combined with the relative paths
129+
// to get absolute paths, if needed.
130+
let working_dir =
131+
tcx.sess.opts.working_dir.remapped_path_if_available().to_string_lossy().to_string();
132+
let c_filename =
133+
CString::new(working_dir).expect("null error converting filename to C string");
134+
filenames.insert(c_filename);
146135
Self { filenames }
147136
}
148137

compiler/rustc_codegen_llvm/src/errors.rs

-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ pub(crate) struct ErrorCreatingImportLibrary<'a> {
3939
pub error: String,
4040
}
4141

42-
#[derive(Diagnostic)]
43-
#[diag(codegen_llvm_instrument_coverage_requires_llvm_12)]
44-
pub(crate) struct InstrumentCoverageRequiresLLVM12;
45-
4642
#[derive(Diagnostic)]
4743
#[diag(codegen_llvm_symbol_already_defined)]
4844
pub(crate) struct SymbolAlreadyDefined<'a> {

compiler/rustc_error_messages/locales/en-US/codegen_llvm.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ codegen_llvm_unknown_ctarget_feature_prefix =
1111
codegen_llvm_error_creating_import_library =
1212
Error creating import library for {$lib_name}: {$error}
1313
14-
codegen_llvm_instrument_coverage_requires_llvm_12 =
15-
rustc option `-C instrument-coverage` requires LLVM 12 or higher.
16-
1714
codegen_llvm_symbol_already_defined =
1815
symbol `{$symbol_name}` is already defined
1916

0 commit comments

Comments
 (0)