File tree 7 files changed +41
-0
lines changed
tests/run-make/target-specs
7 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ codegen_ssa_copy_path = could not copy {$from} to {$to}: {$error}
30
30
31
31
codegen_ssa_copy_path_buf = unable to copy { $source_file } to { $output_path } : { $error }
32
32
33
+ codegen_ssa_cpu_required = target requires explicitly specifying a cpu with `-C target-cpu`
34
+
33
35
codegen_ssa_create_temp_dir = couldn't create a temp dir: { $error }
34
36
35
37
codegen_ssa_dlltool_fail_import_library =
Original file line number Diff line number Diff line change @@ -615,6 +615,11 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
615
615
return ongoing_codegen;
616
616
}
617
617
618
+ if tcx. sess . target . need_explicit_cpu && tcx. sess . opts . cg . target_cpu . is_none ( ) {
619
+ // The target has no default cpu, but none is set explicitly
620
+ tcx. dcx ( ) . emit_fatal ( errors:: CpuRequired ) ;
621
+ }
622
+
618
623
let cgu_name_builder = & mut CodegenUnitNameBuilder :: new ( tcx) ;
619
624
620
625
// Run the monomorphization collector and partition the collected items into
Original file line number Diff line number Diff line change @@ -523,6 +523,10 @@ pub(crate) struct CheckInstalledVisualStudio;
523
523
#[ diag( codegen_ssa_insufficient_vs_code_product) ]
524
524
pub ( crate ) struct InsufficientVSCodeProduct ;
525
525
526
+ #[ derive( Diagnostic ) ]
527
+ #[ diag( codegen_ssa_cpu_required) ]
528
+ pub ( crate ) struct CpuRequired ;
529
+
526
530
#[ derive( Diagnostic ) ]
527
531
#[ diag( codegen_ssa_processing_dymutil_failed) ]
528
532
#[ note]
Original file line number Diff line number Diff line change @@ -546,6 +546,7 @@ impl Target {
546
546
key ! ( link_env_remove, list) ;
547
547
key ! ( asm_args, list) ;
548
548
key ! ( cpu) ;
549
+ key ! ( need_explicit_cpu, bool ) ;
549
550
key ! ( features) ;
550
551
key ! ( dynamic_linking, bool ) ;
551
552
key ! ( direct_access_external_data, Option <bool >) ;
@@ -720,6 +721,7 @@ impl ToJson for Target {
720
721
target_option_val ! ( link_env_remove) ;
721
722
target_option_val ! ( asm_args) ;
722
723
target_option_val ! ( cpu) ;
724
+ target_option_val ! ( need_explicit_cpu) ;
723
725
target_option_val ! ( features) ;
724
726
target_option_val ! ( dynamic_linking) ;
725
727
target_option_val ! ( direct_access_external_data) ;
Original file line number Diff line number Diff line change @@ -2254,6 +2254,9 @@ pub struct TargetOptions {
2254
2254
/// Default CPU to pass to LLVM. Corresponds to `llc -mcpu=$cpu`. Defaults
2255
2255
/// to "generic".
2256
2256
pub cpu : StaticCow < str > ,
2257
+ /// Whether a cpu needs to be explicitly set.
2258
+ /// Set to true if there is no default cpu. Defaults to false.
2259
+ pub need_explicit_cpu : bool ,
2257
2260
/// Default target features to pass to LLVM. These features overwrite
2258
2261
/// `-Ctarget-cpu` but can be overwritten with `-Ctarget-features`.
2259
2262
/// Corresponds to `llc -mattr=$features`.
@@ -2686,6 +2689,7 @@ impl Default for TargetOptions {
2686
2689
link_script : None ,
2687
2690
asm_args : cvs ! [ ] ,
2688
2691
cpu : "generic" . into ( ) ,
2692
+ need_explicit_cpu : false ,
2689
2693
features : "" . into ( ) ,
2690
2694
direct_access_external_data : None ,
2691
2695
dynamic_linking : false ,
Original file line number Diff line number Diff line change
1
+ {
2
+ "data-layout" : " e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i128:128-f64:32:64-f80:32-n8:16:32-S128" ,
3
+ "linker-flavor" : " gcc" ,
4
+ "llvm-target" : " i686-unknown-linux-gnu" ,
5
+ "target-endian" : " little" ,
6
+ "target-pointer-width" : " 32" ,
7
+ "target-c-int-width" : " 32" ,
8
+ "arch" : " x86" ,
9
+ "os" : " linux" ,
10
+ "need-explicit-cpu" : true
11
+ }
Original file line number Diff line number Diff line change @@ -63,4 +63,17 @@ fn main() {
63
63
. crate_type ( "lib" )
64
64
. run_fail ( )
65
65
. assert_stderr_contains ( "data-layout for target" ) ;
66
+ rustc ( )
67
+ . input ( "foo.rs" )
68
+ . target ( "require-explicit-cpu" )
69
+ . crate_type ( "lib" )
70
+ . run_fail ( )
71
+ . assert_stderr_contains ( "target requires explicitly specifying a cpu" ) ;
72
+ rustc ( )
73
+ . input ( "foo.rs" )
74
+ . target ( "require-explicit-cpu" )
75
+ . crate_type ( "lib" )
76
+ . arg ( "-Ctarget-cpu=generic" )
77
+ . run ( ) ;
78
+ rustc ( ) . target ( "require-explicit-cpu" ) . arg ( "--print=target-cpus" ) . run ( ) ;
66
79
}
You can’t perform that action at this time.
0 commit comments