@@ -248,14 +248,24 @@ impl Toolchain {
248248 }
249249 } ) ;
250250
251- let mut cmd = match ( script, cfg. args . timeout ) {
252- ( Some ( script) , None ) => {
251+ let target_dir = format ! ( "target-{}" , self . rustup_name( ) ) ;
252+ // Used in filecheck mode
253+ let llir_path = PathBuf :: from ( & target_dir)
254+ . join ( "debug" )
255+ . join ( "deps" )
256+ . join ( "output.ll" ) ;
257+
258+ let mut cmd = match ( script, cfg. args . timeout , & cfg. args . filecheck ) {
259+ ( Some ( _) , _, Some ( _) ) => {
260+ panic ! ( "incompatbile options `--script` and `--filecheck` used" ) ;
261+ }
262+ ( Some ( script) , None , None ) => {
253263 let mut cmd = Command :: new ( script) ;
254264 cmd. env ( "RUSTUP_TOOLCHAIN" , self . rustup_name ( ) ) ;
255265 cmd. args ( & cfg. args . command_args ) ;
256266 cmd
257267 }
258- ( None , None ) => {
268+ ( None , None , None ) => {
259269 let mut cmd = Command :: new ( "cargo" ) ;
260270 cmd. arg ( & format ! ( "+{}" , self . rustup_name( ) ) ) ;
261271 if cfg. args . command_args . is_empty ( ) {
@@ -265,15 +275,15 @@ impl Toolchain {
265275 }
266276 cmd
267277 }
268- ( Some ( script) , Some ( timeout) ) => {
278+ ( Some ( script) , Some ( timeout) , None ) => {
269279 let mut cmd = Command :: new ( "timeout" ) ;
270280 cmd. arg ( timeout. to_string ( ) ) ;
271281 cmd. arg ( script) ;
272282 cmd. args ( & cfg. args . command_args ) ;
273283 cmd. env ( "RUSTUP_TOOLCHAIN" , self . rustup_name ( ) ) ;
274284 cmd
275285 }
276- ( None , Some ( timeout) ) => {
286+ ( None , Some ( timeout) , None ) => {
277287 let mut cmd = Command :: new ( "timeout" ) ;
278288 cmd. arg ( timeout. to_string ( ) ) ;
279289 cmd. arg ( "cargo" ) ;
@@ -285,9 +295,39 @@ impl Toolchain {
285295 }
286296 cmd
287297 }
298+ ( None , None , Some ( _) ) => {
299+ let mut cmd = Command :: new ( "cargo" ) ;
300+ cmd. arg ( & format ! ( "+{}" , self . rustup_name( ) ) ) ;
301+ if cfg. args . command_args . is_empty ( ) {
302+ cmd. arg ( "rustc" )
303+ . arg ( "--" )
304+ . arg ( "-Copt-level=3" )
305+ . arg ( "-Cdebuginfo=0" )
306+ . arg ( format ! ( "--emit=llvm-ir={}" , llir_path. display( ) ) ) ;
307+ } else {
308+ cmd. args ( & cfg. args . command_args ) ;
309+ }
310+ cmd
311+ }
312+ ( None , Some ( timeout) , Some ( _) ) => {
313+ let mut cmd = Command :: new ( "timeout" ) ;
314+ cmd. arg ( timeout. to_string ( ) ) ;
315+ cmd. arg ( "cargo" ) ;
316+ cmd. arg ( & format ! ( "+{}" , self . rustup_name( ) ) ) ;
317+ if cfg. args . command_args . is_empty ( ) {
318+ cmd. arg ( "rustc" )
319+ . arg ( "--" )
320+ . arg ( "-Copt-level=3" )
321+ . arg ( "-Cdebuginfo=0" )
322+ . arg ( format ! ( "--emit=llvm-ir={}" , llir_path. display( ) ) ) ;
323+ } else {
324+ cmd. args ( & cfg. args . command_args ) ;
325+ }
326+ cmd
327+ }
288328 } ;
289329 cmd. current_dir ( & cfg. args . test_dir ) ;
290- cmd. env ( "CARGO_TARGET_DIR" , format ! ( "target-{}" , self . rustup_name ( ) ) ) ;
330+ cmd. env ( "CARGO_TARGET_DIR" , & target_dir ) ;
291331 if let Some ( target) = & cfg. args . target {
292332 cmd. env ( "CARGO_BUILD_TARGET" , target) ;
293333 }
@@ -319,6 +359,44 @@ impl Toolchain {
319359 io:: stdout ( ) . write_all ( & output. stdout ) . unwrap ( ) ;
320360 io:: stderr ( ) . write_all ( & output. stderr ) . unwrap ( ) ;
321361 }
362+
363+ let Some ( check_file) = & cfg. args . filecheck else {
364+ return output;
365+ } ;
366+
367+ if !output. status . success ( ) {
368+ return output;
369+ }
370+
371+ let filecheck_path = cfg
372+ . args
373+ . filecheck_path
374+ . clone ( )
375+ . unwrap_or_else ( || PathBuf :: from ( "FileCheck" ) ) ;
376+
377+ let mut cmd = Command :: new ( filecheck_path) ;
378+ cmd. arg ( "--input-file" )
379+ . arg (
380+ PathBuf :: from ( target_dir)
381+ . join ( "debug" )
382+ . join ( "deps" )
383+ . join ( "output.ll" ) ,
384+ )
385+ . arg ( check_file) ;
386+
387+ cmd. stdout ( default_stdio ( ) ) ;
388+ cmd. stderr ( default_stdio ( ) ) ;
389+ let output = match cmd. output ( ) {
390+ Ok ( output) => output,
391+ Err ( err) => {
392+ panic ! ( "thiserror::Errored to run {:?}: {:?}" , cmd, err) ;
393+ }
394+ } ;
395+ if must_capture_output && emit_output {
396+ io:: stdout ( ) . write_all ( & output. stdout ) . unwrap ( ) ;
397+ io:: stderr ( ) . write_all ( & output. stderr ) . unwrap ( ) ;
398+ }
399+
322400 output
323401 }
324402
0 commit comments