@@ -128,7 +128,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
128
128
dest : Option < PlaceTy < ' tcx , Tag > > ,
129
129
ret : Option < mir:: BasicBlock > ,
130
130
) -> InterpResult < ' tcx > {
131
- use rustc:: mir:: interpret:: InterpError :: Panic ;
132
131
let this = self . eval_context_mut ( ) ;
133
132
let attrs = this. tcx . get_attrs ( def_id) ;
134
133
let link_name = match attr:: first_attr_value_str_by_name ( & attrs, sym:: link_name) {
@@ -142,15 +141,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
142
141
// First: functions that diverge.
143
142
match link_name {
144
143
"__rust_start_panic" | "panic_impl" => {
145
- return err ! ( MachineError ( "the evaluated program panicked" . to_string( ) ) ) ;
144
+ throw_unsup ! ( MachineError ( "the evaluated program panicked" . to_string( ) ) ) ;
146
145
}
147
146
"exit" | "ExitProcess" => {
148
147
// it's really u32 for ExitProcess, but we have to put it into the `Exit` error variant anyway
149
148
let code = this. read_scalar ( args[ 0 ] ) ?. to_i32 ( ) ?;
150
- return err ! ( Exit ( code) ) ;
149
+ return Err ( InterpError :: Exit ( code) . into ( ) ) ;
151
150
}
152
151
_ => if dest. is_none ( ) {
153
- return err ! ( Unimplemented (
152
+ throw_unsup ! ( Unimplemented (
154
153
format!( "can't call diverging foreign function: {}" , link_name) ,
155
154
) ) ;
156
155
}
@@ -168,7 +167,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
168
167
"calloc" => {
169
168
let items = this. read_scalar ( args[ 0 ] ) ?. to_usize ( this) ?;
170
169
let len = this. read_scalar ( args[ 1 ] ) ?. to_usize ( this) ?;
171
- let size = items. checked_mul ( len) . ok_or_else ( || Panic ( PanicMessage :: Overflow ( mir:: BinOp :: Mul ) ) ) ?;
170
+ let size = items. checked_mul ( len) . ok_or_else ( || err_panic ! ( Overflow ( mir:: BinOp :: Mul ) ) ) ?;
172
171
let res = this. malloc ( size, /*zero_init:*/ true , MiriMemoryKind :: C ) ;
173
172
this. write_scalar ( res, dest) ?;
174
173
}
@@ -178,13 +177,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
178
177
let size = this. read_scalar ( args[ 2 ] ) ?. to_usize ( this) ?;
179
178
// Align must be power of 2, and also at least ptr-sized (POSIX rules).
180
179
if !align. is_power_of_two ( ) {
181
- return err ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
180
+ throw_unsup ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
182
181
}
183
182
/*
184
183
FIXME: This check is disabled because rustc violates it.
185
184
See <https://github.com/rust-lang/rust/issues/62251>.
186
185
if align < this.pointer_size().bytes() {
187
- return err !(MachineError(format!(
186
+ throw_unsup !(MachineError(format!(
188
187
"posix_memalign: alignment must be at least the size of a pointer, but is {}",
189
188
align,
190
189
)));
@@ -217,10 +216,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
217
216
let size = this. read_scalar ( args[ 0 ] ) ?. to_usize ( this) ?;
218
217
let align = this. read_scalar ( args[ 1 ] ) ?. to_usize ( this) ?;
219
218
if size == 0 {
220
- return err ! ( HeapAllocZeroBytes ) ;
219
+ throw_unsup ! ( HeapAllocZeroBytes ) ;
221
220
}
222
221
if !align. is_power_of_two ( ) {
223
- return err ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
222
+ throw_unsup ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
224
223
}
225
224
let ptr = this. memory_mut ( )
226
225
. allocate (
@@ -234,10 +233,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
234
233
let size = this. read_scalar ( args[ 0 ] ) ?. to_usize ( this) ?;
235
234
let align = this. read_scalar ( args[ 1 ] ) ?. to_usize ( this) ?;
236
235
if size == 0 {
237
- return err ! ( HeapAllocZeroBytes ) ;
236
+ throw_unsup ! ( HeapAllocZeroBytes ) ;
238
237
}
239
238
if !align. is_power_of_two ( ) {
240
- return err ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
239
+ throw_unsup ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
241
240
}
242
241
let ptr = this. memory_mut ( )
243
242
. allocate (
@@ -256,10 +255,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
256
255
let old_size = this. read_scalar ( args[ 1 ] ) ?. to_usize ( this) ?;
257
256
let align = this. read_scalar ( args[ 2 ] ) ?. to_usize ( this) ?;
258
257
if old_size == 0 {
259
- return err ! ( HeapAllocZeroBytes ) ;
258
+ throw_unsup ! ( HeapAllocZeroBytes ) ;
260
259
}
261
260
if !align. is_power_of_two ( ) {
262
- return err ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
261
+ throw_unsup ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
263
262
}
264
263
let ptr = this. force_ptr ( ptr) ?;
265
264
this. memory_mut ( ) . deallocate (
@@ -274,10 +273,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
274
273
let align = this. read_scalar ( args[ 2 ] ) ?. to_usize ( this) ?;
275
274
let new_size = this. read_scalar ( args[ 3 ] ) ?. to_usize ( this) ?;
276
275
if old_size == 0 || new_size == 0 {
277
- return err ! ( HeapAllocZeroBytes ) ;
276
+ throw_unsup ! ( HeapAllocZeroBytes ) ;
278
277
}
279
278
if !align. is_power_of_two ( ) {
280
- return err ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
279
+ throw_unsup ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
281
280
}
282
281
let align = Align :: from_bytes ( align) . unwrap ( ) ;
283
282
let new_ptr = this. memory_mut ( ) . reallocate (
@@ -310,7 +309,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
310
309
this. write_scalar ( Scalar :: from_uint ( len, dest. layout . size ) , dest) ?;
311
310
}
312
311
id => {
313
- return err ! ( Unimplemented (
312
+ throw_unsup ! ( Unimplemented (
314
313
format!( "miri does not support syscall ID {}" , id) ,
315
314
) )
316
315
}
@@ -361,10 +360,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
361
360
let mut args = this. frame ( ) . body . args_iter ( ) ;
362
361
363
362
let arg_local = args. next ( ) . ok_or_else ( ||
364
- InterpError :: AbiViolation (
363
+ err_unsup ! ( AbiViolation (
365
364
"Argument to __rust_maybe_catch_panic does not take enough arguments."
366
365
. to_owned( ) ,
367
- ) ,
366
+ ) ) ,
368
367
) ?;
369
368
let arg_dest = this. local_place ( arg_local) ?;
370
369
this. write_scalar ( data, arg_dest) ?;
@@ -633,7 +632,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
633
632
if let Some ( result) = result {
634
633
this. write_scalar ( result, dest) ?;
635
634
} else {
636
- return err ! ( Unimplemented (
635
+ throw_unsup ! ( Unimplemented (
637
636
format!( "Unimplemented sysconf name: {}" , name) ,
638
637
) ) ;
639
638
}
@@ -662,14 +661,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
662
661
// This is `libc::pthread_key_t`.
663
662
let key_type = args[ 0 ] . layout . ty
664
663
. builtin_deref ( true )
665
- . ok_or_else ( || InterpError :: AbiViolation ( "wrong signature used for `pthread_key_create`: first argument must be a raw pointer." . to_owned ( ) ) ) ?
664
+ . ok_or_else ( || err_unsup ! (
665
+ AbiViolation ( "wrong signature used for `pthread_key_create`: first argument must be a raw pointer." . to_owned( ) )
666
+ ) ) ?
666
667
. ty ;
667
668
let key_layout = this. layout_of ( key_type) ?;
668
669
669
670
// Create key and write it into the memory where `key_ptr` wants it.
670
671
let key = this. machine . tls . create_tls_key ( dtor) as u128 ;
671
672
if key_layout. size . bits ( ) < 128 && key >= ( 1u128 << key_layout. size . bits ( ) as u128 ) {
672
- return err ! ( OutOfTls ) ;
673
+ throw_unsup ! ( OutOfTls ) ;
673
674
}
674
675
675
676
let key_ptr = this. memory ( ) . check_ptr_access ( key_ptr, key_layout. size , key_layout. align . abi ) ?
@@ -728,7 +729,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
728
729
729
730
// We don't support threading. (Also for Windows.)
730
731
"pthread_create" | "CreateThread" => {
731
- return err ! ( Unimplemented ( format!( "Miri does not support threading" ) ) ) ;
732
+ throw_unsup ! ( Unimplemented ( format!( "Miri does not support threading" ) ) ) ;
732
733
}
733
734
734
735
// Stub out calls for condvar, mutex and rwlock, to just return `0`.
@@ -869,7 +870,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
869
870
// Figure out how large a TLS key actually is. This is `c::DWORD`.
870
871
if dest. layout . size . bits ( ) < 128
871
872
&& key >= ( 1u128 << dest. layout . size . bits ( ) as u128 ) {
872
- return err ! ( OutOfTls ) ;
873
+ throw_unsup ! ( OutOfTls ) ;
873
874
}
874
875
this. write_scalar ( Scalar :: from_uint ( key, dest. layout . size ) , dest) ?;
875
876
}
@@ -947,7 +948,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
947
948
948
949
// We can't execute anything else.
949
950
_ => {
950
- return err ! ( Unimplemented (
951
+ throw_unsup ! ( Unimplemented (
951
952
format!( "can't call foreign function: {}" , link_name) ,
952
953
) ) ;
953
954
}
0 commit comments