Skip to content

Commit 51268d2

Browse files
committed
Check for LLVM 11+ when using -Z instrument-coverage
* `rustc` should now compile under LLVM 9 or 10 * Compiler generates an error if `-Z instrument-coverage` is specified but LLVM version is less than 11 * Coverage tests that require `-Z instrument-coverage` and run codegen should be skipped if LLVM version is less than 11
1 parent 5d5dc4c commit 51268d2

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn finalize<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
3939

4040
// Encode coverage mappings and generate function records
4141
let mut function_data = Vec::new();
42-
for (instance, function_coverage) in function_coverage_map.into_iter() {
42+
for (instance, function_coverage) in function_coverage_map {
4343
debug!("Generate coverage map for: {:?}", instance);
4444

4545
let mangled_function_name = cx.tcx.symbol_name(instance).to_string();
@@ -172,7 +172,7 @@ impl CoverageMapGenerator {
172172
// as of `llvm::coverage::CovMapVersion::Version4`.
173173
let zero_was_n_records_val = cx.const_u32(0);
174174
let filenames_size_val = cx.const_u32(filenames_size as u32);
175-
let zero_was_coverage_size_val = cx.const_u32(0 as u32);
175+
let zero_was_coverage_size_val = cx.const_u32(0);
176176
let version_val = cx.const_u32(coverageinfo::mapping_version());
177177
let cov_data_header_val = cx.const_struct(
178178
&[zero_was_n_records_val, filenames_size_val, zero_was_coverage_size_val, version_val],

compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ extern "C" void LLVMRustCoverageWriteMapSectionNameToString(LLVMModuleRef M,
7171

7272
extern "C" void LLVMRustCoverageWriteFuncSectionNameToString(LLVMModuleRef M,
7373
RustStringRef Str) {
74+
#if LLVM_VERSION_GE(11, 0)
7475
WriteSectionNameToString(M, IPSK_covfun, Str);
76+
#else
77+
report_fatal_error("rustc option `-Z instrument-coverage` requires LLVM 11 or higher.");
78+
#endif
7579
}
7680

7781
extern "C" void LLVMRustCoverageWriteMappingVarNameToString(RustStringRef Str) {
@@ -81,5 +85,9 @@ extern "C" void LLVMRustCoverageWriteMappingVarNameToString(RustStringRef Str) {
8185
}
8286

8387
extern "C" uint32_t LLVMRustCoverageMappingVersion() {
88+
#if LLVM_VERSION_GE(11, 0)
8489
return coverage::CovMapVersion::Version4;
90+
#else
91+
report_fatal_error("rustc option `-Z instrument-coverage` requires LLVM 11 or higher.");
92+
#endif
8593
}

src/test/run-make-fulldeps/coverage-llvmir-base/Makefile

+9-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ else
5656
-DINSTR_PROF_ORDERFILE='$(DATA_SECTION_PREFIX)__llvm_orderfile'
5757
endif
5858

59+
ifeq ($(LLVM_VERSION_11_PLUS),false)
60+
all: test_llvm_ir
61+
else
62+
$(info Rust option `-Z instrument-coverage` requires LLVM 11 or higher. Test skipped.)
5963
all:
64+
endif
65+
66+
test_llvm_ir:
6067
# Compile the test program with non-experimental coverage instrumentation, and generate LLVM IR
6168
#
6269
# Note: `-Clink-dead-code=no` disables the option, needed because the option is automatically
@@ -68,4 +75,5 @@ all:
6875
-Clink-dead-code=$(LINK_DEAD_CODE) \
6976
--emit=llvm-ir
7077

71-
cat "$(TMPDIR)"/testprog.ll | "$(LLVM_FILECHECK)" $(BASEDIR)/filecheck.testprog.txt $(LLVM_FILECHECK_OPTIONS)
78+
cat "$(TMPDIR)"/testprog.ll | \
79+
"$(LLVM_FILECHECK)" $(BASEDIR)/filecheck.testprog.txt $(LLVM_FILECHECK_OPTIONS)

src/test/run-make-fulldeps/coverage-reports-base/Makefile

+9-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ SOURCEDIR=../coverage
1818
# `llvm/release_debuginfo`. Note that some CI builds disable debug assertions (by setting
1919
# `NO_LLVM_ASSERTIONS=1`), so it is not OK to fail the test, but `bless`ed test results cannot be
2020
# generated without debug assertions.
21-
LLVM_COV_DEBUG := $(shell "$(LLVM_BIN_DIR)"/llvm-cov show --debug 2>&1 | grep -q "Unknown command line argument '--debug'"; echo $$?)
21+
LLVM_COV_DEBUG := $(shell \
22+
"$(LLVM_BIN_DIR)"/llvm-cov show --debug 2>&1 | \
23+
grep -q "Unknown command line argument '--debug'"; \
24+
echo $$?)
2225
ifeq ($(LLVM_COV_DEBUG), 1)
2326
DEBUG_FLAG=--debug
2427
endif
@@ -30,7 +33,12 @@ ifdef RUSTC_BLESS_TEST
3033
DEBUG_FLAG=--debug
3134
endif
3235

36+
ifeq ($(LLVM_VERSION_11_PLUS),true)
3337
all: $(patsubst $(SOURCEDIR)/%.rs,%,$(wildcard $(SOURCEDIR)/*.rs))
38+
else
39+
$(info Rust option `-Z instrument-coverage` requires LLVM 11 or higher. Test skipped.)
40+
all:
41+
endif
3442

3543
# Ensure there are no `expected` results for tests that may have been removed or renamed
3644
.PHONY: clear_expected_if_blessed

src/test/run-make-fulldeps/coverage-spanview-base/Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ For revisions in Pull Requests (PR):
2424
endef
2525
export SPANVIEW_HEADER
2626

27+
ifeq ($(LLVM_VERSION_11_PLUS),true)
2728
all: $(patsubst $(SOURCEDIR)/%.rs,%,$(wildcard $(SOURCEDIR)/*.rs))
29+
else
30+
$(info Rust option `-Z instrument-coverage` requires LLVM 11 or higher. Test skipped.)
31+
all:
32+
endif
2833

2934
# Ensure there are no `expected` results for tests that may have been removed or renamed
3035
.PHONY: clear_expected_if_blessed

src/test/run-make-fulldeps/coverage/coverage_tools.mk

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ endif
3838

3939
UNAME = $(shell uname)
4040

41+
# Rust option `-Z instrument-coverage` uses LLVM Coverage Mapping Format version 4,
42+
# which requires LLVM 11 or greater.
43+
LLVM_VERSION_11_PLUS := $(shell \
44+
LLVM_VERSION=$$("$(LLVM_BIN_DIR)"/llvm-config --version) && \
45+
LLVM_VERSION_MAJOR=$${LLVM_VERSION/.*/} && \
46+
[ $$LLVM_VERSION_MAJOR -ge 11 ] && echo true || echo false)
47+
4148
# FIXME(richkadel): Can any of the features tested by `run-make-fulldeps/coverage-*` tests be tested
4249
# just as completely by more focused unit tests of the code logic itself, to reduce the number of
4350
# test result files generated and maintained, and to help identify specific test failures and root

0 commit comments

Comments
 (0)