@@ -366,47 +366,21 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
366
366
/// Returns `true` if an intercept happened.
367
367
pub fn hook_panic_fn (
368
368
& mut self ,
369
+ span : Span ,
369
370
instance : ty:: Instance < ' tcx > ,
370
371
args : & [ OpTy < ' tcx , M :: PointerTag > ] ,
371
- _ret : Option < ( PlaceTy < ' tcx , M :: PointerTag > , mir:: BasicBlock ) > ,
372
372
) -> InterpResult < ' tcx , bool > {
373
373
let def_id = instance. def_id ( ) ;
374
- if Some ( def_id) == self . tcx . lang_items ( ) . panic_fn ( ) {
375
- // &'static str, &core::panic::Location { &'static str, u32, u32 }
376
- assert ! ( args. len( ) == 2 ) ;
374
+ if Some ( def_id) == self . tcx . lang_items ( ) . panic_fn ( )
375
+ || Some ( def_id) == self . tcx . lang_items ( ) . begin_panic_fn ( )
376
+ {
377
+ // &'static str
378
+ assert ! ( args. len( ) == 1 ) ;
377
379
378
380
let msg_place = self . deref_operand ( args[ 0 ] ) ?;
379
381
let msg = Symbol :: intern ( self . read_str ( msg_place) ?) ;
380
-
381
- let location = self . deref_operand ( args[ 1 ] ) ?;
382
- let ( file, line, col) = (
383
- self . mplace_field ( location, 0 ) ?,
384
- self . mplace_field ( location, 1 ) ?,
385
- self . mplace_field ( location, 2 ) ?,
386
- ) ;
387
-
388
- let file_place = self . deref_operand ( file. into ( ) ) ?;
389
- let file = Symbol :: intern ( self . read_str ( file_place) ?) ;
390
- let line = self . read_scalar ( line. into ( ) ) ?. to_u32 ( ) ?;
391
- let col = self . read_scalar ( col. into ( ) ) ?. to_u32 ( ) ?;
392
- throw_panic ! ( Panic { msg, file, line, col } )
393
- } else if Some ( def_id) == self . tcx . lang_items ( ) . begin_panic_fn ( ) {
394
- assert ! ( args. len( ) == 2 ) ;
395
- // &'static str, &(&'static str, u32, u32)
396
- let msg = args[ 0 ] ;
397
- let place = self . deref_operand ( args[ 1 ] ) ?;
398
- let ( file, line, col) = (
399
- self . mplace_field ( place, 0 ) ?,
400
- self . mplace_field ( place, 1 ) ?,
401
- self . mplace_field ( place, 2 ) ?,
402
- ) ;
403
-
404
- let msg_place = self . deref_operand ( msg. into ( ) ) ?;
405
- let msg = Symbol :: intern ( self . read_str ( msg_place) ?) ;
406
- let file_place = self . deref_operand ( file. into ( ) ) ?;
407
- let file = Symbol :: intern ( self . read_str ( file_place) ?) ;
408
- let line = self . read_scalar ( line. into ( ) ) ?. to_u32 ( ) ?;
409
- let col = self . read_scalar ( col. into ( ) ) ?. to_u32 ( ) ?;
382
+ let span = self . find_closest_untracked_caller_location ( ) . unwrap_or ( span) ;
383
+ let ( file, line, col) = self . location_triple_for_span ( span) ;
410
384
throw_panic ! ( Panic { msg, file, line, col } )
411
385
} else {
412
386
return Ok ( false ) ;
0 commit comments