1+ pub mod dlsym;
2+ pub mod env;
13pub mod foreign_items;
24pub mod intrinsics;
35pub mod tls;
4- pub mod dlsym;
5- pub mod env;
66
7- use rustc:: { ty , mir } ;
7+ use rustc:: { mir , ty } ;
88
99use crate :: * ;
1010
@@ -18,7 +18,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1818 ret : Option < mir:: BasicBlock > ,
1919 ) -> InterpResult < ' tcx , Option < & ' mir mir:: Body < ' tcx > > > {
2020 let this = self . eval_context_mut ( ) ;
21- trace ! ( "eval_fn_call: {:#?}, {:?}" , instance, dest. map( |place| * place) ) ;
21+ trace ! (
22+ "eval_fn_call: {:#?}, {:?}" ,
23+ instance,
24+ dest. map( |place| * place)
25+ ) ;
2226
2327 // First, run the common hooks also supported by CTFE.
2428 if this. hook_fn ( instance, args, dest) ? {
@@ -28,7 +32,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2832 // There are some more lang items we want to hook that CTFE does not hook (yet).
2933 if this. tcx . lang_items ( ) . align_offset_fn ( ) == Some ( instance. def . def_id ( ) ) {
3034 let dest = dest. unwrap ( ) ;
31- let n = this. align_offset ( args[ 0 ] , args[ 1 ] , dest. layout ) ?;
35+ let n = this
36+ . align_offset ( args[ 0 ] , args[ 1 ] ) ?
37+ . unwrap_or_else ( || this. truncate ( u128:: max_value ( ) , dest. layout ) ) ;
3238 this. write_scalar ( Scalar :: from_uint ( n, dest. layout . size ) , dest) ?;
3339 this. goto_block ( ret) ?;
3440 return Ok ( None ) ;
@@ -51,13 +57,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
5157 & mut self ,
5258 ptr_op : OpTy < ' tcx , Tag > ,
5359 align_op : OpTy < ' tcx , Tag > ,
54- layout : ty:: layout:: TyLayout < ' tcx > ,
55- ) -> InterpResult < ' tcx , u128 > {
60+ ) -> InterpResult < ' tcx , Option < u128 > > {
5661 let this = self . eval_context_mut ( ) ;
5762
5863 let req_align = this. force_bits (
5964 this. read_scalar ( align_op) ?. not_undef ( ) ?,
60- this. pointer_size ( )
65+ this. pointer_size ( ) ,
6166 ) ? as usize ;
6267
6368 // FIXME: This should actually panic in the interpreted program
@@ -67,18 +72,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
6772
6873 let ptr_scalar = this. read_scalar ( ptr_op) ?. not_undef ( ) ?;
6974
70- if let Scalar :: Ptr ( ptr) = ptr_scalar {
75+ if let Ok ( ptr) = this . force_ptr ( ptr_scalar) {
7176 let cur_align = this. memory ( ) . get ( ptr. alloc_id ) ?. align . bytes ( ) as usize ;
72- if cur_align < req_align {
73- return Ok ( this. truncate ( u128:: max_value ( ) , layout) ) ;
77+ if cur_align >= req_align {
78+ // if the allocation alignment is at least the required alignment we use the
79+ // libcore implementation
80+ return Ok ( Some (
81+ ( this. force_bits ( ptr_scalar, this. pointer_size ( ) ) ? as * const i8 )
82+ . align_offset ( req_align) as u128 ,
83+ ) ) ;
7484 }
7585 }
76-
77- // if the allocation alignment is at least the required alignment or if the pointer is an
78- // integer, we use the libcore implementation
79- Ok (
80- ( this. force_bits ( ptr_scalar, this. pointer_size ( ) ) ? as * const i8 )
81- . align_offset ( req_align) as u128
82- )
86+ // If the allocation alignment is smaller than then required alignment or the pointer was
87+ // actually an integer, we return `None`
88+ Ok ( None )
8389 }
8490}
0 commit comments