coverage: Don't convert symbol names to CString
for FFI
This commit is contained in:
parent
e184118683
commit
4b154bc8e2
3 changed files with 18 additions and 7 deletions
|
@ -25,7 +25,6 @@ use rustc_middle::ty::Instance;
|
||||||
use rustc_middle::ty::Ty;
|
use rustc_middle::ty::Ty;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::ffi::CString;
|
|
||||||
|
|
||||||
pub(crate) mod ffi;
|
pub(crate) mod ffi;
|
||||||
pub(crate) mod map_data;
|
pub(crate) mod map_data;
|
||||||
|
@ -332,10 +331,15 @@ fn create_pgo_func_name_var<'ll, 'tcx>(
|
||||||
cx: &CodegenCx<'ll, 'tcx>,
|
cx: &CodegenCx<'ll, 'tcx>,
|
||||||
instance: Instance<'tcx>,
|
instance: Instance<'tcx>,
|
||||||
) -> &'ll llvm::Value {
|
) -> &'ll llvm::Value {
|
||||||
let mangled_fn_name = CString::new(cx.tcx.symbol_name(instance).name)
|
let mangled_fn_name: &str = cx.tcx.symbol_name(instance).name;
|
||||||
.expect("error converting function name to C string");
|
|
||||||
let llfn = cx.get_fn(instance);
|
let llfn = cx.get_fn(instance);
|
||||||
unsafe { llvm::LLVMRustCoverageCreatePGOFuncNameVar(llfn, mangled_fn_name.as_ptr()) }
|
unsafe {
|
||||||
|
llvm::LLVMRustCoverageCreatePGOFuncNameVar(
|
||||||
|
llfn,
|
||||||
|
mangled_fn_name.as_ptr().cast(),
|
||||||
|
mangled_fn_name.len(),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn write_filenames_section_to_buffer<'a>(
|
pub(crate) fn write_filenames_section_to_buffer<'a>(
|
||||||
|
|
|
@ -1720,7 +1720,11 @@ extern "C" {
|
||||||
BufferOut: &RustString,
|
BufferOut: &RustString,
|
||||||
);
|
);
|
||||||
|
|
||||||
pub fn LLVMRustCoverageCreatePGOFuncNameVar(F: &Value, FuncName: *const c_char) -> &Value;
|
pub fn LLVMRustCoverageCreatePGOFuncNameVar(
|
||||||
|
F: &Value,
|
||||||
|
FuncName: *const c_char,
|
||||||
|
FuncNameLen: size_t,
|
||||||
|
) -> &Value;
|
||||||
pub fn LLVMRustCoverageHashByteArray(Bytes: *const c_char, NumBytes: size_t) -> u64;
|
pub fn LLVMRustCoverageHashByteArray(Bytes: *const c_char, NumBytes: size_t) -> u64;
|
||||||
|
|
||||||
#[allow(improper_ctypes)]
|
#[allow(improper_ctypes)]
|
||||||
|
|
|
@ -161,8 +161,11 @@ extern "C" void LLVMRustCoverageWriteMappingToBuffer(
|
||||||
CoverageMappingWriter.write(OS);
|
CoverageMappingWriter.write(OS);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" LLVMValueRef LLVMRustCoverageCreatePGOFuncNameVar(LLVMValueRef F, const char *FuncName) {
|
extern "C" LLVMValueRef LLVMRustCoverageCreatePGOFuncNameVar(
|
||||||
StringRef FuncNameRef(FuncName);
|
LLVMValueRef F,
|
||||||
|
const char *FuncName,
|
||||||
|
size_t FuncNameLen) {
|
||||||
|
StringRef FuncNameRef(FuncName, FuncNameLen);
|
||||||
return wrap(createPGOFuncNameVar(*cast<Function>(unwrap(F)), FuncNameRef));
|
return wrap(createPGOFuncNameVar(*cast<Function>(unwrap(F)), FuncNameRef));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue