Skip to content

Commit

Permalink
coverage. Disable supporting mcdc on llvm-18
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuUx committed Oct 8, 2024
1 parent 3ae715c commit 911ac56
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 54 deletions.
13 changes: 13 additions & 0 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,11 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
) {
debug!("mcdc_parameters() with args ({:?}, {:?}, {:?})", fn_name, hash, bitmap_bytes);

assert!(
crate::llvm_util::get_version() >= (19, 0, 0),
"MCDC intrinsics require LLVM 19 or later"
);

let llfn = unsafe { llvm::LLVMRustGetInstrProfMCDCParametersIntrinsic(self.cx().llmod) };
let llty = self.cx.type_func(
&[self.cx.type_ptr(), self.cx.type_i64(), self.cx.type_i32()],
Expand Down Expand Up @@ -1716,6 +1721,10 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
"mcdc_tvbitmap_update() with args ({:?}, {:?}, {:?}, {:?}, {:?})",
fn_name, hash, bitmap_bytes, bitmap_index, mcdc_temp
);
assert!(
crate::llvm_util::get_version() >= (19, 0, 0),
"MCDC intrinsics require LLVM 19 or later"
);

let llfn =
unsafe { llvm::LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(self.cx().llmod) };
Expand Down Expand Up @@ -1757,6 +1766,10 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
"mcdc_condbitmap_update() with args ({:?}, {:?}, {:?}, {:?}, {:?})",
fn_name, hash, cond_loc, mcdc_temp, bool_value
);
assert!(
crate::llvm_util::get_version() >= (19, 0, 0),
"MCDC intrinsics require LLVM 19 or later"
);
let llfn = unsafe { llvm::LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(self.cx().llmod) };
let llty = self.cx.type_func(
&[
Expand Down
45 changes: 9 additions & 36 deletions compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,38 +88,7 @@ struct LLVMRustMCDCParameters {
LLVMRustMCDCBranchParameters BranchParameters;
};

// LLVM representations for `MCDCParameters` evolved from LLVM 18 to 19.
// Look at representations in 18
// https://github.com/rust-lang/llvm-project/blob/66a2881a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L253-L263
// and representations in 19
// https://github.com/llvm/llvm-project/blob/843cc474faefad1d639f4c44c1cf3ad7dbda76c8/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h
#if LLVM_VERSION_LT(19, 0)
static coverage::CounterMappingRegion::MCDCParameters
fromRust(LLVMRustMCDCParameters Params) {
auto parameter = coverage::CounterMappingRegion::MCDCParameters{};
switch (Params.Tag) {
case LLVMRustMCDCParametersTag::None:
return parameter;
case LLVMRustMCDCParametersTag::Decision:
parameter.BitmapIdx =
static_cast<unsigned>(Params.DecisionParameters.BitmapIdx),
parameter.NumConditions =
static_cast<unsigned>(Params.DecisionParameters.NumConditions);
return parameter;
case LLVMRustMCDCParametersTag::Branch:
parameter.ID = static_cast<coverage::CounterMappingRegion::MCDCConditionID>(
Params.BranchParameters.ConditionID),
parameter.FalseID =
static_cast<coverage::CounterMappingRegion::MCDCConditionID>(
Params.BranchParameters.ConditionIDs[0]),
parameter.TrueID =
static_cast<coverage::CounterMappingRegion::MCDCConditionID>(
Params.BranchParameters.ConditionIDs[1]);
return parameter;
}
report_fatal_error("Bad LLVMRustMCDCParametersTag!");
}
#else
#if LLVM_VERSION_GE(19, 0)
static coverage::mcdc::Parameters fromRust(LLVMRustMCDCParameters Params) {
switch (Params.Tag) {
case LLVMRustMCDCParametersTag::None:
Expand Down Expand Up @@ -214,13 +183,17 @@ extern "C" void LLVMRustCoverageWriteMappingToBuffer(
RustMappingRegions, NumMappingRegions)) {
MappingRegions.emplace_back(
fromRust(Region.Count), fromRust(Region.FalseCount),
#if LLVM_VERSION_LT(19, 0)
// LLVM 19 may move this argument to last.
fromRust(Region.MCDCParameters),
#if LLVM_VERSION_GE(18, 0) && LLVM_VERSION_LT(19, 0)
coverage::CounterMappingRegion::MCDCParameters{},
#endif
Region.FileID, Region.ExpandedFileID, // File IDs, then region info.
Region.LineStart, Region.ColumnStart, Region.LineEnd, Region.ColumnEnd,
fromRust(Region.Kind));
fromRust(Region.Kind)
#if LLVM_VERSION_GE(19, 0)
,
fromRust(Region.MCDCParameters)
#endif
);
}

std::vector<coverage::CounterExpression> Expressions;
Expand Down
14 changes: 6 additions & 8 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1539,23 +1539,21 @@ LLVMRustGetInstrProfIncrementIntrinsic(LLVMModuleRef M) {

extern "C" LLVMValueRef
LLVMRustGetInstrProfMCDCParametersIntrinsic(LLVMModuleRef M) {
#if LLVM_VERSION_GE(19, 0)
return wrap(llvm::Intrinsic::getDeclaration(
unwrap(M), llvm::Intrinsic::instrprof_mcdc_parameters));
#else
report_fatal_error("LLVM 19.0 is required for mcdc intrinsic functions");
#endif
}

extern "C" LLVMValueRef
LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(LLVMModuleRef M) {
#if LLVM_VERSION_GE(19, 0)
return wrap(llvm::Intrinsic::getDeclaration(
unwrap(M), llvm::Intrinsic::instrprof_mcdc_tvbitmap_update));
}

extern "C" LLVMValueRef
LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(LLVMModuleRef M) {
#if LLVM_VERSION_LT(19, 0)
return wrap(llvm::Intrinsic::getDeclaration(
unwrap(M), llvm::Intrinsic::instrprof_mcdc_condbitmap_update));
#else
report_fatal_error("LLVM 18.0 is required for mcdc intrinsic functions");
report_fatal_error("LLVM 19.0 is required for mcdc intrinsic functions");
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion tests/coverage/mcdc/condition-limit.coverage
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ ignore-llvm-version: 19 - 99
LL| |//@ min-llvm-version: 19
LL| |//@ compile-flags: -Zcoverage-options=mcdc
LL| |//@ llvm-cov-flags: --show-branches=count --show-mcdc
LL| |
Expand Down
2 changes: 1 addition & 1 deletion tests/coverage/mcdc/condition-limit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ ignore-llvm-version: 19 - 99
//@ min-llvm-version: 19
//@ compile-flags: -Zcoverage-options=mcdc
//@ llvm-cov-flags: --show-branches=count --show-mcdc

Expand Down
2 changes: 1 addition & 1 deletion tests/coverage/mcdc/if.coverage
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ ignore-llvm-version: 19 - 99
LL| |//@ min-llvm-version: 19
LL| |//@ compile-flags: -Zcoverage-options=mcdc
LL| |//@ llvm-cov-flags: --show-branches=count --show-mcdc
LL| |
Expand Down
2 changes: 1 addition & 1 deletion tests/coverage/mcdc/if.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ ignore-llvm-version: 19 - 99
//@ min-llvm-version: 19
//@ compile-flags: -Zcoverage-options=mcdc
//@ llvm-cov-flags: --show-branches=count --show-mcdc

Expand Down
2 changes: 1 addition & 1 deletion tests/coverage/mcdc/inlined_expressions.coverage
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ ignore-llvm-version: 19 - 99
LL| |//@ min-llvm-version: 19
LL| |//@ compile-flags: -Zcoverage-options=mcdc -Copt-level=z -Cllvm-args=--inline-threshold=0
LL| |//@ llvm-cov-flags: --show-branches=count --show-mcdc
LL| |
Expand Down
2 changes: 1 addition & 1 deletion tests/coverage/mcdc/inlined_expressions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ ignore-llvm-version: 19 - 99
//@ min-llvm-version: 19
//@ compile-flags: -Zcoverage-options=mcdc -Copt-level=z -Cllvm-args=--inline-threshold=0
//@ llvm-cov-flags: --show-branches=count --show-mcdc

Expand Down
2 changes: 1 addition & 1 deletion tests/coverage/mcdc/nested_if.coverage
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ ignore-llvm-version: 19 - 99
LL| |//@ min-llvm-version: 19
LL| |//@ compile-flags: -Zcoverage-options=mcdc
LL| |//@ llvm-cov-flags: --show-branches=count --show-mcdc
LL| |
Expand Down
2 changes: 1 addition & 1 deletion tests/coverage/mcdc/nested_if.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ ignore-llvm-version: 19 - 99
//@ min-llvm-version: 19
//@ compile-flags: -Zcoverage-options=mcdc
//@ llvm-cov-flags: --show-branches=count --show-mcdc

Expand Down
2 changes: 1 addition & 1 deletion tests/coverage/mcdc/non_control_flow.coverage
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
LL| |#![feature(coverage_attribute)]
LL| |//@ edition: 2021
LL| |//@ ignore-llvm-version: 19 - 99
LL| |//@ min-llvm-version: 19
LL| |//@ compile-flags: -Zcoverage-options=mcdc
LL| |//@ llvm-cov-flags: --show-branches=count --show-mcdc
LL| |
Expand Down
2 changes: 1 addition & 1 deletion tests/coverage/mcdc/non_control_flow.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(coverage_attribute)]
//@ edition: 2021
//@ ignore-llvm-version: 19 - 99
//@ min-llvm-version: 19
//@ compile-flags: -Zcoverage-options=mcdc
//@ llvm-cov-flags: --show-branches=count --show-mcdc

Expand Down

0 comments on commit 911ac56

Please sign in to comment.