@@ -93,6 +93,7 @@ struct TestArg {
9393 sysroot_panic_abort : bool ,
9494 config_info : ConfigInfo ,
9595 sysroot_features : Vec < String > ,
96+ keep_lto_tests : bool ,
9697}
9798
9899impl TestArg {
@@ -128,6 +129,9 @@ impl TestArg {
128129 "--sysroot-panic-abort" => {
129130 test_arg. sysroot_panic_abort = true ;
130131 }
132+ "--keep-lto-tests" => {
133+ test_arg. keep_lto_tests = true ;
134+ }
131135 "--sysroot-features" => match args. next ( ) {
132136 Some ( feature) if !feature. is_empty ( ) => {
133137 test_arg. sysroot_features . push ( feature) ;
@@ -194,7 +198,7 @@ fn build_if_no_backend(env: &Env, args: &TestArg) -> Result<(), String> {
194198}
195199
196200fn clean ( _env : & Env , args : & TestArg ) -> Result < ( ) , String > {
197- let _ = std :: fs :: remove_dir_all ( & args. config_info . cargo_target_dir ) ;
201+ let _ = remove_dir_all ( & args. config_info . cargo_target_dir ) ;
198202 let path = Path :: new ( & args. config_info . cargo_target_dir ) . join ( "gccjit" ) ;
199203 create_dir ( & path)
200204}
@@ -835,8 +839,7 @@ fn valid_ui_error_pattern_test(file: &str) -> bool {
835839 . any ( |to_ignore| file. ends_with ( to_ignore) )
836840}
837841
838- #[ rustfmt:: skip]
839- fn contains_ui_error_patterns ( file_path : & Path ) -> Result < bool , String > {
842+ fn contains_ui_error_patterns ( file_path : & Path , keep_lto_tests : bool ) -> Result < bool , String > {
840843 // Tests generating errors.
841844 let file = File :: open ( file_path)
842845 . map_err ( |error| format ! ( "Failed to read `{}`: {:?}" , file_path. display( ) , error) ) ?;
@@ -845,19 +848,22 @@ fn contains_ui_error_patterns(file_path: &Path) -> Result<bool, String> {
845848 if line. is_empty ( ) {
846849 continue ;
847850 }
848- if [
849- "//@ error-pattern:" ,
850- "//@ build-fail" ,
851- "//@ run-fail" ,
852- "-Cllvm-args" ,
853- "//~" ,
854- "thread" ,
855- ]
851+ if [ "//@ error-pattern:" , "//@ build-fail" , "//@ run-fail" , "-Cllvm-args" , "//~" , "thread" ]
856852 . iter ( )
857853 . any ( |check| line. contains ( check) )
858854 {
859855 return Ok ( true ) ;
860856 }
857+
858+ if !keep_lto_tests
859+ && ( line. contains ( "-Clto" )
860+ || line. contains ( "-C lto" )
861+ || line. contains ( "compile-flags: -Clinker-plugin-lto" ) )
862+ && !line. contains ( "-Clto=thin" )
863+ {
864+ return Ok ( true ) ;
865+ }
866+
861867 if line. contains ( "//[" ) && line. contains ( "]~" ) {
862868 return Ok ( true ) ;
863869 }
@@ -903,7 +909,7 @@ where
903909 rust_path. join ( "tests/ui" ) ,
904910 & mut |_dir| Ok ( ( ) ) ,
905911 & mut |file_path| {
906- if contains_ui_error_patterns ( file_path) ? {
912+ if contains_ui_error_patterns ( file_path, args . keep_lto_tests ) ? {
907913 Ok ( ( ) )
908914 } else {
909915 remove_file ( file_path) . map_err ( |e| e. to_string ( ) )
@@ -928,7 +934,7 @@ where
928934 . iter ( )
929935 . any ( |name| * name == dir_name)
930936 {
931- std :: fs :: remove_dir_all ( dir) . map_err ( |error| {
937+ remove_dir_all ( dir) . map_err ( |error| {
932938 format ! ( "Failed to remove folder `{}`: {:?}" , dir. display( ) , error)
933939 } ) ?;
934940 }
@@ -940,27 +946,42 @@ where
940946
941947 // These two functions are used to remove files that are known to not be working currently
942948 // with the GCC backend to reduce noise.
943- fn dir_handling ( dir : & Path ) -> Result < ( ) , String > {
944- if dir. file_name ( ) . map ( |name| name == "auxiliary" ) . unwrap_or ( true ) {
945- return Ok ( ( ) ) ;
946- }
949+ fn dir_handling ( keep_lto_tests : bool ) -> impl Fn ( & Path ) -> Result < ( ) , String > {
950+ move |dir| {
951+ if dir. file_name ( ) . map ( |name| name == "auxiliary" ) . unwrap_or ( true ) {
952+ return Ok ( ( ) ) ;
953+ }
947954
948- walk_dir ( dir, & mut dir_handling, & mut file_handling, false )
949- }
950- fn file_handling ( file_path : & Path ) -> Result < ( ) , String > {
951- if !file_path. extension ( ) . map ( |extension| extension == "rs" ) . unwrap_or ( false ) {
952- return Ok ( ( ) ) ;
955+ walk_dir (
956+ dir,
957+ & mut dir_handling ( keep_lto_tests) ,
958+ & mut file_handling ( keep_lto_tests) ,
959+ false ,
960+ )
953961 }
954- let path_str = file_path. display ( ) . to_string ( ) . replace ( "\\ " , "/" ) ;
955- if valid_ui_error_pattern_test ( & path_str) {
956- return Ok ( ( ) ) ;
957- } else if contains_ui_error_patterns ( file_path) ? {
958- return remove_file ( & file_path) ;
962+ }
963+
964+ fn file_handling ( keep_lto_tests : bool ) -> impl Fn ( & Path ) -> Result < ( ) , String > {
965+ move |file_path| {
966+ if !file_path. extension ( ) . map ( |extension| extension == "rs" ) . unwrap_or ( false ) {
967+ return Ok ( ( ) ) ;
968+ }
969+ let path_str = file_path. display ( ) . to_string ( ) . replace ( "\\ " , "/" ) ;
970+ if valid_ui_error_pattern_test ( & path_str) {
971+ return Ok ( ( ) ) ;
972+ } else if contains_ui_error_patterns ( file_path, keep_lto_tests) ? {
973+ return remove_file ( & file_path) ;
974+ }
975+ Ok ( ( ) )
959976 }
960- Ok ( ( ) )
961977 }
962978
963- walk_dir ( rust_path. join ( "tests/ui" ) , & mut dir_handling, & mut file_handling, false ) ?;
979+ walk_dir (
980+ rust_path. join ( "tests/ui" ) ,
981+ & mut dir_handling ( args. keep_lto_tests ) ,
982+ & mut file_handling ( args. keep_lto_tests ) ,
983+ false ,
984+ ) ?;
964985 }
965986 let nb_parts = args. nb_parts . unwrap_or ( 0 ) ;
966987 if nb_parts > 0 {
@@ -1173,7 +1194,7 @@ fn remove_files_callback<'a>(
11731194 files. split ( '\n' ) . map ( |line| line. trim ( ) ) . filter ( |line| !line. is_empty ( ) )
11741195 {
11751196 let path = rust_path. join ( file) ;
1176- if let Err ( e) = std :: fs :: remove_dir_all ( & path) {
1197+ if let Err ( e) = remove_dir_all ( & path) {
11771198 println ! ( "Failed to remove directory `{}`: {}" , path. display( ) , e) ;
11781199 }
11791200 }
0 commit comments