@@ -7,7 +7,7 @@ use hir::CRATE_HIR_ID;
7
7
use rustc_hir:: { self as hir, def_id:: DefId , definitions:: DefPathData } ;
8
8
use rustc_index:: IndexVec ;
9
9
use rustc_middle:: mir;
10
- use rustc_middle:: mir:: interpret:: { ErrorHandled , InvalidMetaKind , ReportedErrorInfo } ;
10
+ use rustc_middle:: mir:: interpret:: { alloc_range , ErrorHandled , InvalidMetaKind , ReportedErrorInfo } ;
11
11
use rustc_middle:: query:: TyCtxtAt ;
12
12
use rustc_middle:: ty:: layout:: {
13
13
self , FnAbiError , FnAbiOfHelpers , FnAbiRequest , LayoutError , LayoutOf , LayoutOfHelpers ,
@@ -17,6 +17,7 @@ use rustc_middle::ty::{self, GenericArgsRef, ParamEnv, Ty, TyCtxt, TypeFoldable,
17
17
use rustc_mir_dataflow:: storage:: always_storage_live_locals;
18
18
use rustc_session:: Limit ;
19
19
use rustc_span:: Span ;
20
+ use rustc_target:: abi:: { self , Abi } ;
20
21
use rustc_target:: abi:: { call:: FnAbi , Align , HasDataLayout , Size , TargetDataLayout } ;
21
22
22
23
use super :: {
@@ -1069,23 +1070,36 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1069
1070
} )
1070
1071
}
1071
1072
1072
- pub fn eval_global (
1073
+ pub fn eval_global_scalar (
1073
1074
& self ,
1074
1075
instance : ty:: Instance < ' tcx > ,
1075
- ) -> InterpResult < ' tcx , MPlaceTy < ' tcx , M :: Provenance > > {
1076
+ ) -> InterpResult < ' tcx , Scalar < M :: Provenance > > {
1076
1077
let gid = GlobalId { instance, promoted : None } ;
1077
- // For statics we pick `ParamEnv::reveal_all`, because statics don't have generics
1078
- // and thus don't care about the parameter environment. While we could just use
1079
- // `self.param_env`, that would mean we invoke the query to evaluate the static
1080
- // with different parameter environments, thus causing the static to be evaluated
1081
- // multiple times.
1082
- let param_env = if self . tcx . is_static ( gid. instance . def_id ( ) ) {
1083
- ty:: ParamEnv :: reveal_all ( )
1078
+ let ( alloc_id, alloc) = if self . tcx . is_static ( gid. instance . def_id ( ) ) {
1079
+ (
1080
+ self . tcx . reserve_and_set_static_alloc ( gid. instance . def_id ( ) ) ,
1081
+ self . ctfe_query ( |tcx| tcx. eval_static_initializer ( gid. instance . def_id ( ) ) ) ?,
1082
+ )
1084
1083
} else {
1085
- self . param_env
1084
+ let val = self . ctfe_query ( |tcx| tcx. eval_to_allocation_raw ( self . param_env . and ( gid) ) ) ?;
1085
+ ( val. alloc_id , self . tcx . global_alloc ( val. alloc_id ) . unwrap_memory ( ) )
1086
1086
} ;
1087
- let val = self . ctfe_query ( |tcx| tcx. eval_to_allocation_raw ( param_env. and ( gid) ) ) ?;
1088
- self . raw_const_to_mplace ( val)
1087
+
1088
+ let ty = instance. ty ( self . tcx . tcx , self . param_env ) ;
1089
+ let layout = self . layout_of ( ty) ?;
1090
+ let read_provenance = matches ! (
1091
+ layout. abi,
1092
+ Abi :: Scalar ( abi:: Scalar :: Initialized { value: abi:: Primitive :: Pointer ( ..) , .. } )
1093
+ ) ;
1094
+
1095
+ let scalar = alloc
1096
+ . inner ( )
1097
+ . read_scalar ( self , alloc_range ( Size :: ZERO , layout. size ) , read_provenance)
1098
+ . map_err ( |err| err. to_interp_error ( alloc_id) ) ?;
1099
+ Ok ( match scalar {
1100
+ Scalar :: Ptr ( ptr, size) => Scalar :: Ptr ( self . global_base_pointer ( ptr) ?, size) ,
1101
+ Scalar :: Int ( int) => Scalar :: Int ( int) ,
1102
+ } )
1089
1103
}
1090
1104
1091
1105
pub fn eval_mir_constant (
0 commit comments