@@ -128,7 +128,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
128128 dest : Option < PlaceTy < ' tcx , Tag > > ,
129129 ret : Option < mir:: BasicBlock > ,
130130 ) -> InterpResult < ' tcx > {
131- use rustc:: mir:: interpret:: InterpError :: Panic ;
132131 let this = self . eval_context_mut ( ) ;
133132 let attrs = this. tcx . get_attrs ( def_id) ;
134133 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
142141 // First: functions that diverge.
143142 match link_name {
144143 "__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( ) ) ) ;
146145 }
147146 "exit" | "ExitProcess" => {
148147 // it's really u32 for ExitProcess, but we have to put it into the `Exit` error variant anyway
149148 let code = this. read_scalar ( args[ 0 ] ) ?. to_i32 ( ) ?;
150- return err ! ( Exit ( code) ) ;
149+ return Err ( InterpError :: Exit ( code) . into ( ) ) ;
151150 }
152151 _ => if dest. is_none ( ) {
153- return err ! ( Unimplemented (
152+ throw_unsup ! ( Unimplemented (
154153 format!( "can't call diverging foreign function: {}" , link_name) ,
155154 ) ) ;
156155 }
@@ -168,7 +167,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
168167 "calloc" => {
169168 let items = this. read_scalar ( args[ 0 ] ) ?. to_usize ( this) ?;
170169 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 ) ) ) ?;
172171 let res = this. malloc ( size, /*zero_init:*/ true , MiriMemoryKind :: C ) ;
173172 this. write_scalar ( res, dest) ?;
174173 }
@@ -178,13 +177,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
178177 let size = this. read_scalar ( args[ 2 ] ) ?. to_usize ( this) ?;
179178 // Align must be power of 2, and also at least ptr-sized (POSIX rules).
180179 if !align. is_power_of_two ( ) {
181- return err ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
180+ throw_unsup ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
182181 }
183182 /*
184183 FIXME: This check is disabled because rustc violates it.
185184 See <https://github.com/rust-lang/rust/issues/62251>.
186185 if align < this.pointer_size().bytes() {
187- return err !(MachineError(format!(
186+ throw_unsup !(MachineError(format!(
188187 "posix_memalign: alignment must be at least the size of a pointer, but is {}",
189188 align,
190189 )));
@@ -217,10 +216,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
217216 let size = this. read_scalar ( args[ 0 ] ) ?. to_usize ( this) ?;
218217 let align = this. read_scalar ( args[ 1 ] ) ?. to_usize ( this) ?;
219218 if size == 0 {
220- return err ! ( HeapAllocZeroBytes ) ;
219+ throw_unsup ! ( HeapAllocZeroBytes ) ;
221220 }
222221 if !align. is_power_of_two ( ) {
223- return err ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
222+ throw_unsup ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
224223 }
225224 let ptr = this. memory_mut ( )
226225 . allocate (
@@ -234,10 +233,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
234233 let size = this. read_scalar ( args[ 0 ] ) ?. to_usize ( this) ?;
235234 let align = this. read_scalar ( args[ 1 ] ) ?. to_usize ( this) ?;
236235 if size == 0 {
237- return err ! ( HeapAllocZeroBytes ) ;
236+ throw_unsup ! ( HeapAllocZeroBytes ) ;
238237 }
239238 if !align. is_power_of_two ( ) {
240- return err ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
239+ throw_unsup ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
241240 }
242241 let ptr = this. memory_mut ( )
243242 . allocate (
@@ -256,10 +255,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
256255 let old_size = this. read_scalar ( args[ 1 ] ) ?. to_usize ( this) ?;
257256 let align = this. read_scalar ( args[ 2 ] ) ?. to_usize ( this) ?;
258257 if old_size == 0 {
259- return err ! ( HeapAllocZeroBytes ) ;
258+ throw_unsup ! ( HeapAllocZeroBytes ) ;
260259 }
261260 if !align. is_power_of_two ( ) {
262- return err ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
261+ throw_unsup ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
263262 }
264263 let ptr = this. force_ptr ( ptr) ?;
265264 this. memory_mut ( ) . deallocate (
@@ -274,10 +273,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
274273 let align = this. read_scalar ( args[ 2 ] ) ?. to_usize ( this) ?;
275274 let new_size = this. read_scalar ( args[ 3 ] ) ?. to_usize ( this) ?;
276275 if old_size == 0 || new_size == 0 {
277- return err ! ( HeapAllocZeroBytes ) ;
276+ throw_unsup ! ( HeapAllocZeroBytes ) ;
278277 }
279278 if !align. is_power_of_two ( ) {
280- return err ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
279+ throw_unsup ! ( HeapAllocNonPowerOfTwoAlignment ( align) ) ;
281280 }
282281 let align = Align :: from_bytes ( align) . unwrap ( ) ;
283282 let new_ptr = this. memory_mut ( ) . reallocate (
@@ -310,7 +309,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
310309 this. write_scalar ( Scalar :: from_uint ( len, dest. layout . size ) , dest) ?;
311310 }
312311 id => {
313- return err ! ( Unimplemented (
312+ throw_unsup ! ( Unimplemented (
314313 format!( "miri does not support syscall ID {}" , id) ,
315314 ) )
316315 }
@@ -361,10 +360,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
361360 let mut args = this. frame ( ) . body . args_iter ( ) ;
362361
363362 let arg_local = args. next ( ) . ok_or_else ( ||
364- InterpError :: AbiViolation (
363+ err_unsup ! ( AbiViolation (
365364 "Argument to __rust_maybe_catch_panic does not take enough arguments."
366365 . to_owned( ) ,
367- ) ,
366+ ) ) ,
368367 ) ?;
369368 let arg_dest = this. local_place ( arg_local) ?;
370369 this. write_scalar ( data, arg_dest) ?;
@@ -633,7 +632,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
633632 if let Some ( result) = result {
634633 this. write_scalar ( result, dest) ?;
635634 } else {
636- return err ! ( Unimplemented (
635+ throw_unsup ! ( Unimplemented (
637636 format!( "Unimplemented sysconf name: {}" , name) ,
638637 ) ) ;
639638 }
@@ -662,14 +661,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
662661 // This is `libc::pthread_key_t`.
663662 let key_type = args[ 0 ] . layout . ty
664663 . 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+ ) ) ?
666667 . ty ;
667668 let key_layout = this. layout_of ( key_type) ?;
668669
669670 // Create key and write it into the memory where `key_ptr` wants it.
670671 let key = this. machine . tls . create_tls_key ( dtor) as u128 ;
671672 if key_layout. size . bits ( ) < 128 && key >= ( 1u128 << key_layout. size . bits ( ) as u128 ) {
672- return err ! ( OutOfTls ) ;
673+ throw_unsup ! ( OutOfTls ) ;
673674 }
674675
675676 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
728729
729730 // We don't support threading. (Also for Windows.)
730731 "pthread_create" | "CreateThread" => {
731- return err ! ( Unimplemented ( format!( "Miri does not support threading" ) ) ) ;
732+ throw_unsup ! ( Unimplemented ( format!( "Miri does not support threading" ) ) ) ;
732733 }
733734
734735 // 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
869870 // Figure out how large a TLS key actually is. This is `c::DWORD`.
870871 if dest. layout . size . bits ( ) < 128
871872 && key >= ( 1u128 << dest. layout . size . bits ( ) as u128 ) {
872- return err ! ( OutOfTls ) ;
873+ throw_unsup ! ( OutOfTls ) ;
873874 }
874875 this. write_scalar ( Scalar :: from_uint ( key, dest. layout . size ) , dest) ?;
875876 }
@@ -947,7 +948,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
947948
948949 // We can't execute anything else.
949950 _ => {
950- return err ! ( Unimplemented (
951+ throw_unsup ! ( Unimplemented (
951952 format!( "can't call foreign function: {}" , link_name) ,
952953 ) ) ;
953954 }
0 commit comments