@@ -76,7 +76,7 @@ pub(crate) fn codegen_tls_ref<'tcx>(
7676pub ( crate ) fn eval_mir_constant < ' tcx > (
7777 fx : & FunctionCx < ' _ , ' _ , ' tcx > ,
7878 constant : & Constant < ' tcx > ,
79- ) -> Option < ( ConstValue < ' tcx > , Ty < ' tcx > ) > {
79+ ) -> Option < ( ConstValue , Ty < ' tcx > ) > {
8080 let constant_kind = fx. monomorphize ( constant. literal ) ;
8181 let uv = match constant_kind {
8282 ConstantKind :: Ty ( const_) => match const_. kind ( ) {
@@ -127,7 +127,7 @@ pub(crate) fn codegen_constant_operand<'tcx>(
127127
128128pub ( crate ) fn codegen_const_value < ' tcx > (
129129 fx : & mut FunctionCx < ' _ , ' _ , ' tcx > ,
130- const_val : ConstValue < ' tcx > ,
130+ const_val : ConstValue ,
131131 ty : Ty < ' tcx > ,
132132) -> CValue < ' tcx > {
133133 let layout = fx. layout_of ( ty) ;
@@ -222,12 +222,18 @@ pub(crate) fn codegen_const_value<'tcx>(
222222 CValue :: by_val ( val, layout)
223223 }
224224 } ,
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?
231237 let ptr = pointer_for_allocation ( fx, data)
232238 . offset_i64 ( fx, i64:: try_from ( start) . unwrap ( ) )
233239 . get_addr ( fx) ;
@@ -237,14 +243,23 @@ pub(crate) fn codegen_const_value<'tcx>(
237243 . iconst ( fx. pointer_type , i64:: try_from ( end. checked_sub ( start) . unwrap ( ) ) . unwrap ( ) ) ;
238244 CValue :: by_val_pair ( ptr, len, layout)
239245 }
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+ }
240255 }
241256}
242257
243258fn pointer_for_allocation < ' tcx > (
244259 fx : & mut FunctionCx < ' _ , ' _ , ' tcx > ,
245260 alloc : ConstAllocation < ' tcx > ,
246261) -> 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) ;
248263 let data_id = data_id_for_alloc_id (
249264 & mut fx. constants_cx ,
250265 & mut * fx. module ,
@@ -477,7 +492,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
477492pub ( crate ) fn mir_operand_get_const_val < ' tcx > (
478493 fx : & FunctionCx < ' _ , ' _ , ' tcx > ,
479494 operand : & Operand < ' tcx > ,
480- ) -> Option < ConstValue < ' tcx > > {
495+ ) -> Option < ConstValue > {
481496 match operand {
482497 Operand :: Constant ( const_) => Some ( eval_mir_constant ( fx, const_) . unwrap ( ) . 0 ) ,
483498 // FIXME(rust-lang/rust#85105): Casts like `IMM8 as u32` result in the const being stored
0 commit comments