@@ -12,7 +12,7 @@ use common::{Config, TestPaths};
1212use common:: { UI_FIXED , UI_STDERR , UI_STDOUT } ;
1313use common:: { CompileFail , ParseFail , Pretty , RunFail , RunPass , RunPassValgrind } ;
1414use common:: { Codegen , DebugInfoLldb , DebugInfoGdb , Rustdoc , CodegenUnits } ;
15- use common:: { Incremental , RunMake , Ui , MirOpt } ;
15+ use common:: { Incremental , RunMake , Ui , MirOpt , Assembly } ;
1616use diff;
1717use errors:: { self , ErrorKind , Error } ;
1818use filetime:: FileTime ;
@@ -142,6 +142,7 @@ impl<'test> TestCx<'test> {
142142 RunMake => self . run_rmake_test ( ) ,
143143 Ui => self . run_ui_test ( ) ,
144144 MirOpt => self . run_mir_opt_test ( ) ,
145+ Assembly => self . run_assembly_test ( ) ,
145146 }
146147 }
147148
@@ -1441,7 +1442,8 @@ actual:\n\
14411442 Codegen |
14421443 Rustdoc |
14431444 RunMake |
1444- CodegenUnits => {
1445+ CodegenUnits |
1446+ Assembly => {
14451447 // do not use JSON output
14461448 }
14471449 }
@@ -1712,10 +1714,35 @@ actual:\n\
17121714 self . compose_and_run_compiler ( rustc, None )
17131715 }
17141716
1715- fn check_ir_with_filecheck ( & self ) -> ProcRes {
1716- let irfile = self . output_base_name ( ) . with_extension ( "ll" ) ;
1717+ fn compile_test_and_save_assembly ( & self ) -> ( ProcRes , PathBuf ) {
1718+ // This works with both `--emit asm` (as default output name for the assembly)
1719+ // and `ptx-linker` because the latter can write output at requested location.
1720+ let output_path = self . output_base_name ( ) . with_extension ( "s" ) ;
1721+
1722+ let output_file = TargetLocation :: ThisFile ( output_path. clone ( ) ) ;
1723+ let mut rustc = self . make_compile_args ( & self . testpaths . file , output_file, AllowUnused :: No ) ;
1724+
1725+ rustc. arg ( "-L" ) . arg ( self . aux_output_dir_name ( ) ) ;
1726+
1727+ match self . props . assembly_output . as_ref ( ) . map ( AsRef :: as_ref) {
1728+ Some ( "emit-asm" ) => {
1729+ rustc. arg ( "--emit=asm" ) ;
1730+ }
1731+
1732+ Some ( "ptx-linker" ) => {
1733+ // No extra flags needed.
1734+ }
1735+
1736+ Some ( _) => self . fatal ( "unknown 'assembly-output' header" ) ,
1737+ None => self . fatal ( "missing 'assembly-output' header" ) ,
1738+ }
1739+
1740+ ( self . compose_and_run_compiler ( rustc, None ) , output_path)
1741+ }
1742+
1743+ fn verify_with_filecheck ( & self , output : & Path ) -> ProcRes {
17171744 let mut filecheck = Command :: new ( self . config . llvm_filecheck . as_ref ( ) . unwrap ( ) ) ;
1718- filecheck. arg ( "--input-file" ) . arg ( irfile )
1745+ filecheck. arg ( "--input-file" ) . arg ( output )
17191746 . arg ( & self . testpaths . file ) ;
17201747 self . compose_and_run ( filecheck, "" , None , None )
17211748 }
@@ -1727,12 +1754,29 @@ actual:\n\
17271754 self . fatal ( "missing --llvm-filecheck" ) ;
17281755 }
17291756
1730- let mut proc_res = self . compile_test_and_save_ir ( ) ;
1757+ let proc_res = self . compile_test_and_save_ir ( ) ;
1758+ if !proc_res. status . success ( ) {
1759+ self . fatal_proc_rec ( "compilation failed!" , & proc_res) ;
1760+ }
1761+
1762+ let output_path = self . output_base_name ( ) . with_extension ( "ll" ) ;
1763+ let proc_res = self . verify_with_filecheck ( & output_path) ;
1764+ if !proc_res. status . success ( ) {
1765+ self . fatal_proc_rec ( "verification with 'FileCheck' failed" , & proc_res) ;
1766+ }
1767+ }
1768+
1769+ fn run_assembly_test ( & self ) {
1770+ if self . config . llvm_filecheck . is_none ( ) {
1771+ self . fatal ( "missing --llvm-filecheck" ) ;
1772+ }
1773+
1774+ let ( proc_res, output_path) = self . compile_test_and_save_assembly ( ) ;
17311775 if !proc_res. status . success ( ) {
17321776 self . fatal_proc_rec ( "compilation failed!" , & proc_res) ;
17331777 }
17341778
1735- proc_res = self . check_ir_with_filecheck ( ) ;
1779+ let proc_res = self . verify_with_filecheck ( & output_path ) ;
17361780 if !proc_res. status . success ( ) {
17371781 self . fatal_proc_rec ( "verification with 'FileCheck' failed" , & proc_res) ;
17381782 }
0 commit comments