@@ -4,7 +4,7 @@ use rand::rngs::StdRng;
4
4
use rand:: SeedableRng ;
5
5
6
6
use rustc:: hir:: def_id:: DefId ;
7
- use rustc:: ty:: layout:: { Align , LayoutOf , Size } ;
7
+ use rustc:: ty:: layout:: { LayoutOf , Size } ;
8
8
use rustc:: ty:: { self , TyCtxt } ;
9
9
use syntax:: source_map:: DUMMY_SP ;
10
10
@@ -48,7 +48,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
48
48
EnvVars :: init ( & mut ecx, config. excluded_env_vars ) ;
49
49
50
50
// 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) ;
52
52
let main_mir = ecx. load_mir ( main_instance. def , None ) ?;
53
53
54
54
if !main_mir. return_ty ( ) . is_unit ( ) || main_mir. arg_count != 0 {
@@ -59,11 +59,10 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
59
59
let main_ret_ty = tcx. fn_sig ( main_id) . output ( ) ;
60
60
let main_ret_ty = main_ret_ty. no_bound_vars ( ) . unwrap ( ) ;
61
61
let start_instance = ty:: Instance :: resolve (
62
- ecx . tcx . tcx ,
62
+ tcx,
63
63
ty:: ParamEnv :: reveal_all ( ) ,
64
64
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) ) ) ,
67
66
)
68
67
. unwrap ( ) ;
69
68
let start_mir = ecx. load_mir ( start_instance. def , None ) ?;
@@ -106,7 +105,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
106
105
{
107
106
let argc_place = ecx. allocate ( dest. layout , MiriMemoryKind :: Env . into ( ) ) ;
108
107
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 ) ;
110
109
}
111
110
112
111
// Third argument (`argv`): created from `config.args`.
@@ -134,8 +133,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
134
133
}
135
134
// Make an array with all these pointers, in the Miri memory.
136
135
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 ) ,
139
137
) ?;
140
138
let argvs_place = ecx. allocate ( argvs_layout, MiriMemoryKind :: Env . into ( ) ) ;
141
139
for ( idx, arg) in argvs. into_iter ( ) . enumerate ( ) {
@@ -151,36 +149,26 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
151
149
{
152
150
let argv_place = ecx. allocate ( dest. layout , MiriMemoryKind :: Env . into ( ) ) ;
153
151
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 ) ;
155
153
}
156
154
// Store command line as UTF-16 for Windows `GetCommandLineW`.
157
155
{
158
156
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 ) ;
165
160
// Store the UTF-16 string. We just allocated so we know the bounds are fine.
166
161
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 ( ) ) ?;
177
165
}
178
166
}
179
167
180
168
args. next ( ) . expect_none ( "start lang item has more arguments than expected" ) ;
181
169
182
170
// 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 ) ?;
184
172
let errno_place = ecx. allocate ( errno_layout, MiriMemoryKind :: Static . into ( ) ) ;
185
173
ecx. write_scalar ( Scalar :: from_u32 ( 0 ) , errno_place. into ( ) ) ?;
186
174
ecx. machine . last_error = Some ( errno_place) ;
0 commit comments