Skip to content

Commit 58f62e8

Browse files
author
zhuyunxing
committed
coverage. Allow to be compiled on llvm-17
1 parent 2c054b0 commit 58f62e8

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
12461246
) -> &'ll Value {
12471247
debug!("mcdc_parameters() with args ({:?}, {:?}, {:?})", fn_name, hash, bitmap_bytes);
12481248

1249+
assert!(llvm_util::get_version() >= (18, 0, 0), "MCDC intrinsics require LLVM 18 or later");
1250+
12491251
let llfn = unsafe { llvm::LLVMRustGetInstrProfMCDCParametersIntrinsic(self.cx().llmod) };
12501252
let llty = self.cx.type_func(
12511253
&[self.cx.type_ptr(), self.cx.type_i64(), self.cx.type_i32()],
@@ -1290,6 +1292,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
12901292
"mcdc_tvbitmap_update() with args ({:?}, {:?}, {:?}, {:?}, {:?})",
12911293
fn_name, hash, bitmap_bytes, bitmap_index, mcdc_temp
12921294
);
1295+
assert!(llvm_util::get_version() >= (18, 0, 0), "MCDC intrinsics require LLVM 18 or later");
12931296

12941297
let llfn =
12951298
unsafe { llvm::LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(self.cx().llmod) };
@@ -1326,6 +1329,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
13261329
mcdc_temp: Self::Value,
13271330
bool_value: Self::Value,
13281331
) {
1332+
debug!(
1333+
"mcdc_condbitmap_update() with args ({:?}, {:?}, {:?}, {:?}, {:?})",
1334+
fn_name, hash, cond_loc, mcdc_temp, bool_value
1335+
);
1336+
assert!(llvm_util::get_version() >= (18, 0, 0), "MCDC intrinsics require LLVM 18 or later");
13291337
let llfn = unsafe { llvm::LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(self.cx().llmod) };
13301338
let llty = self.cx.type_func(
13311339
&[

compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,17 @@ fromRust(LLVMRustCounterMappingRegionKind Kind) {
5858
return coverage::CounterMappingRegion::GapRegion;
5959
case LLVMRustCounterMappingRegionKind::BranchRegion:
6060
return coverage::CounterMappingRegion::BranchRegion;
61+
#if LLVM_VERSION_GE(18, 0)
6162
case LLVMRustCounterMappingRegionKind::MCDCDecisionRegion:
6263
return coverage::CounterMappingRegion::MCDCDecisionRegion;
6364
case LLVMRustCounterMappingRegionKind::MCDCBranchRegion:
6465
return coverage::CounterMappingRegion::MCDCBranchRegion;
66+
#else
67+
case LLVMRustCounterMappingRegionKind::MCDCDecisionRegion:
68+
break;
69+
case LLVMRustCounterMappingRegionKind::MCDCBranchRegion:
70+
break;
71+
#endif
6572
}
6673
report_fatal_error("Bad LLVMRustCounterMappingRegionKind!");
6774
}

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "llvm/Bitcode/BitcodeWriter.h"
2424
#include "llvm/Support/Signals.h"
2525

26+
#include <cassert>
2627
#include <iostream>
2728

2829
// for raw `write` in the bad-alloc handler
@@ -1529,18 +1530,33 @@ extern "C" LLVMValueRef LLVMRustGetInstrProfIncrementIntrinsic(LLVMModuleRef M)
15291530
}
15301531

15311532
extern "C" LLVMValueRef LLVMRustGetInstrProfMCDCParametersIntrinsic(LLVMModuleRef M) {
1533+
assert(LLVM_VERSION_GE(18, 0));
1534+
#if LLVM_VERSION_GE(18, 0)
15321535
return wrap(llvm::Intrinsic::getDeclaration(unwrap(M),
15331536
(llvm::Intrinsic::ID)llvm::Intrinsic::instrprof_mcdc_parameters));
1537+
#else // Just make the wrapper can be compiled
1538+
return LLVMRustGetInstrProfIncrementIntrinsic(M);
1539+
#endif
15341540
}
15351541

15361542
extern "C" LLVMValueRef LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(LLVMModuleRef M) {
1537-
return wrap(llvm::Intrinsic::getDeclaration(unwrap(M),
1538-
(llvm::Intrinsic::ID)llvm::Intrinsic::instrprof_mcdc_tvbitmap_update));
1543+
assert(LLVM_VERSION_GE(18, 0));
1544+
#if LLVM_VERSION_GE(18, 0)
1545+
return wrap(llvm::Intrinsic::getDeclaration(
1546+
unwrap(M), llvm::Intrinsic::instrprof_mcdc_tvbitmap_update));
1547+
#else // Just make the wrapper can be compiled
1548+
return LLVMRustGetInstrProfIncrementIntrinsic(M);
1549+
#endif
15391550
}
15401551

15411552
extern "C" LLVMValueRef LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(LLVMModuleRef M) {
1542-
return wrap(llvm::Intrinsic::getDeclaration(unwrap(M),
1543-
(llvm::Intrinsic::ID)llvm::Intrinsic::instrprof_mcdc_condbitmap_update));
1553+
assert(LLVM_VERSION_GE(18, 0));
1554+
#if LLVM_VERSION_GE(18, 0)
1555+
return wrap(llvm::Intrinsic::getDeclaration(
1556+
unwrap(M), llvm::Intrinsic::instrprof_mcdc_condbitmap_update));
1557+
#else // Just make the wrapper can be compiled
1558+
return LLVMRustGetInstrProfIncrementIntrinsic(M);
1559+
#endif
15441560
}
15451561

15461562
extern "C" LLVMValueRef LLVMRustBuildMemCpy(LLVMBuilderRef B,

0 commit comments

Comments
 (0)