@@ -76,7 +76,7 @@ pub(crate) fn codegen_tls_ref<'tcx>(
76
76
pub ( crate ) fn eval_mir_constant < ' tcx > (
77
77
fx : & FunctionCx < ' _ , ' _ , ' tcx > ,
78
78
constant : & Constant < ' tcx > ,
79
- ) -> Option < ( ConstValue < ' tcx > , Ty < ' tcx > ) > {
79
+ ) -> Option < ( ConstValue , Ty < ' tcx > ) > {
80
80
let constant_kind = fx. monomorphize ( constant. literal ) ;
81
81
let uv = match constant_kind {
82
82
ConstantKind :: Ty ( const_) => match const_. kind ( ) {
@@ -127,7 +127,7 @@ pub(crate) fn codegen_constant_operand<'tcx>(
127
127
128
128
pub ( crate ) fn codegen_const_value < ' tcx > (
129
129
fx : & mut FunctionCx < ' _ , ' _ , ' tcx > ,
130
- const_val : ConstValue < ' tcx > ,
130
+ const_val : ConstValue ,
131
131
ty : Ty < ' tcx > ,
132
132
) -> CValue < ' tcx > {
133
133
let layout = fx. layout_of ( ty) ;
@@ -222,12 +222,18 @@ pub(crate) fn codegen_const_value<'tcx>(
222
222
CValue :: by_val ( val, layout)
223
223
}
224
224
} ,
225
- ConstValue :: ByRef { alloc, offset } => CValue :: by_ref (
226
- pointer_for_allocation ( fx, alloc)
227
- . offset_i64 ( fx, i64:: try_from ( offset. bytes ( ) ) . unwrap ( ) ) ,
228
- layout,
229
- ) ,
230
- ConstValue :: Slice { data, start, end } => {
225
+ ConstValue :: Indirect { alloc_id, offset } => {
226
+ let alloc = fx. tcx . global_alloc ( alloc_id) . unwrap_memory ( ) ;
227
+ // FIXME: avoid creating multiple allocations for the same AllocId?
228
+ CValue :: by_ref (
229
+ pointer_for_allocation ( fx, alloc)
230
+ . offset_i64 ( fx, i64:: try_from ( offset. bytes ( ) ) . unwrap ( ) ) ,
231
+ layout,
232
+ )
233
+ }
234
+ ConstValue :: Slice { alloc_id : Some ( alloc_id) , start, end } => {
235
+ let data = fx. tcx . global_alloc ( alloc_id) . unwrap_memory ( ) ;
236
+ // FIXME: avoid creating multiple allocations for the same AllocId?
231
237
let ptr = pointer_for_allocation ( fx, data)
232
238
. offset_i64 ( fx, i64:: try_from ( start) . unwrap ( ) )
233
239
. get_addr ( fx) ;
@@ -237,14 +243,23 @@ pub(crate) fn codegen_const_value<'tcx>(
237
243
. iconst ( fx. pointer_type , i64:: try_from ( end. checked_sub ( start) . unwrap ( ) ) . unwrap ( ) ) ;
238
244
CValue :: by_val_pair ( ptr, len, layout)
239
245
}
246
+ ConstValue :: Slice { alloc_id : None , start, end } => {
247
+ assert_eq ! ( start, end) ;
248
+ // Empty slice at `start`.
249
+ // FIXME: `start` could in principle be big enough to overflow into the negative.
250
+ // How should the clif value be constructed then?
251
+ let addr = fx. bcx . ins ( ) . iconst ( fx. pointer_type , i64:: try_from ( start) . unwrap ( ) ) ;
252
+ let len = fx. bcx . ins ( ) . iconst ( fx. pointer_type , 0 ) ;
253
+ CValue :: by_val_pair ( addr, len, layout)
254
+ }
240
255
}
241
256
}
242
257
243
258
fn pointer_for_allocation < ' tcx > (
244
259
fx : & mut FunctionCx < ' _ , ' _ , ' tcx > ,
245
260
alloc : ConstAllocation < ' tcx > ,
246
261
) -> crate :: pointer:: Pointer {
247
- let alloc_id = fx. tcx . create_memory_alloc ( alloc) ;
262
+ let alloc_id = fx. tcx . reserve_and_set_memory_alloc ( alloc) ;
248
263
let data_id = data_id_for_alloc_id (
249
264
& mut fx. constants_cx ,
250
265
& mut * fx. module ,
@@ -477,7 +492,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
477
492
pub ( crate ) fn mir_operand_get_const_val < ' tcx > (
478
493
fx : & FunctionCx < ' _ , ' _ , ' tcx > ,
479
494
operand : & Operand < ' tcx > ,
480
- ) -> Option < ConstValue < ' tcx > > {
495
+ ) -> Option < ConstValue > {
481
496
match operand {
482
497
Operand :: Constant ( const_) => Some ( eval_mir_constant ( fx, const_) . unwrap ( ) . 0 ) ,
483
498
// FIXME(rust-lang/rust#85105): Casts like `IMM8 as u32` result in the const being stored
0 commit comments