Skip to content

Commit 79c9f6e

Browse files
committed
Stop using as_c_char_ptr for coverage-related bindings
1 parent 9d82de1 commit 79c9f6e

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use std::ffi::CString;
44

5-
use crate::common::AsCCharPtr;
65
use crate::coverageinfo::ffi;
76
use crate::llvm;
87

@@ -34,7 +33,7 @@ pub(crate) fn create_pgo_func_name_var<'ll>(
3433
unsafe {
3534
llvm::LLVMRustCoverageCreatePGOFuncNameVar(
3635
llfn,
37-
mangled_fn_name.as_c_char_ptr(),
36+
mangled_fn_name.as_ptr(),
3837
mangled_fn_name.len(),
3938
)
4039
}
@@ -44,7 +43,7 @@ pub(crate) fn write_filenames_to_buffer(filenames: &[impl AsRef<str>]) -> Vec<u8
4443
let (pointers, lengths) = filenames
4544
.into_iter()
4645
.map(AsRef::as_ref)
47-
.map(|s: &str| (s.as_c_char_ptr(), s.len()))
46+
.map(|s: &str| (s.as_ptr(), s.len()))
4847
.unzip::<_, _, Vec<_>, Vec<_>>();
4948

5049
llvm::build_byte_buffer(|buffer| unsafe {
@@ -89,7 +88,7 @@ pub(crate) fn write_function_mappings_to_buffer(
8988
/// Hashes some bytes into a 64-bit hash, via LLVM's `IndexedInstrProf::ComputeHash`,
9089
/// as required for parts of the LLVM coverage mapping format.
9190
pub(crate) fn hash_bytes(bytes: &[u8]) -> u64 {
92-
unsafe { llvm::LLVMRustCoverageHashBytes(bytes.as_c_char_ptr(), bytes.len()) }
91+
unsafe { llvm::LLVMRustCoverageHashBytes(bytes.as_ptr(), bytes.len()) }
9392
}
9493

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

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,8 +2080,11 @@ unsafe extern "C" {
20802080
ConstraintsLen: size_t,
20812081
) -> bool;
20822082

2083+
/// A list of pointer-length strings is passed as two pointer-length slices,
2084+
/// one slice containing pointers and one slice containing their corresponding
2085+
/// lengths. The implementation will check that both slices have the same length.
20832086
pub(crate) fn LLVMRustCoverageWriteFilenamesToBuffer(
2084-
Filenames: *const *const c_char,
2087+
Filenames: *const *const c_uchar, // See "PTR_LEN_STR".
20852088
FilenamesLen: size_t,
20862089
Lengths: *const size_t,
20872090
LengthsLen: size_t,
@@ -2104,10 +2107,13 @@ unsafe extern "C" {
21042107

21052108
pub(crate) fn LLVMRustCoverageCreatePGOFuncNameVar(
21062109
F: &Value,
2107-
FuncName: *const c_char,
2110+
FuncName: *const c_uchar, // See "PTR_LEN_STR".
21082111
FuncNameLen: size_t,
21092112
) -> &Value;
2110-
pub(crate) fn LLVMRustCoverageHashBytes(Bytes: *const c_char, NumBytes: size_t) -> u64;
2113+
pub(crate) fn LLVMRustCoverageHashBytes(
2114+
Bytes: *const c_uchar, // See "PTR_LEN_STR".
2115+
NumBytes: size_t,
2116+
) -> u64;
21112117

21122118
pub(crate) fn LLVMRustCoverageWriteCovmapSectionNameToString(M: &Module, OutStr: &RustString);
21132119

0 commit comments

Comments
 (0)