@@ -190,7 +190,6 @@ pub(crate) fn codegen_const_value<'tcx>(
190
190
let alloc_kind = fx. tcx . get_global_alloc ( ptr. alloc_id ) ;
191
191
let base_addr = match alloc_kind {
192
192
Some ( GlobalAlloc :: Memory ( alloc) ) => {
193
- fx. constants_cx . todo . push ( TodoItem :: Alloc ( ptr. alloc_id ) ) ;
194
193
let data_id = data_id_for_alloc_id (
195
194
& mut fx. constants_cx ,
196
195
fx. module ,
@@ -249,12 +248,11 @@ pub(crate) fn codegen_const_value<'tcx>(
249
248
}
250
249
}
251
250
252
- pub ( crate ) fn pointer_for_allocation < ' tcx > (
251
+ fn pointer_for_allocation < ' tcx > (
253
252
fx : & mut FunctionCx < ' _ , ' _ , ' tcx > ,
254
253
alloc : & ' tcx Allocation ,
255
254
) -> crate :: pointer:: Pointer {
256
255
let alloc_id = fx. tcx . create_memory_alloc ( alloc) ;
257
- fx. constants_cx . todo . push ( TodoItem :: Alloc ( alloc_id) ) ;
258
256
let data_id =
259
257
data_id_for_alloc_id ( & mut fx. constants_cx , & mut * fx. module , alloc_id, alloc. mutability ) ;
260
258
@@ -266,12 +264,13 @@ pub(crate) fn pointer_for_allocation<'tcx>(
266
264
crate :: pointer:: Pointer :: new ( global_ptr)
267
265
}
268
266
269
- fn data_id_for_alloc_id (
267
+ pub ( crate ) fn data_id_for_alloc_id (
270
268
cx : & mut ConstantCx ,
271
269
module : & mut dyn Module ,
272
270
alloc_id : AllocId ,
273
271
mutability : rustc_hir:: Mutability ,
274
272
) -> DataId {
273
+ cx. todo . push ( TodoItem :: Alloc ( alloc_id) ) ;
275
274
* cx. anon_allocs . entry ( alloc_id) . or_insert_with ( || {
276
275
module. declare_anonymous_data ( mutability == rustc_hir:: Mutability :: Mut , false ) . unwrap ( )
277
276
} )
@@ -352,7 +351,14 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
352
351
GlobalAlloc :: Memory ( alloc) => alloc,
353
352
GlobalAlloc :: Function ( _) | GlobalAlloc :: Static ( _) => unreachable ! ( ) ,
354
353
} ;
355
- let data_id = data_id_for_alloc_id ( cx, module, alloc_id, alloc. mutability ) ;
354
+ let data_id = * cx. anon_allocs . entry ( alloc_id) . or_insert_with ( || {
355
+ module
356
+ . declare_anonymous_data (
357
+ alloc. mutability == rustc_hir:: Mutability :: Mut ,
358
+ false ,
359
+ )
360
+ . unwrap ( )
361
+ } ) ;
356
362
( data_id, alloc, None )
357
363
}
358
364
TodoItem :: Static ( def_id) => {
@@ -415,7 +421,6 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
415
421
continue ;
416
422
}
417
423
GlobalAlloc :: Memory ( target_alloc) => {
418
- cx. todo . push ( TodoItem :: Alloc ( reloc) ) ;
419
424
data_id_for_alloc_id ( cx, module, reloc, target_alloc. mutability )
420
425
}
421
426
GlobalAlloc :: Static ( def_id) => {
0 commit comments