@@ -1780,102 +1780,49 @@ impl<'test> TestCx<'test> {
17801780 proc_res. fatal ( None , || on_failure ( * self ) ) ;
17811781 }
17821782
1783- fn get_output_file ( & self , extension : & str ) -> TargetLocation {
1784- let thin_lto = self . props . compile_flags . iter ( ) . any ( |s| s. ends_with ( "lto=thin" ) ) ;
1785- if thin_lto {
1786- TargetLocation :: ThisDirectory ( self . output_base_dir ( ) )
1787- } else {
1788- // This works with both `--emit asm` (as default output name for the assembly)
1789- // and `ptx-linker` because the latter can write output at requested location.
1790- let output_path = self . output_base_name ( ) . with_extension ( extension) ;
1791-
1792- TargetLocation :: ThisFile ( output_path. clone ( ) )
1793- }
1794- }
1795-
1796- fn get_filecheck_file ( & self , extension : & str ) -> PathBuf {
1797- let thin_lto = self . props . compile_flags . iter ( ) . any ( |s| s. ends_with ( "lto=thin" ) ) ;
1798- if thin_lto {
1799- let name = self . testpaths . file . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
1800- let canonical_name = name. replace ( '-' , "_" ) ;
1801- let mut output_file = None ;
1802- for entry in self . output_base_dir ( ) . read_dir ( ) . unwrap ( ) {
1803- if let Ok ( entry) = entry {
1804- let entry_path = entry. path ( ) ;
1805- let entry_file = entry_path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
1806- if entry_file. starts_with ( & format ! ( "{}.{}" , name, canonical_name) )
1807- && entry_file. ends_with ( extension)
1808- {
1809- assert ! (
1810- output_file. is_none( ) ,
1811- "thinlto doesn't support multiple cgu tests"
1812- ) ;
1813- output_file = Some ( entry_file. to_string ( ) ) ;
1814- }
1815- }
1816- }
1817- if let Some ( output_file) = output_file {
1818- self . output_base_dir ( ) . join ( output_file)
1819- } else {
1820- self . output_base_name ( ) . with_extension ( extension)
1821- }
1822- } else {
1823- self . output_base_name ( ) . with_extension ( extension)
1824- }
1825- }
1826-
18271783 // codegen tests (using FileCheck)
18281784
18291785 fn compile_test_and_save_ir ( & self ) -> ( ProcRes , PathBuf ) {
1830- let output_file = self . get_output_file ( "ll" ) ;
1786+ let output_path = self . output_base_name ( ) . with_extension ( "ll" ) ;
18311787 let input_file = & self . testpaths . file ;
18321788 let rustc = self . make_compile_args (
18331789 input_file,
1834- output_file ,
1790+ TargetLocation :: ThisFile ( output_path . clone ( ) ) ,
18351791 Emit :: LlvmIr ,
18361792 AllowUnused :: No ,
18371793 LinkToAux :: Yes ,
18381794 Vec :: new ( ) ,
18391795 ) ;
18401796
18411797 let proc_res = self . compose_and_run_compiler ( rustc, None , self . testpaths ) ;
1842- let output_path = self . get_filecheck_file ( "ll" ) ;
18431798 ( proc_res, output_path)
18441799 }
18451800
18461801 fn compile_test_and_save_assembly ( & self ) -> ( ProcRes , PathBuf ) {
1847- let output_file = self . get_output_file ( "s" ) ;
1802+ // This works with both `--emit asm` (as default output name for the assembly)
1803+ // and `ptx-linker` because the latter can write output at requested location.
1804+ let output_path = self . output_base_name ( ) . with_extension ( "s" ) ;
18481805 let input_file = & self . testpaths . file ;
18491806
1850- let mut emit = Emit :: None ;
1851- match self . props . assembly_output . as_ref ( ) . map ( AsRef :: as_ref) {
1852- Some ( "emit-asm" ) => {
1853- emit = Emit :: Asm ;
1854- }
1855-
1856- Some ( "bpf-linker" ) => {
1857- emit = Emit :: LinkArgsAsm ;
1858- }
1859-
1860- Some ( "ptx-linker" ) => {
1861- // No extra flags needed.
1862- }
1863-
1864- Some ( header) => self . fatal ( & format ! ( "unknown 'assembly-output' header: {header}" ) ) ,
1865- None => self . fatal ( "missing 'assembly-output' header" ) ,
1866- }
1807+ // Use the `//@ assembly-output:` directive to determine how to emit assembly.
1808+ let emit = match self . props . assembly_output . as_deref ( ) {
1809+ Some ( "emit-asm" ) => Emit :: Asm ,
1810+ Some ( "bpf-linker" ) => Emit :: LinkArgsAsm ,
1811+ Some ( "ptx-linker" ) => Emit :: None , // No extra flags needed.
1812+ Some ( other) => self . fatal ( & format ! ( "unknown 'assembly-output' directive: {other}" ) ) ,
1813+ None => self . fatal ( "missing 'assembly-output' directive" ) ,
1814+ } ;
18671815
18681816 let rustc = self . make_compile_args (
18691817 input_file,
1870- output_file ,
1818+ TargetLocation :: ThisFile ( output_path . clone ( ) ) ,
18711819 emit,
18721820 AllowUnused :: No ,
18731821 LinkToAux :: Yes ,
18741822 Vec :: new ( ) ,
18751823 ) ;
18761824
18771825 let proc_res = self . compose_and_run_compiler ( rustc, None , self . testpaths ) ;
1878- let output_path = self . get_filecheck_file ( "s" ) ;
18791826 ( proc_res, output_path)
18801827 }
18811828
0 commit comments