@@ -474,14 +474,12 @@ impl<'test> TestCx<'test> {
474474 self . fatal ( "missing --coverage-dump" ) ;
475475 } ;
476476
477- let proc_res = self . compile_test_and_save_ir ( ) ;
477+ let ( proc_res, llvm_ir_path ) = self . compile_test_and_save_ir ( ) ;
478478 if !proc_res. status . success ( ) {
479479 self . fatal_proc_rec ( "compilation failed!" , & proc_res) ;
480480 }
481481 drop ( proc_res) ;
482482
483- let llvm_ir_path = self . output_base_name ( ) . with_extension ( "ll" ) ;
484-
485483 let mut dump_command = Command :: new ( coverage_dump_path) ;
486484 dump_command. arg ( llvm_ir_path) ;
487485 let proc_res = self . run_command_to_procres ( & mut dump_command) ;
@@ -2785,10 +2783,54 @@ impl<'test> TestCx<'test> {
27852783 proc_res. fatal ( None , || on_failure ( * self ) ) ;
27862784 }
27872785
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+
27882830 // codegen tests (using FileCheck)
27892831
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" ) ;
27922834 let input_file = & self . testpaths . file ;
27932835 let rustc = self . make_compile_args (
27942836 input_file,
@@ -2799,15 +2841,13 @@ impl<'test> TestCx<'test> {
27992841 Vec :: new ( ) ,
28002842 ) ;
28012843
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)
28032847 }
28042848
28052849 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" ) ;
28112851 let input_file = & self . testpaths . file ;
28122852
28132853 let mut emit = Emit :: None ;
@@ -2837,7 +2877,9 @@ impl<'test> TestCx<'test> {
28372877 Vec :: new ( ) ,
28382878 ) ;
28392879
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)
28412883 }
28422884
28432885 fn verify_with_filecheck ( & self , output : & Path ) -> ProcRes {
@@ -2870,16 +2912,14 @@ impl<'test> TestCx<'test> {
28702912 self . fatal ( "missing --llvm-filecheck" ) ;
28712913 }
28722914
2873- let proc_res = self . compile_test_and_save_ir ( ) ;
2915+ let ( proc_res, output_path ) = self . compile_test_and_save_ir ( ) ;
28742916 if !proc_res. status . success ( ) {
28752917 self . fatal_proc_rec ( "compilation failed!" , & proc_res) ;
28762918 }
28772919
28782920 if let Some ( PassMode :: Build ) = self . pass_mode ( ) {
28792921 return ;
28802922 }
2881-
2882- let output_path = self . output_base_name ( ) . with_extension ( "ll" ) ;
28832923 let proc_res = self . verify_with_filecheck ( & output_path) ;
28842924 if !proc_res. status . success ( ) {
28852925 self . fatal_proc_rec ( "verification with 'FileCheck' failed" , & proc_res) ;
0 commit comments