@@ -12,7 +12,7 @@ use common::{Config, TestPaths};
12
12
use common:: { UI_FIXED , UI_STDERR , UI_STDOUT } ;
13
13
use common:: { CompileFail , ParseFail , Pretty , RunFail , RunPass , RunPassValgrind } ;
14
14
use common:: { Codegen , DebugInfoLldb , DebugInfoGdb , Rustdoc , CodegenUnits } ;
15
- use common:: { Incremental , RunMake , Ui , MirOpt } ;
15
+ use common:: { Incremental , RunMake , Ui , MirOpt , Assembly } ;
16
16
use diff;
17
17
use errors:: { self , ErrorKind , Error } ;
18
18
use filetime:: FileTime ;
@@ -142,6 +142,7 @@ impl<'test> TestCx<'test> {
142
142
RunMake => self . run_rmake_test ( ) ,
143
143
Ui => self . run_ui_test ( ) ,
144
144
MirOpt => self . run_mir_opt_test ( ) ,
145
+ Assembly => self . run_assembly_test ( ) ,
145
146
}
146
147
}
147
148
@@ -1441,7 +1442,8 @@ actual:\n\
1441
1442
Codegen |
1442
1443
Rustdoc |
1443
1444
RunMake |
1444
- CodegenUnits => {
1445
+ CodegenUnits |
1446
+ Assembly => {
1445
1447
// do not use JSON output
1446
1448
}
1447
1449
}
@@ -1712,10 +1714,35 @@ actual:\n\
1712
1714
self . compose_and_run_compiler ( rustc, None )
1713
1715
}
1714
1716
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 {
1717
1744
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 )
1719
1746
. arg ( & self . testpaths . file ) ;
1720
1747
self . compose_and_run ( filecheck, "" , None , None )
1721
1748
}
@@ -1727,12 +1754,29 @@ actual:\n\
1727
1754
self . fatal ( "missing --llvm-filecheck" ) ;
1728
1755
}
1729
1756
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 ( ) ;
1731
1775
if !proc_res. status . success ( ) {
1732
1776
self . fatal_proc_rec ( "compilation failed!" , & proc_res) ;
1733
1777
}
1734
1778
1735
- proc_res = self . check_ir_with_filecheck ( ) ;
1779
+ let proc_res = self . verify_with_filecheck ( & output_path ) ;
1736
1780
if !proc_res. status . success ( ) {
1737
1781
self . fatal_proc_rec ( "verification with 'FileCheck' failed" , & proc_res) ;
1738
1782
}
0 commit comments