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
This commit is contained in:
parent
5d5dc4c9d8
commit
51268d2735
@ -39,7 +39,7 @@ pub fn finalize<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
|
||||
|
||||
// Encode coverage mappings and generate function records
|
||||
let mut function_data = Vec::new();
|
||||
for (instance, function_coverage) in function_coverage_map.into_iter() {
|
||||
for (instance, function_coverage) in function_coverage_map {
|
||||
debug!("Generate coverage map for: {:?}", instance);
|
||||
|
||||
let mangled_function_name = cx.tcx.symbol_name(instance).to_string();
|
||||
@ -172,7 +172,7 @@ impl CoverageMapGenerator {
|
||||
// as of `llvm::coverage::CovMapVersion::Version4`.
|
||||
let zero_was_n_records_val = cx.const_u32(0);
|
||||
let filenames_size_val = cx.const_u32(filenames_size as u32);
|
||||
let zero_was_coverage_size_val = cx.const_u32(0 as u32);
|
||||
let zero_was_coverage_size_val = cx.const_u32(0);
|
||||
let version_val = cx.const_u32(coverageinfo::mapping_version());
|
||||
let cov_data_header_val = cx.const_struct(
|
||||
&[zero_was_n_records_val, filenames_size_val, zero_was_coverage_size_val, version_val],
|
||||
|
@ -71,7 +71,11 @@ extern "C" void LLVMRustCoverageWriteMapSectionNameToString(LLVMModuleRef M,
|
||||
|
||||
extern "C" void LLVMRustCoverageWriteFuncSectionNameToString(LLVMModuleRef M,
|
||||
RustStringRef Str) {
|
||||
#if LLVM_VERSION_GE(11, 0)
|
||||
WriteSectionNameToString(M, IPSK_covfun, Str);
|
||||
#else
|
||||
report_fatal_error("rustc option `-Z instrument-coverage` requires LLVM 11 or higher.");
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" void LLVMRustCoverageWriteMappingVarNameToString(RustStringRef Str) {
|
||||
@ -81,5 +85,9 @@ extern "C" void LLVMRustCoverageWriteMappingVarNameToString(RustStringRef Str) {
|
||||
}
|
||||
|
||||
extern "C" uint32_t LLVMRustCoverageMappingVersion() {
|
||||
#if LLVM_VERSION_GE(11, 0)
|
||||
return coverage::CovMapVersion::Version4;
|
||||
#else
|
||||
report_fatal_error("rustc option `-Z instrument-coverage` requires LLVM 11 or higher.");
|
||||
#endif
|
||||
}
|
||||
|
@ -56,7 +56,14 @@ else
|
||||
-DINSTR_PROF_ORDERFILE='$(DATA_SECTION_PREFIX)__llvm_orderfile'
|
||||
endif
|
||||
|
||||
ifeq ($(LLVM_VERSION_11_PLUS),false)
|
||||
all: test_llvm_ir
|
||||
else
|
||||
$(info Rust option `-Z instrument-coverage` requires LLVM 11 or higher. Test skipped.)
|
||||
all:
|
||||
endif
|
||||
|
||||
test_llvm_ir:
|
||||
# Compile the test program with non-experimental coverage instrumentation, and generate LLVM IR
|
||||
#
|
||||
# Note: `-Clink-dead-code=no` disables the option, needed because the option is automatically
|
||||
@ -68,4 +75,5 @@ all:
|
||||
-Clink-dead-code=$(LINK_DEAD_CODE) \
|
||||
--emit=llvm-ir
|
||||
|
||||
cat "$(TMPDIR)"/testprog.ll | "$(LLVM_FILECHECK)" $(BASEDIR)/filecheck.testprog.txt $(LLVM_FILECHECK_OPTIONS)
|
||||
cat "$(TMPDIR)"/testprog.ll | \
|
||||
"$(LLVM_FILECHECK)" $(BASEDIR)/filecheck.testprog.txt $(LLVM_FILECHECK_OPTIONS)
|
||||
|
@ -18,7 +18,10 @@ SOURCEDIR=../coverage
|
||||
# `llvm/release_debuginfo`. Note that some CI builds disable debug assertions (by setting
|
||||
# `NO_LLVM_ASSERTIONS=1`), so it is not OK to fail the test, but `bless`ed test results cannot be
|
||||
# generated without debug assertions.
|
||||
LLVM_COV_DEBUG := $(shell "$(LLVM_BIN_DIR)"/llvm-cov show --debug 2>&1 | grep -q "Unknown command line argument '--debug'"; echo $$?)
|
||||
LLVM_COV_DEBUG := $(shell \
|
||||
"$(LLVM_BIN_DIR)"/llvm-cov show --debug 2>&1 | \
|
||||
grep -q "Unknown command line argument '--debug'"; \
|
||||
echo $$?)
|
||||
ifeq ($(LLVM_COV_DEBUG), 1)
|
||||
DEBUG_FLAG=--debug
|
||||
endif
|
||||
@ -30,7 +33,12 @@ ifdef RUSTC_BLESS_TEST
|
||||
DEBUG_FLAG=--debug
|
||||
endif
|
||||
|
||||
ifeq ($(LLVM_VERSION_11_PLUS),true)
|
||||
all: $(patsubst $(SOURCEDIR)/%.rs,%,$(wildcard $(SOURCEDIR)/*.rs))
|
||||
else
|
||||
$(info Rust option `-Z instrument-coverage` requires LLVM 11 or higher. Test skipped.)
|
||||
all:
|
||||
endif
|
||||
|
||||
# Ensure there are no `expected` results for tests that may have been removed or renamed
|
||||
.PHONY: clear_expected_if_blessed
|
||||
|
@ -24,7 +24,12 @@ For revisions in Pull Requests (PR):
|
||||
endef
|
||||
export SPANVIEW_HEADER
|
||||
|
||||
ifeq ($(LLVM_VERSION_11_PLUS),true)
|
||||
all: $(patsubst $(SOURCEDIR)/%.rs,%,$(wildcard $(SOURCEDIR)/*.rs))
|
||||
else
|
||||
$(info Rust option `-Z instrument-coverage` requires LLVM 11 or higher. Test skipped.)
|
||||
all:
|
||||
endif
|
||||
|
||||
# Ensure there are no `expected` results for tests that may have been removed or renamed
|
||||
.PHONY: clear_expected_if_blessed
|
||||
|
@ -38,6 +38,13 @@ endif
|
||||
|
||||
UNAME = $(shell uname)
|
||||
|
||||
# Rust option `-Z instrument-coverage` uses LLVM Coverage Mapping Format version 4,
|
||||
# which requires LLVM 11 or greater.
|
||||
LLVM_VERSION_11_PLUS := $(shell \
|
||||
LLVM_VERSION=$$("$(LLVM_BIN_DIR)"/llvm-config --version) && \
|
||||
LLVM_VERSION_MAJOR=$${LLVM_VERSION/.*/} && \
|
||||
[ $$LLVM_VERSION_MAJOR -ge 11 ] && echo true || echo false)
|
||||
|
||||
# FIXME(richkadel): Can any of the features tested by `run-make-fulldeps/coverage-*` tests be tested
|
||||
# just as completely by more focused unit tests of the code logic itself, to reduce the number of
|
||||
# test result files generated and maintained, and to help identify specific test failures and root
|
||||
|
Loading…
Reference in New Issue
Block a user