@@ -4,7 +4,7 @@ use rand::rngs::StdRng;
44use rand:: SeedableRng ;
55
66use rustc:: hir:: def_id:: DefId ;
7- use rustc:: ty:: layout:: { Align , LayoutOf , Size } ;
7+ use rustc:: ty:: layout:: { LayoutOf , Size } ;
88use rustc:: ty:: { self , TyCtxt } ;
99use syntax:: source_map:: DUMMY_SP ;
1010
@@ -48,7 +48,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
4848 EnvVars :: init ( & mut ecx, config. excluded_env_vars ) ;
4949
5050 // Setup first stack-frame
51- let main_instance = ty:: Instance :: mono ( ecx . tcx . tcx , main_id) ;
51+ let main_instance = ty:: Instance :: mono ( tcx, main_id) ;
5252 let main_mir = ecx. load_mir ( main_instance. def , None ) ?;
5353
5454 if !main_mir. return_ty ( ) . is_unit ( ) || main_mir. arg_count != 0 {
@@ -59,11 +59,10 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
5959 let main_ret_ty = tcx. fn_sig ( main_id) . output ( ) ;
6060 let main_ret_ty = main_ret_ty. no_bound_vars ( ) . unwrap ( ) ;
6161 let start_instance = ty:: Instance :: resolve (
62- ecx . tcx . tcx ,
62+ tcx,
6363 ty:: ParamEnv :: reveal_all ( ) ,
6464 start_id,
65- ecx. tcx
66- . mk_substs ( :: std:: iter:: once ( ty:: subst:: GenericArg :: from ( main_ret_ty) ) ) ,
65+ tcx. mk_substs ( :: std:: iter:: once ( ty:: subst:: GenericArg :: from ( main_ret_ty) ) ) ,
6766 )
6867 . unwrap ( ) ;
6968 let start_mir = ecx. load_mir ( start_instance. def , None ) ?;
@@ -106,7 +105,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
106105 {
107106 let argc_place = ecx. allocate ( dest. layout , MiriMemoryKind :: Env . into ( ) ) ;
108107 ecx. write_scalar ( argc, argc_place. into ( ) ) ?;
109- ecx. machine . argc = Some ( argc_place. ptr . to_ptr ( ) ? ) ;
108+ ecx. machine . argc = Some ( argc_place. ptr ) ;
110109 }
111110
112111 // Third argument (`argv`): created from `config.args`.
@@ -134,8 +133,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
134133 }
135134 // Make an array with all these pointers, in the Miri memory.
136135 let argvs_layout = ecx. layout_of (
137- ecx. tcx
138- . mk_array ( ecx. tcx . mk_imm_ptr ( ecx. tcx . types . u8 ) , argvs. len ( ) as u64 ) ,
136+ tcx. mk_array ( tcx. mk_imm_ptr ( tcx. types . u8 ) , argvs. len ( ) as u64 ) ,
139137 ) ?;
140138 let argvs_place = ecx. allocate ( argvs_layout, MiriMemoryKind :: Env . into ( ) ) ;
141139 for ( idx, arg) in argvs. into_iter ( ) . enumerate ( ) {
@@ -151,36 +149,26 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
151149 {
152150 let argv_place = ecx. allocate ( dest. layout , MiriMemoryKind :: Env . into ( ) ) ;
153151 ecx. write_scalar ( argv, argv_place. into ( ) ) ?;
154- ecx. machine . argv = Some ( argv_place. ptr . to_ptr ( ) ? ) ;
152+ ecx. machine . argv = Some ( argv_place. ptr ) ;
155153 }
156154 // Store command line as UTF-16 for Windows `GetCommandLineW`.
157155 {
158156 let cmd_utf16: Vec < u16 > = cmd. encode_utf16 ( ) . collect ( ) ;
159- let cmd_ptr = ecx. memory . allocate (
160- Size :: from_bytes ( cmd_utf16. len ( ) as u64 * 2 ) ,
161- Align :: from_bytes ( 2 ) . unwrap ( ) ,
162- MiriMemoryKind :: Env . into ( ) ,
163- ) ;
164- ecx. machine . cmd_line = Some ( cmd_ptr) ;
157+ let cmd_type = tcx. mk_array ( tcx. types . u16 , cmd_utf16. len ( ) as u64 ) ;
158+ let cmd_place = ecx. allocate ( ecx. layout_of ( cmd_type) ?, MiriMemoryKind :: Env . into ( ) ) ;
159+ ecx. machine . cmd_line = Some ( cmd_place. ptr ) ;
165160 // Store the UTF-16 string. We just allocated so we know the bounds are fine.
166161 let char_size = Size :: from_bytes ( 2 ) ;
167- let cmd_alloc = ecx. memory . get_mut ( cmd_ptr. alloc_id ) ?;
168- let mut cur_ptr = cmd_ptr;
169- for & c in cmd_utf16. iter ( ) {
170- cmd_alloc. write_scalar (
171- & * ecx. tcx ,
172- cur_ptr,
173- Scalar :: from_uint ( c, char_size) . into ( ) ,
174- char_size,
175- ) ?;
176- cur_ptr = cur_ptr. offset ( char_size, & * ecx. tcx ) ?;
162+ for ( idx, & c) in cmd_utf16. iter ( ) . enumerate ( ) {
163+ let place = ecx. mplace_field ( cmd_place, idx as u64 ) ?;
164+ ecx. write_scalar ( Scalar :: from_uint ( c, char_size) , place. into ( ) ) ?;
177165 }
178166 }
179167
180168 args. next ( ) . expect_none ( "start lang item has more arguments than expected" ) ;
181169
182170 // Set the last_error to 0
183- let errno_layout = ecx. layout_of ( ecx . tcx . types . u32 ) ?;
171+ let errno_layout = ecx. layout_of ( tcx. types . u32 ) ?;
184172 let errno_place = ecx. allocate ( errno_layout, MiriMemoryKind :: Static . into ( ) ) ;
185173 ecx. write_scalar ( Scalar :: from_u32 ( 0 ) , errno_place. into ( ) ) ?;
186174 ecx. machine . last_error = Some ( errno_place) ;
0 commit comments