Skip to content

Commit 19d5dc0

Browse files
committed
coverage: Tidy up coverage-specific FFI functions
1 parent b790e44 commit 19d5dc0

File tree

3 files changed

+52
-52
lines changed

3 files changed

+52
-52
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,27 @@
22
33
use std::ffi::CString;
44

5-
use libc::c_uint;
6-
75
use crate::common::AsCCharPtr;
86
use crate::coverageinfo::ffi;
97
use crate::llvm;
108

119
pub(crate) fn covmap_var_name() -> CString {
1210
CString::new(llvm::build_byte_buffer(|s| unsafe {
13-
llvm::LLVMRustCoverageWriteMappingVarNameToString(s);
11+
llvm::LLVMRustCoverageWriteCovmapVarNameToString(s);
1412
}))
1513
.expect("covmap variable name should not contain NUL")
1614
}
1715

1816
pub(crate) fn covmap_section_name(llmod: &llvm::Module) -> CString {
1917
CString::new(llvm::build_byte_buffer(|s| unsafe {
20-
llvm::LLVMRustCoverageWriteMapSectionNameToString(llmod, s);
18+
llvm::LLVMRustCoverageWriteCovmapSectionNameToString(llmod, s);
2119
}))
2220
.expect("covmap section name should not contain NUL")
2321
}
2422

2523
pub(crate) fn covfun_section_name(llmod: &llvm::Module) -> CString {
2624
CString::new(llvm::build_byte_buffer(|s| unsafe {
27-
llvm::LLVMRustCoverageWriteFuncSectionNameToString(llmod, s);
25+
llvm::LLVMRustCoverageWriteCovfunSectionNameToString(llmod, s);
2826
}))
2927
.expect("covfun section name should not contain NUL")
3028
}
@@ -51,7 +49,7 @@ pub(crate) fn write_filenames_to_buffer<'a>(
5149
.unzip::<_, _, Vec<_>, Vec<_>>();
5250

5351
llvm::build_byte_buffer(|buffer| unsafe {
54-
llvm::LLVMRustCoverageWriteFilenamesSectionToBuffer(
52+
llvm::LLVMRustCoverageWriteFilenamesToBuffer(
5553
pointers.as_ptr(),
5654
pointers.len(),
5755
lengths.as_ptr(),
@@ -70,19 +68,19 @@ pub(crate) fn write_function_mappings_to_buffer(
7068
mcdc_decision_regions: &[ffi::MCDCDecisionRegion],
7169
) -> Vec<u8> {
7270
llvm::build_byte_buffer(|buffer| unsafe {
73-
llvm::LLVMRustCoverageWriteMappingToBuffer(
71+
llvm::LLVMRustCoverageWriteFunctionMappingsToBuffer(
7472
virtual_file_mapping.as_ptr(),
75-
virtual_file_mapping.len() as c_uint,
73+
virtual_file_mapping.len(),
7674
expressions.as_ptr(),
77-
expressions.len() as c_uint,
75+
expressions.len(),
7876
code_regions.as_ptr(),
79-
code_regions.len() as c_uint,
77+
code_regions.len(),
8078
branch_regions.as_ptr(),
81-
branch_regions.len() as c_uint,
79+
branch_regions.len(),
8280
mcdc_branch_regions.as_ptr(),
83-
mcdc_branch_regions.len() as c_uint,
81+
mcdc_branch_regions.len(),
8482
mcdc_decision_regions.as_ptr(),
85-
mcdc_decision_regions.len() as c_uint,
83+
mcdc_decision_regions.len(),
8684
buffer,
8785
)
8886
})
@@ -91,7 +89,7 @@ pub(crate) fn write_function_mappings_to_buffer(
9189
/// Hashes some bytes into a 64-bit hash, via LLVM's `IndexedInstrProf::ComputeHash`,
9290
/// as required for parts of the LLVM coverage mapping format.
9391
pub(crate) fn hash_bytes(bytes: &[u8]) -> u64 {
94-
unsafe { llvm::LLVMRustCoverageHashByteArray(bytes.as_c_char_ptr(), bytes.len()) }
92+
unsafe { llvm::LLVMRustCoverageHashBytes(bytes.as_c_char_ptr(), bytes.len()) }
9593
}
9694

9795
/// Returns LLVM's `coverage::CovMapVersion::CurrentVersion` (CoverageMapping.h)

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@ unsafe extern "C" {
17901790
) -> bool;
17911791

17921792
#[allow(improper_ctypes)]
1793-
pub(crate) fn LLVMRustCoverageWriteFilenamesSectionToBuffer(
1793+
pub(crate) fn LLVMRustCoverageWriteFilenamesToBuffer(
17941794
Filenames: *const *const c_char,
17951795
FilenamesLen: size_t,
17961796
Lengths: *const size_t,
@@ -1799,19 +1799,19 @@ unsafe extern "C" {
17991799
);
18001800

18011801
#[allow(improper_ctypes)]
1802-
pub(crate) fn LLVMRustCoverageWriteMappingToBuffer(
1802+
pub(crate) fn LLVMRustCoverageWriteFunctionMappingsToBuffer(
18031803
VirtualFileMappingIDs: *const c_uint,
1804-
NumVirtualFileMappingIDs: c_uint,
1804+
NumVirtualFileMappingIDs: size_t,
18051805
Expressions: *const crate::coverageinfo::ffi::CounterExpression,
1806-
NumExpressions: c_uint,
1806+
NumExpressions: size_t,
18071807
CodeRegions: *const crate::coverageinfo::ffi::CodeRegion,
1808-
NumCodeRegions: c_uint,
1808+
NumCodeRegions: size_t,
18091809
BranchRegions: *const crate::coverageinfo::ffi::BranchRegion,
1810-
NumBranchRegions: c_uint,
1810+
NumBranchRegions: size_t,
18111811
MCDCBranchRegions: *const crate::coverageinfo::ffi::MCDCBranchRegion,
1812-
NumMCDCBranchRegions: c_uint,
1812+
NumMCDCBranchRegions: size_t,
18131813
MCDCDecisionRegions: *const crate::coverageinfo::ffi::MCDCDecisionRegion,
1814-
NumMCDCDecisionRegions: c_uint,
1814+
NumMCDCDecisionRegions: size_t,
18151815
BufferOut: &RustString,
18161816
);
18171817

@@ -1820,16 +1820,16 @@ unsafe extern "C" {
18201820
FuncName: *const c_char,
18211821
FuncNameLen: size_t,
18221822
) -> &Value;
1823-
pub(crate) fn LLVMRustCoverageHashByteArray(Bytes: *const c_char, NumBytes: size_t) -> u64;
1823+
pub(crate) fn LLVMRustCoverageHashBytes(Bytes: *const c_char, NumBytes: size_t) -> u64;
18241824

18251825
#[allow(improper_ctypes)]
1826-
pub(crate) fn LLVMRustCoverageWriteMapSectionNameToString(M: &Module, Str: &RustString);
1826+
pub(crate) fn LLVMRustCoverageWriteCovmapSectionNameToString(M: &Module, OutStr: &RustString);
18271827

18281828
#[allow(improper_ctypes)]
1829-
pub(crate) fn LLVMRustCoverageWriteFuncSectionNameToString(M: &Module, Str: &RustString);
1829+
pub(crate) fn LLVMRustCoverageWriteCovfunSectionNameToString(M: &Module, OutStr: &RustString);
18301830

18311831
#[allow(improper_ctypes)]
1832-
pub(crate) fn LLVMRustCoverageWriteMappingVarNameToString(Str: &RustString);
1832+
pub(crate) fn LLVMRustCoverageWriteCovmapVarNameToString(OutStr: &RustString);
18331833

18341834
pub(crate) fn LLVMRustCoverageMappingVersion() -> u32;
18351835
pub fn LLVMRustDebugMetadataVersion() -> u32;

compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp

+28-26
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ fromRust(LLVMRustCounterExprKind Kind) {
123123
report_fatal_error("Bad LLVMRustCounterExprKind!");
124124
}
125125

126-
extern "C" void LLVMRustCoverageWriteFilenamesSectionToBuffer(
126+
extern "C" void LLVMRustCoverageWriteFilenamesToBuffer(
127127
const char *const Filenames[], size_t FilenamesLen, // String start pointers
128128
const size_t *const Lengths, size_t LengthsLen, // Corresponding lengths
129129
RustStringRef BufferOut) {
130130
if (FilenamesLen != LengthsLen) {
131131
report_fatal_error(
132-
"Mismatched lengths in LLVMRustCoverageWriteFilenamesSectionToBuffer");
132+
"Mismatched lengths in LLVMRustCoverageWriteFilenamesToBuffer");
133133
}
134134

135135
SmallVector<std::string, 32> FilenameRefs;
@@ -143,16 +143,15 @@ extern "C" void LLVMRustCoverageWriteFilenamesSectionToBuffer(
143143
FilenamesWriter.write(OS);
144144
}
145145

146-
extern "C" void LLVMRustCoverageWriteMappingToBuffer(
147-
const unsigned *VirtualFileMappingIDs, unsigned NumVirtualFileMappingIDs,
148-
const LLVMRustCounterExpression *RustExpressions, unsigned NumExpressions,
149-
const LLVMRustCoverageCodeRegion *CodeRegions, unsigned NumCodeRegions,
150-
const LLVMRustCoverageBranchRegion *BranchRegions,
151-
unsigned NumBranchRegions,
146+
extern "C" void LLVMRustCoverageWriteFunctionMappingsToBuffer(
147+
const unsigned *VirtualFileMappingIDs, size_t NumVirtualFileMappingIDs,
148+
const LLVMRustCounterExpression *RustExpressions, size_t NumExpressions,
149+
const LLVMRustCoverageCodeRegion *CodeRegions, size_t NumCodeRegions,
150+
const LLVMRustCoverageBranchRegion *BranchRegions, size_t NumBranchRegions,
152151
const LLVMRustCoverageMCDCBranchRegion *MCDCBranchRegions,
153-
unsigned NumMCDCBranchRegions,
152+
size_t NumMCDCBranchRegions,
154153
const LLVMRustCoverageMCDCDecisionRegion *MCDCDecisionRegions,
155-
unsigned NumMCDCDecisionRegions, RustStringRef BufferOut) {
154+
size_t NumMCDCDecisionRegions, RustStringRef BufferOut) {
156155
// Convert from FFI representation to LLVM representation.
157156

158157
// Expressions:
@@ -219,34 +218,37 @@ LLVMRustCoverageCreatePGOFuncNameVar(LLVMValueRef F, const char *FuncName,
219218
return wrap(createPGOFuncNameVar(*cast<Function>(unwrap(F)), FuncNameRef));
220219
}
221220

222-
extern "C" uint64_t LLVMRustCoverageHashByteArray(const char *Bytes,
223-
size_t NumBytes) {
224-
auto StrRef = StringRef(Bytes, NumBytes);
225-
return IndexedInstrProf::ComputeHash(StrRef);
221+
extern "C" uint64_t LLVMRustCoverageHashBytes(const char *Bytes,
222+
size_t NumBytes) {
223+
return IndexedInstrProf::ComputeHash(StringRef(Bytes, NumBytes));
226224
}
227225

228-
static void WriteSectionNameToString(LLVMModuleRef M, InstrProfSectKind SK,
229-
RustStringRef Str) {
226+
// Private helper function for getting the covmap and covfun section names.
227+
static void writeInstrProfSectionNameToString(LLVMModuleRef M,
228+
InstrProfSectKind SectKind,
229+
RustStringRef OutStr) {
230230
auto TargetTriple = Triple(unwrap(M)->getTargetTriple());
231-
auto name = getInstrProfSectionName(SK, TargetTriple.getObjectFormat());
232-
auto OS = RawRustStringOstream(Str);
231+
auto name = getInstrProfSectionName(SectKind, TargetTriple.getObjectFormat());
232+
auto OS = RawRustStringOstream(OutStr);
233233
OS << name;
234234
}
235235

236-
extern "C" void LLVMRustCoverageWriteMapSectionNameToString(LLVMModuleRef M,
237-
RustStringRef Str) {
238-
WriteSectionNameToString(M, IPSK_covmap, Str);
236+
extern "C" void
237+
LLVMRustCoverageWriteCovmapSectionNameToString(LLVMModuleRef M,
238+
RustStringRef OutStr) {
239+
writeInstrProfSectionNameToString(M, IPSK_covmap, OutStr);
239240
}
240241

241242
extern "C" void
242-
LLVMRustCoverageWriteFuncSectionNameToString(LLVMModuleRef M,
243-
RustStringRef Str) {
244-
WriteSectionNameToString(M, IPSK_covfun, Str);
243+
LLVMRustCoverageWriteCovfunSectionNameToString(LLVMModuleRef M,
244+
RustStringRef OutStr) {
245+
writeInstrProfSectionNameToString(M, IPSK_covfun, OutStr);
245246
}
246247

247-
extern "C" void LLVMRustCoverageWriteMappingVarNameToString(RustStringRef Str) {
248+
extern "C" void
249+
LLVMRustCoverageWriteCovmapVarNameToString(RustStringRef OutStr) {
248250
auto name = getCoverageMappingVarName();
249-
auto OS = RawRustStringOstream(Str);
251+
auto OS = RawRustStringOstream(OutStr);
250252
OS << name;
251253
}
252254

0 commit comments

Comments
 (0)