@@ -15,6 +15,7 @@ use crate::json;
15
15
use crate :: read2:: { read2_abbreviated, Truncated } ;
16
16
use crate :: util:: { add_dylib_path, dylib_env_var, logv, PathBufExt } ;
17
17
use crate :: ColorConfig ;
18
+ use miropt_test_tools:: { files_for_miropt_test, MiroptTest , MiroptTestFile } ;
18
19
use regex:: { Captures , Regex } ;
19
20
use rustfix:: { apply_suggestions, get_suggestions_from_json, Filter } ;
20
21
@@ -229,6 +230,7 @@ enum Emit {
229
230
None ,
230
231
Metadata ,
231
232
LlvmIr ,
233
+ Mir ,
232
234
Asm ,
233
235
LinkArgsAsm ,
234
236
}
@@ -2506,6 +2508,9 @@ impl<'test> TestCx<'test> {
2506
2508
Emit :: LlvmIr => {
2507
2509
rustc. args ( & [ "--emit" , "llvm-ir" ] ) ;
2508
2510
}
2511
+ Emit :: Mir => {
2512
+ rustc. args ( & [ "--emit" , "mir" ] ) ;
2513
+ }
2509
2514
Emit :: Asm => {
2510
2515
rustc. args ( & [ "--emit" , "asm" ] ) ;
2511
2516
}
@@ -3984,11 +3989,17 @@ impl<'test> TestCx<'test> {
3984
3989
fn run_mir_opt_test ( & self ) {
3985
3990
let pm = self . pass_mode ( ) ;
3986
3991
let should_run = self . should_run ( pm) ;
3987
- let emit_metadata = self . should_emit_metadata ( pm) ;
3988
- let passes = self . get_passes ( ) ;
3989
3992
3990
- let proc_res = self . compile_test_with_passes ( should_run, emit_metadata, passes) ;
3991
- self . check_mir_dump ( ) ;
3993
+ let mut test_info = files_for_miropt_test (
3994
+ & self . testpaths . file ,
3995
+ self . config . get_pointer_width ( ) ,
3996
+ self . config . target_cfg ( ) . panic . for_miropt_test_tools ( ) ,
3997
+ ) ;
3998
+
3999
+ let passes = std:: mem:: take ( & mut test_info. passes ) ;
4000
+
4001
+ let proc_res = self . compile_test_with_passes ( should_run, Emit :: Mir , passes) ;
4002
+ self . check_mir_dump ( test_info) ;
3992
4003
if !proc_res. status . success ( ) {
3993
4004
self . fatal_proc_rec ( "compilation failed!" , & proc_res) ;
3994
4005
}
@@ -4002,37 +4013,12 @@ impl<'test> TestCx<'test> {
4002
4013
}
4003
4014
}
4004
4015
4005
- fn get_passes ( & self ) -> Vec < String > {
4006
- let files = miropt_test_tools:: files_for_miropt_test (
4007
- & self . testpaths . file ,
4008
- self . config . get_pointer_width ( ) ,
4009
- self . config . target_cfg ( ) . panic . for_miropt_test_tools ( ) ,
4010
- ) ;
4011
-
4012
- let mut out = Vec :: new ( ) ;
4013
-
4014
- for miropt_test_tools:: MiroptTestFiles {
4015
- from_file : _,
4016
- to_file : _,
4017
- expected_file : _,
4018
- passes,
4019
- } in files
4020
- {
4021
- out. extend ( passes) ;
4022
- }
4023
- out
4024
- }
4025
-
4026
- fn check_mir_dump ( & self ) {
4016
+ fn check_mir_dump ( & self , test_info : MiroptTest ) {
4027
4017
let test_dir = self . testpaths . file . parent ( ) . unwrap ( ) ;
4028
4018
let test_crate =
4029
4019
self . testpaths . file . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . replace ( "-" , "_" ) ;
4030
4020
4031
- let suffix = miropt_test_tools:: output_file_suffix (
4032
- & self . testpaths . file ,
4033
- self . config . get_pointer_width ( ) ,
4034
- self . config . target_cfg ( ) . panic . for_miropt_test_tools ( ) ,
4035
- ) ;
4021
+ let MiroptTest { run_filecheck, suffix, files, passes : _ } = test_info;
4036
4022
4037
4023
if self . config . bless {
4038
4024
for e in
@@ -4047,14 +4033,7 @@ impl<'test> TestCx<'test> {
4047
4033
}
4048
4034
}
4049
4035
4050
- let files = miropt_test_tools:: files_for_miropt_test (
4051
- & self . testpaths . file ,
4052
- self . config . get_pointer_width ( ) ,
4053
- self . config . target_cfg ( ) . panic . for_miropt_test_tools ( ) ,
4054
- ) ;
4055
- for miropt_test_tools:: MiroptTestFiles { from_file, to_file, expected_file, passes : _ } in
4056
- files
4057
- {
4036
+ for MiroptTestFile { from_file, to_file, expected_file } in files {
4058
4037
let dumped_string = if let Some ( after) = to_file {
4059
4038
self . diff_mir_files ( from_file. into ( ) , after. into ( ) )
4060
4039
} else {
@@ -4095,6 +4074,14 @@ impl<'test> TestCx<'test> {
4095
4074
}
4096
4075
}
4097
4076
}
4077
+
4078
+ if run_filecheck {
4079
+ let output_path = self . output_base_name ( ) . with_extension ( "mir" ) ;
4080
+ let proc_res = self . verify_with_filecheck ( & output_path) ;
4081
+ if !proc_res. status . success ( ) {
4082
+ self . fatal_proc_rec ( "verification with 'FileCheck' failed" , & proc_res) ;
4083
+ }
4084
+ }
4098
4085
}
4099
4086
4100
4087
fn diff_mir_files ( & self , before : PathBuf , after : PathBuf ) -> String {
0 commit comments