@@ -14,7 +14,7 @@ use rustc_data_structures::small_c_str::SmallCStr;
1414use rustc_fs_util:: path_to_c_string;
1515use rustc_middle:: bug;
1616use rustc_session:: Session ;
17- use rustc_session:: config:: { PrintKind , PrintRequest } ;
17+ use rustc_session:: config:: { NATIVE_CPU , PrintKind , PrintRequest } ;
1818use rustc_target:: spec:: {
1919 Arch , CfgAbi , Env , MergeFunctions , Os , PanicStrategy , SmallDataThresholdSupport ,
2020} ;
@@ -514,10 +514,12 @@ fn print_target_cpus(sess: &Session, tm: &llvm::TargetMachine, out: &mut String)
514514
515515 // Only print the "native" entry when host and target are the same arch,
516516 // since otherwise it could be wrong or misleading.
517- if sess. host . arch == sess. target . arch {
517+ // Also do not print it if `requires_consistent_cpu` is set, because in this case
518+ // "native" would be rejected.
519+ if sess. host . arch == sess. target . arch && !sess. target . requires_consistent_cpu {
518520 let host = get_host_cpu_name ( ) ;
519521 cpus. push_front ( Cpu {
520- cpu_name : "native" ,
522+ cpu_name : NATIVE_CPU ,
521523 remark : format ! ( " - Select the CPU of the current host (currently {host})." ) ,
522524 } ) ;
523525 }
@@ -612,7 +614,7 @@ fn get_host_cpu_name() -> &'static str {
612614/// LLVM. Otherwise, the string is returned as-is.
613615fn handle_native ( cpu_name : & str ) -> & str {
614616 match cpu_name {
615- "native" => get_host_cpu_name ( ) ,
617+ NATIVE_CPU => get_host_cpu_name ( ) ,
616618 _ => cpu_name,
617619 }
618620}
@@ -666,7 +668,7 @@ pub(crate) fn global_llvm_features(sess: &Session, only_base_features: bool) ->
666668
667669 // -Ctarget-cpu=native
668670 match sess. opts . cg . target_cpu {
669- Some ( ref s) if s == "native" => {
671+ Some ( ref s) if s == NATIVE_CPU => {
670672 // We have already figured out the actual CPU name with `LLVMRustGetHostCPUName` and set
671673 // that for LLVM, so the features implied by that CPU name will be available everywhere.
672674 // However, that is not sufficient: e.g. `skylake` alone is not sufficient to tell if
0 commit comments