@@ -4,7 +4,7 @@ use crate::common::{output_base_dir, output_base_name, output_testname_unique};
4
4
use crate :: common:: { Codegen , CodegenUnits , DebugInfoBoth , DebugInfoGdb , DebugInfoLldb , Rustdoc } ;
5
5
use crate :: common:: { CompileFail , Pretty , RunFail , RunPass , RunPassValgrind } ;
6
6
use crate :: common:: { Config , TestPaths } ;
7
- use crate :: common:: { Incremental , MirOpt , RunMake , Ui , JsDocTest } ;
7
+ use crate :: common:: { Incremental , MirOpt , RunMake , Ui , JsDocTest , Assembly } ;
8
8
use diff;
9
9
use crate :: errors:: { self , Error , ErrorKind } ;
10
10
use filetime:: FileTime ;
@@ -275,6 +275,7 @@ impl<'test> TestCx<'test> {
275
275
RunMake => self . run_rmake_test ( ) ,
276
276
RunPass | Ui => self . run_ui_test ( ) ,
277
277
MirOpt => self . run_mir_opt_test ( ) ,
278
+ Assembly => self . run_assembly_test ( ) ,
278
279
JsDocTest => self . run_js_doc_test ( ) ,
279
280
}
280
281
}
@@ -1606,6 +1607,7 @@ impl<'test> TestCx<'test> {
1606
1607
|| self . config . target . contains ( "emscripten" )
1607
1608
|| ( self . config . target . contains ( "musl" ) && !aux_props. force_host )
1608
1609
|| self . config . target . contains ( "wasm32" )
1610
+ || self . config . target . contains ( "nvptx" )
1609
1611
{
1610
1612
// We primarily compile all auxiliary libraries as dynamic libraries
1611
1613
// to avoid code size bloat and large binaries as much as possible
@@ -1805,7 +1807,7 @@ impl<'test> TestCx<'test> {
1805
1807
rustc. arg ( dir_opt) ;
1806
1808
}
1807
1809
RunFail | RunPassValgrind | Pretty | DebugInfoBoth | DebugInfoGdb | DebugInfoLldb
1808
- | Codegen | Rustdoc | RunMake | CodegenUnits | JsDocTest => {
1810
+ | Codegen | Rustdoc | RunMake | CodegenUnits | JsDocTest | Assembly => {
1809
1811
// do not use JSON output
1810
1812
}
1811
1813
}
@@ -2100,12 +2102,37 @@ impl<'test> TestCx<'test> {
2100
2102
self . compose_and_run_compiler ( rustc, None )
2101
2103
}
2102
2104
2103
- fn check_ir_with_filecheck ( & self ) -> ProcRes {
2104
- let irfile = self . output_base_name ( ) . with_extension ( "ll" ) ;
2105
+ fn compile_test_and_save_assembly ( & self ) -> ( ProcRes , PathBuf ) {
2106
+ // This works with both `--emit asm` (as default output name for the assembly)
2107
+ // and `ptx-linker` because the latter can write output at requested location.
2108
+ let output_path = self . output_base_name ( ) . with_extension ( "s" ) ;
2109
+
2110
+ let output_file = TargetLocation :: ThisFile ( output_path. clone ( ) ) ;
2111
+ let mut rustc = self . make_compile_args ( & self . testpaths . file , output_file) ;
2112
+
2113
+ rustc. arg ( "-L" ) . arg ( self . aux_output_dir_name ( ) ) ;
2114
+
2115
+ match self . props . assembly_output . as_ref ( ) . map ( AsRef :: as_ref) {
2116
+ Some ( "emit-asm" ) => {
2117
+ rustc. arg ( "--emit=asm" ) ;
2118
+ }
2119
+
2120
+ Some ( "ptx-linker" ) => {
2121
+ // No extra flags needed.
2122
+ }
2123
+
2124
+ Some ( _) => self . fatal ( "unknown 'assembly-output' header" ) ,
2125
+ None => self . fatal ( "missing 'assembly-output' header" ) ,
2126
+ }
2127
+
2128
+ ( self . compose_and_run_compiler ( rustc, None ) , output_path)
2129
+ }
2130
+
2131
+ fn verify_with_filecheck ( & self , output : & Path ) -> ProcRes {
2105
2132
let mut filecheck = Command :: new ( self . config . llvm_filecheck . as_ref ( ) . unwrap ( ) ) ;
2106
2133
filecheck
2107
2134
. arg ( "--input-file" )
2108
- . arg ( irfile )
2135
+ . arg ( output )
2109
2136
. arg ( & self . testpaths . file ) ;
2110
2137
// It would be more appropriate to make most of the arguments configurable through
2111
2138
// a comment-attribute similar to `compile-flags`. For example, --check-prefixes is a very
@@ -2124,12 +2151,29 @@ impl<'test> TestCx<'test> {
2124
2151
self . fatal ( "missing --llvm-filecheck" ) ;
2125
2152
}
2126
2153
2127
- let mut proc_res = self . compile_test_and_save_ir ( ) ;
2154
+ let proc_res = self . compile_test_and_save_ir ( ) ;
2155
+ if !proc_res. status . success ( ) {
2156
+ self . fatal_proc_rec ( "compilation failed!" , & proc_res) ;
2157
+ }
2158
+
2159
+ let output_path = self . output_base_name ( ) . with_extension ( "ll" ) ;
2160
+ let proc_res = self . verify_with_filecheck ( & output_path) ;
2161
+ if !proc_res. status . success ( ) {
2162
+ self . fatal_proc_rec ( "verification with 'FileCheck' failed" , & proc_res) ;
2163
+ }
2164
+ }
2165
+
2166
+ fn run_assembly_test ( & self ) {
2167
+ if self . config . llvm_filecheck . is_none ( ) {
2168
+ self . fatal ( "missing --llvm-filecheck" ) ;
2169
+ }
2170
+
2171
+ let ( proc_res, output_path) = self . compile_test_and_save_assembly ( ) ;
2128
2172
if !proc_res. status . success ( ) {
2129
2173
self . fatal_proc_rec ( "compilation failed!" , & proc_res) ;
2130
2174
}
2131
2175
2132
- proc_res = self . check_ir_with_filecheck ( ) ;
2176
+ let proc_res = self . verify_with_filecheck ( & output_path ) ;
2133
2177
if !proc_res. status . success ( ) {
2134
2178
self . fatal_proc_rec ( "verification with 'FileCheck' failed" , & proc_res) ;
2135
2179
}
0 commit comments