Don't create data object for zero sized allocations
This commit is contained in:
parent
82dd93fb57
commit
9ad96205cb
@ -137,18 +137,23 @@ pub(crate) fn codegen_const_value<'tcx>(
|
||||
let alloc_id = prov.alloc_id();
|
||||
let base_addr = match fx.tcx.global_alloc(alloc_id) {
|
||||
GlobalAlloc::Memory(alloc) => {
|
||||
let data_id = data_id_for_alloc_id(
|
||||
&mut fx.constants_cx,
|
||||
fx.module,
|
||||
alloc_id,
|
||||
alloc.inner().mutability,
|
||||
);
|
||||
let local_data_id =
|
||||
fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||
if fx.clif_comments.enabled() {
|
||||
fx.add_comment(local_data_id, format!("{:?}", alloc_id));
|
||||
if alloc.inner().len() == 0 {
|
||||
assert_eq!(offset, Size::ZERO);
|
||||
fx.bcx.ins().iconst(fx.pointer_type, alloc.inner().align.bytes() as i64)
|
||||
} else {
|
||||
let data_id = data_id_for_alloc_id(
|
||||
&mut fx.constants_cx,
|
||||
fx.module,
|
||||
alloc_id,
|
||||
alloc.inner().mutability,
|
||||
);
|
||||
let local_data_id =
|
||||
fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||
if fx.clif_comments.enabled() {
|
||||
fx.add_comment(local_data_id, format!("{:?}", alloc_id));
|
||||
}
|
||||
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
|
||||
}
|
||||
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
|
||||
}
|
||||
GlobalAlloc::Function(instance) => {
|
||||
let func_id = crate::abi::import_function(fx.tcx, fx.module, instance);
|
||||
|
Loading…
x
Reference in New Issue
Block a user