Skip to content

Commit

Permalink
added SAFETY comment
Browse files Browse the repository at this point in the history
  • Loading branch information
mj10021 committed May 5, 2023
1 parent cb74cd5 commit f239cd6
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ pub(crate) fn print(req: PrintRequest, sess: &Session) {
let tm = create_informational_target_machine(sess);
match req {
PrintRequest::TargetCPUs => {
// SAFETY generate a C compatible string from a byte slice to pass
// the target CPU name into LLVM, the lifetime of the reference is
// at least as long as the C function
let cpu_cstring = CString::new(handle_native(sess.target.cpu.as_ref()))
.unwrap_or_else(|e| bug!("failed to convert to cstring: {}", e));
unsafe { llvm::LLVMRustPrintTargetCPUs(tm, cpu_cstring.as_ptr()) };
Expand Down

0 comments on commit f239cd6

Please sign in to comment.