Skip to content

Commit f239cd6

Browse files
committed
added SAFETY comment
1 parent cb74cd5 commit f239cd6

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+3
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ pub(crate) fn print(req: PrintRequest, sess: &Session) {
330330
let tm = create_informational_target_machine(sess);
331331
match req {
332332
PrintRequest::TargetCPUs => {
333+
// SAFETY generate a C compatible string from a byte slice to pass
334+
// the target CPU name into LLVM, the lifetime of the reference is
335+
// at least as long as the C function
333336
let cpu_cstring = CString::new(handle_native(sess.target.cpu.as_ref()))
334337
.unwrap_or_else(|e| bug!("failed to convert to cstring: {}", e));
335338
unsafe { llvm::LLVMRustPrintTargetCPUs(tm, cpu_cstring.as_ptr()) };

0 commit comments

Comments
 (0)