Skip to content

Commit 352d031

Browse files
committed
Remove LLVMRustCoverageHashCString
Coverage has two FFI functions for computing the hash of a byte string. One takes a ptr/len pair, and the other takes a NUL-terminated C string. But on closer inspection, the C string version is unnecessary. The calling-side code converts a Rust `&str` into a C string, and the C++ code then immediately turns it back into a ptr/len string before actually hashing it.
1 parent 7292608 commit 352d031

File tree

4 files changed

+1
-12
lines changed

4 files changed

+1
-12
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn save_function_record(
238238
let coverage_mapping_size = coverage_mapping_buffer.len();
239239
let coverage_mapping_val = cx.const_bytes(&coverage_mapping_buffer);
240240

241-
let func_name_hash = coverageinfo::hash_str(mangled_function_name);
241+
let func_name_hash = coverageinfo::hash_bytes(mangled_function_name.as_bytes());
242242
let func_name_hash_val = cx.const_u64(func_name_hash);
243243
let coverage_mapping_size_val = cx.const_u32(coverage_mapping_size as u32);
244244
let source_hash_val = cx.const_u64(source_hash);

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,6 @@ pub(crate) fn write_mapping_to_buffer(
373373
}
374374
}
375375

376-
pub(crate) fn hash_str(strval: &str) -> u64 {
377-
let strval = CString::new(strval).expect("null error converting hashable str to C string");
378-
unsafe { llvm::LLVMRustCoverageHashCString(strval.as_ptr()) }
379-
}
380-
381376
pub(crate) fn hash_bytes(bytes: &[u8]) -> u64 {
382377
unsafe { llvm::LLVMRustCoverageHashByteArray(bytes.as_ptr().cast(), bytes.len()) }
383378
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,6 @@ extern "C" {
19161916
);
19171917

19181918
pub fn LLVMRustCoverageCreatePGOFuncNameVar(F: &Value, FuncName: *const c_char) -> &Value;
1919-
pub fn LLVMRustCoverageHashCString(StrVal: *const c_char) -> u64;
19201919
pub fn LLVMRustCoverageHashByteArray(Bytes: *const c_char, NumBytes: size_t) -> u64;
19211920

19221921
#[allow(improper_ctypes)]

compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,6 @@ extern "C" LLVMValueRef LLVMRustCoverageCreatePGOFuncNameVar(LLVMValueRef F, con
158158
return wrap(createPGOFuncNameVar(*cast<Function>(unwrap(F)), FuncNameRef));
159159
}
160160

161-
extern "C" uint64_t LLVMRustCoverageHashCString(const char *StrVal) {
162-
StringRef StrRef(StrVal);
163-
return IndexedInstrProf::ComputeHash(StrRef);
164-
}
165-
166161
extern "C" uint64_t LLVMRustCoverageHashByteArray(
167162
const char *Bytes,
168163
size_t NumBytes) {

0 commit comments

Comments
 (0)