@@ -552,9 +552,10 @@ impl<'test> TestCx<'test> {
552
552
. args ( & [ "--target" , & self . config . target ] )
553
553
. arg ( "-L" )
554
554
. arg ( & aux_dir)
555
- . args ( self . split_maybe_args ( & self . config . target_rustcflags ) )
556
555
. args ( & self . props . compile_flags )
557
556
. envs ( self . props . exec_env . clone ( ) ) ;
557
+ self . maybe_add_external_args ( & mut rustc,
558
+ self . split_maybe_args ( & self . config . target_rustcflags ) ) ;
558
559
559
560
let src = match read_from {
560
561
ReadFrom :: Stdin ( src) => Some ( src) ,
@@ -587,6 +588,15 @@ impl<'test> TestCx<'test> {
587
588
}
588
589
}
589
590
591
+ fn set_revision_flags ( & self , cmd : & mut Command ) {
592
+ if let Some ( revision) = self . revision {
593
+ // Normalize revisions to be lowercase and replace `-`s with `_`s.
594
+ // Otherwise the `--cfg` flag is not valid.
595
+ let normalized_revision = revision. to_lowercase ( ) . replace ( "-" , "_" ) ;
596
+ cmd. args ( & [ "--cfg" , & normalized_revision] ) ;
597
+ }
598
+ }
599
+
590
600
fn typecheck_source ( & self , src : String ) -> ProcRes {
591
601
let mut rustc = Command :: new ( & self . config . rustc_path ) ;
592
602
@@ -612,12 +622,9 @@ impl<'test> TestCx<'test> {
612
622
. arg ( & self . config . build_base )
613
623
. arg ( "-L" )
614
624
. arg ( aux_dir) ;
615
-
616
- if let Some ( revision) = self . revision {
617
- rustc. args ( & [ "--cfg" , revision] ) ;
618
- }
619
-
620
- rustc. args ( self . split_maybe_args ( & self . config . target_rustcflags ) ) ;
625
+ self . set_revision_flags ( & mut rustc) ;
626
+ self . maybe_add_external_args ( & mut rustc,
627
+ self . split_maybe_args ( & self . config . target_rustcflags ) ) ;
621
628
rustc. args ( & self . props . compile_flags ) ;
622
629
623
630
self . compose_and_run_compiler ( rustc, Some ( src) )
@@ -1119,6 +1126,35 @@ impl<'test> TestCx<'test> {
1119
1126
Some ( new_options. join ( " " ) )
1120
1127
}
1121
1128
1129
+ fn maybe_add_external_args ( & self , cmd : & mut Command , args : Vec < String > ) {
1130
+ // Filter out the arguments that should not be added by runtest here.
1131
+ //
1132
+ // Notable use-cases are: do not add our optimisation flag if
1133
+ // `compile-flags: -Copt-level=x` and similar for debug-info level as well.
1134
+ const OPT_FLAGS : & [ & str ] = & [ "-O" , "-Copt-level=" , /*-C<space>*/ "opt-level=" ] ;
1135
+ const DEBUG_FLAGS : & [ & str ] = & [ "-g" , "-Cdebuginfo=" , /*-C<space>*/ "debuginfo=" ] ;
1136
+
1137
+ // FIXME: ideally we would "just" check the `cmd` itself, but it does not allow inspecting
1138
+ // its arguments. They need to be collected separately. For now I cannot be bothered to
1139
+ // implement this the "right" way.
1140
+ let have_opt_flag = self . props . compile_flags . iter ( ) . any ( |arg| {
1141
+ OPT_FLAGS . iter ( ) . any ( |f| arg. starts_with ( f) )
1142
+ } ) ;
1143
+ let have_debug_flag = self . props . compile_flags . iter ( ) . any ( |arg| {
1144
+ DEBUG_FLAGS . iter ( ) . any ( |f| arg. starts_with ( f) )
1145
+ } ) ;
1146
+
1147
+ for arg in args {
1148
+ if OPT_FLAGS . iter ( ) . any ( |f| arg. starts_with ( f) ) && have_opt_flag {
1149
+ continue ;
1150
+ }
1151
+ if DEBUG_FLAGS . iter ( ) . any ( |f| arg. starts_with ( f) ) && have_debug_flag {
1152
+ continue ;
1153
+ }
1154
+ cmd. arg ( arg) ;
1155
+ }
1156
+ }
1157
+
1122
1158
fn check_debugger_output ( & self , debugger_run_result : & ProcRes , check_lines : & [ String ] ) {
1123
1159
let num_check_lines = check_lines. len ( ) ;
1124
1160
@@ -1707,10 +1743,7 @@ impl<'test> TestCx<'test> {
1707
1743
1708
1744
rustc. arg ( & format ! ( "--target={}" , target) ) ;
1709
1745
}
1710
-
1711
- if let Some ( revision) = self . revision {
1712
- rustc. args ( & [ "--cfg" , revision] ) ;
1713
- }
1746
+ self . set_revision_flags ( & mut rustc) ;
1714
1747
1715
1748
if !is_rustdoc {
1716
1749
if let Some ( ref incremental_dir) = self . props . incremental_dir {
@@ -1810,9 +1843,11 @@ impl<'test> TestCx<'test> {
1810
1843
}
1811
1844
1812
1845
if self . props . force_host {
1813
- rustc. args ( self . split_maybe_args ( & self . config . host_rustcflags ) ) ;
1846
+ self . maybe_add_external_args ( & mut rustc,
1847
+ self . split_maybe_args ( & self . config . host_rustcflags ) ) ;
1814
1848
} else {
1815
- rustc. args ( self . split_maybe_args ( & self . config . target_rustcflags ) ) ;
1849
+ self . maybe_add_external_args ( & mut rustc,
1850
+ self . split_maybe_args ( & self . config . target_rustcflags ) ) ;
1816
1851
if !is_rustdoc {
1817
1852
if let Some ( ref linker) = self . config . linker {
1818
1853
rustc. arg ( format ! ( "-Clinker={}" , linker) ) ;
@@ -2065,12 +2100,19 @@ impl<'test> TestCx<'test> {
2065
2100
. arg ( "--input-file" )
2066
2101
. arg ( irfile)
2067
2102
. arg ( & self . testpaths . file ) ;
2103
+ // It would be more appropriate to make most of the arguments configurable through
2104
+ // a comment-attribute similar to `compile-flags`. For example, --check-prefixes is a very
2105
+ // useful flag.
2106
+ //
2107
+ // For now, though…
2108
+ if let Some ( rev) = self . revision {
2109
+ let prefixes = format ! ( "CHECK,{}" , rev) ;
2110
+ filecheck. args ( & [ "--check-prefixes" , & prefixes] ) ;
2111
+ }
2068
2112
self . compose_and_run ( filecheck, "" , None , None )
2069
2113
}
2070
2114
2071
2115
fn run_codegen_test ( & self ) {
2072
- assert ! ( self . revision. is_none( ) , "revisions not relevant here" ) ;
2073
-
2074
2116
if self . config . llvm_filecheck . is_none ( ) {
2075
2117
self . fatal ( "missing --llvm-filecheck" ) ;
2076
2118
}
0 commit comments