@@ -474,14 +474,12 @@ impl<'test> TestCx<'test> {
474
474
self . fatal ( "missing --coverage-dump" ) ;
475
475
} ;
476
476
477
- let proc_res = self . compile_test_and_save_ir ( ) ;
477
+ let ( proc_res, llvm_ir_path ) = self . compile_test_and_save_ir ( ) ;
478
478
if !proc_res. status . success ( ) {
479
479
self . fatal_proc_rec ( "compilation failed!" , & proc_res) ;
480
480
}
481
481
drop ( proc_res) ;
482
482
483
- let llvm_ir_path = self . output_base_name ( ) . with_extension ( "ll" ) ;
484
-
485
483
let mut dump_command = Command :: new ( coverage_dump_path) ;
486
484
dump_command. arg ( llvm_ir_path) ;
487
485
let proc_res = self . run_command_to_procres ( & mut dump_command) ;
@@ -2785,10 +2783,54 @@ impl<'test> TestCx<'test> {
2785
2783
proc_res. fatal ( None , || on_failure ( * self ) ) ;
2786
2784
}
2787
2785
2786
+ fn get_output_file ( & self , extension : & str ) -> TargetLocation {
2787
+ let thin_lto = self . props . compile_flags . iter ( ) . any ( |s| s. ends_with ( "lto=thin" ) ) ;
2788
+ if thin_lto {
2789
+ TargetLocation :: ThisDirectory ( self . output_base_dir ( ) )
2790
+ } else {
2791
+ // This works with both `--emit asm` (as default output name for the assembly)
2792
+ // and `ptx-linker` because the latter can write output at requested location.
2793
+ let output_path = self . output_base_name ( ) . with_extension ( extension) ;
2794
+ let output_file = TargetLocation :: ThisFile ( output_path. clone ( ) ) ;
2795
+ output_file
2796
+ }
2797
+ }
2798
+
2799
+ fn get_filecheck_file ( & self , extension : & str ) -> PathBuf {
2800
+ let thin_lto = self . props . compile_flags . iter ( ) . any ( |s| s. ends_with ( "lto=thin" ) ) ;
2801
+ if thin_lto {
2802
+ let name = self . testpaths . file . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
2803
+ let canonical_name = name. replace ( '-' , "_" ) ;
2804
+ let mut output_file = None ;
2805
+ for entry in self . output_base_dir ( ) . read_dir ( ) . unwrap ( ) {
2806
+ if let Ok ( entry) = entry {
2807
+ let entry_path = entry. path ( ) ;
2808
+ let entry_file = entry_path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
2809
+ if entry_file. starts_with ( & format ! ( "{}.{}" , name, canonical_name) )
2810
+ && entry_file. ends_with ( extension)
2811
+ {
2812
+ assert ! (
2813
+ output_file. is_none( ) ,
2814
+ "thinlto doesn't support multiple cgu tests"
2815
+ ) ;
2816
+ output_file = Some ( entry_file. to_string ( ) ) ;
2817
+ }
2818
+ }
2819
+ }
2820
+ if let Some ( output_file) = output_file {
2821
+ self . output_base_dir ( ) . join ( output_file)
2822
+ } else {
2823
+ self . output_base_name ( ) . with_extension ( extension)
2824
+ }
2825
+ } else {
2826
+ self . output_base_name ( ) . with_extension ( extension)
2827
+ }
2828
+ }
2829
+
2788
2830
// codegen tests (using FileCheck)
2789
2831
2790
- fn compile_test_and_save_ir ( & self ) -> ProcRes {
2791
- let output_file = TargetLocation :: ThisDirectory ( self . output_base_dir ( ) ) ;
2832
+ fn compile_test_and_save_ir ( & self ) -> ( ProcRes , PathBuf ) {
2833
+ let output_file = self . get_output_file ( "ll" ) ;
2792
2834
let input_file = & self . testpaths . file ;
2793
2835
let rustc = self . make_compile_args (
2794
2836
input_file,
@@ -2799,15 +2841,13 @@ impl<'test> TestCx<'test> {
2799
2841
Vec :: new ( ) ,
2800
2842
) ;
2801
2843
2802
- self . compose_and_run_compiler ( rustc, None )
2844
+ let proc_res = self . compose_and_run_compiler ( rustc, None ) ;
2845
+ let output_path = self . get_filecheck_file ( "ll" ) ;
2846
+ ( proc_res, output_path)
2803
2847
}
2804
2848
2805
2849
fn compile_test_and_save_assembly ( & self ) -> ( ProcRes , PathBuf ) {
2806
- // This works with both `--emit asm` (as default output name for the assembly)
2807
- // and `ptx-linker` because the latter can write output at requested location.
2808
- let output_path = self . output_base_name ( ) . with_extension ( "s" ) ;
2809
-
2810
- let output_file = TargetLocation :: ThisFile ( output_path. clone ( ) ) ;
2850
+ let output_file = self . get_output_file ( "s" ) ;
2811
2851
let input_file = & self . testpaths . file ;
2812
2852
2813
2853
let mut emit = Emit :: None ;
@@ -2837,7 +2877,9 @@ impl<'test> TestCx<'test> {
2837
2877
Vec :: new ( ) ,
2838
2878
) ;
2839
2879
2840
- ( self . compose_and_run_compiler ( rustc, None ) , output_path)
2880
+ let proc_res = self . compose_and_run_compiler ( rustc, None ) ;
2881
+ let output_path = self . get_filecheck_file ( "s" ) ;
2882
+ ( proc_res, output_path)
2841
2883
}
2842
2884
2843
2885
fn verify_with_filecheck ( & self , output : & Path ) -> ProcRes {
@@ -2870,16 +2912,14 @@ impl<'test> TestCx<'test> {
2870
2912
self . fatal ( "missing --llvm-filecheck" ) ;
2871
2913
}
2872
2914
2873
- let proc_res = self . compile_test_and_save_ir ( ) ;
2915
+ let ( proc_res, output_path ) = self . compile_test_and_save_ir ( ) ;
2874
2916
if !proc_res. status . success ( ) {
2875
2917
self . fatal_proc_rec ( "compilation failed!" , & proc_res) ;
2876
2918
}
2877
2919
2878
2920
if let Some ( PassMode :: Build ) = self . pass_mode ( ) {
2879
2921
return ;
2880
2922
}
2881
-
2882
- let output_path = self . output_base_name ( ) . with_extension ( "ll" ) ;
2883
2923
let proc_res = self . verify_with_filecheck ( & output_path) ;
2884
2924
if !proc_res. status . success ( ) {
2885
2925
self . fatal_proc_rec ( "verification with 'FileCheck' failed" , & proc_res) ;
0 commit comments