Fix warnings about the native
target-cpu
This fixes a regression from #53031 where specifying `-C target-cpu=native` is printing a lot of warnings from LLVM about `native` being an unknown CPU. It turns out that `native` is indeed an unknown CPU and we have to perform a mapping to an actual CPU name, but this mapping is only performed in one location rather than all locations we inform LLVM about the target CPU. This commit centralizes the mapping of `native` to LLVM's value of the native CPU, ensuring that all locations we inform LLVM about the `target-cpu` it's never `native`. Closes #53322
This commit is contained in:
parent
7061b27757
commit
1fd45a13de
8 changed files with 49 additions and 18 deletions
|
@ -17,6 +17,8 @@ use libc::c_int;
|
|||
use std::ffi::CString;
|
||||
use syntax::feature_gate::UnstableFeatures;
|
||||
|
||||
use std::str;
|
||||
use std::slice;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Once;
|
||||
|
||||
|
@ -262,3 +264,19 @@ pub(crate) fn print(req: PrintRequest, sess: &Session) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn target_cpu(sess: &Session) -> &str {
|
||||
let name = match sess.opts.cg.target_cpu {
|
||||
Some(ref s) => &**s,
|
||||
None => &*sess.target.target.options.cpu
|
||||
};
|
||||
if name != "native" {
|
||||
return name
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let mut len = 0;
|
||||
let ptr = llvm::LLVMRustGetHostCPUName(&mut len);
|
||||
str::from_utf8(slice::from_raw_parts(ptr as *const u8, len)).unwrap()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue