1
+ pub mod dlsym;
2
+ pub mod env;
1
3
pub mod foreign_items;
2
4
pub mod intrinsics;
3
5
pub mod tls;
4
- pub mod dlsym;
5
- pub mod env;
6
6
7
- use rustc:: { ty , mir } ;
7
+ use rustc:: { mir , ty } ;
8
8
9
9
use crate :: * ;
10
10
@@ -18,7 +18,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
18
18
ret : Option < mir:: BasicBlock > ,
19
19
) -> InterpResult < ' tcx , Option < & ' mir mir:: Body < ' tcx > > > {
20
20
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
+ ) ;
22
26
23
27
// First, run the common hooks also supported by CTFE.
24
28
if this. hook_fn ( instance, args, dest) ? {
@@ -28,7 +32,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
28
32
// There are some more lang items we want to hook that CTFE does not hook (yet).
29
33
if this. tcx . lang_items ( ) . align_offset_fn ( ) == Some ( instance. def . def_id ( ) ) {
30
34
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 ) ) ;
32
38
this. write_scalar ( Scalar :: from_uint ( n, dest. layout . size ) , dest) ?;
33
39
this. goto_block ( ret) ?;
34
40
return Ok ( None ) ;
@@ -51,13 +57,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
51
57
& mut self ,
52
58
ptr_op : OpTy < ' tcx , Tag > ,
53
59
align_op : OpTy < ' tcx , Tag > ,
54
- layout : ty:: layout:: TyLayout < ' tcx > ,
55
- ) -> InterpResult < ' tcx , u128 > {
60
+ ) -> InterpResult < ' tcx , Option < u128 > > {
56
61
let this = self . eval_context_mut ( ) ;
57
62
58
63
let req_align = this. force_bits (
59
64
this. read_scalar ( align_op) ?. not_undef ( ) ?,
60
- this. pointer_size ( )
65
+ this. pointer_size ( ) ,
61
66
) ? as usize ;
62
67
63
68
// FIXME: This should actually panic in the interpreted program
@@ -67,18 +72,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
67
72
68
73
let ptr_scalar = this. read_scalar ( ptr_op) ?. not_undef ( ) ?;
69
74
70
- if let Scalar :: Ptr ( ptr) = ptr_scalar {
75
+ if let Ok ( ptr) = this . force_ptr ( ptr_scalar) {
71
76
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
+ ) ) ;
74
84
}
75
85
}
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 )
83
89
}
84
90
}
0 commit comments