@@ -552,9 +552,10 @@ impl<'test> TestCx<'test> {
552552 . args ( & [ "--target" , & self . config . target ] )
553553 . arg ( "-L" )
554554 . arg ( & aux_dir)
555- . args ( self . split_maybe_args ( & self . config . target_rustcflags ) )
556555 . args ( & self . props . compile_flags )
557556 . envs ( self . props . exec_env . clone ( ) ) ;
557+ self . maybe_add_external_args ( & mut rustc,
558+ self . split_maybe_args ( & self . config . target_rustcflags ) ) ;
558559
559560 let src = match read_from {
560561 ReadFrom :: Stdin ( src) => Some ( src) ,
@@ -587,6 +588,15 @@ impl<'test> TestCx<'test> {
587588 }
588589 }
589590
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+
590600 fn typecheck_source ( & self , src : String ) -> ProcRes {
591601 let mut rustc = Command :: new ( & self . config . rustc_path ) ;
592602
@@ -612,12 +622,9 @@ impl<'test> TestCx<'test> {
612622 . arg ( & self . config . build_base )
613623 . arg ( "-L" )
614624 . 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 ) ) ;
621628 rustc. args ( & self . props . compile_flags ) ;
622629
623630 self . compose_and_run_compiler ( rustc, Some ( src) )
@@ -1119,6 +1126,35 @@ impl<'test> TestCx<'test> {
11191126 Some ( new_options. join ( " " ) )
11201127 }
11211128
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+
11221158 fn check_debugger_output ( & self , debugger_run_result : & ProcRes , check_lines : & [ String ] ) {
11231159 let num_check_lines = check_lines. len ( ) ;
11241160
@@ -1707,10 +1743,7 @@ impl<'test> TestCx<'test> {
17071743
17081744 rustc. arg ( & format ! ( "--target={}" , target) ) ;
17091745 }
1710-
1711- if let Some ( revision) = self . revision {
1712- rustc. args ( & [ "--cfg" , revision] ) ;
1713- }
1746+ self . set_revision_flags ( & mut rustc) ;
17141747
17151748 if !is_rustdoc {
17161749 if let Some ( ref incremental_dir) = self . props . incremental_dir {
@@ -1810,9 +1843,11 @@ impl<'test> TestCx<'test> {
18101843 }
18111844
18121845 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 ) ) ;
18141848 } 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 ) ) ;
18161851 if !is_rustdoc {
18171852 if let Some ( ref linker) = self . config . linker {
18181853 rustc. arg ( format ! ( "-Clinker={}" , linker) ) ;
@@ -2065,12 +2100,19 @@ impl<'test> TestCx<'test> {
20652100 . arg ( "--input-file" )
20662101 . arg ( irfile)
20672102 . 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+ }
20682112 self . compose_and_run ( filecheck, "" , None , None )
20692113 }
20702114
20712115 fn run_codegen_test ( & self ) {
2072- assert ! ( self . revision. is_none( ) , "revisions not relevant here" ) ;
2073-
20742116 if self . config . llvm_filecheck . is_none ( ) {
20752117 self . fatal ( "missing --llvm-filecheck" ) ;
20762118 }
0 commit comments