adjust constValue::Slice to work for arbitrary slice types
This commit is contained in:
parent
247d38d174
commit
dd48b5e393
@ -184,15 +184,11 @@ pub(crate) fn codegen_const_value<'tcx>(
|
|||||||
.offset_i64(fx, i64::try_from(offset.bytes()).unwrap()),
|
.offset_i64(fx, i64::try_from(offset.bytes()).unwrap()),
|
||||||
layout,
|
layout,
|
||||||
),
|
),
|
||||||
ConstValue::Slice { data, start, end } => {
|
ConstValue::Slice { data, meta } => {
|
||||||
let alloc_id = fx.tcx.reserve_and_set_memory_alloc(data);
|
let alloc_id = fx.tcx.reserve_and_set_memory_alloc(data);
|
||||||
let ptr = pointer_for_allocation(fx, alloc_id)
|
let ptr = pointer_for_allocation(fx, alloc_id).get_addr(fx);
|
||||||
.offset_i64(fx, i64::try_from(start).unwrap())
|
// FIXME: the `try_from` here can actually fail, e.g. for very long ZST slices.
|
||||||
.get_addr(fx);
|
let len = fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(meta).unwrap());
|
||||||
let len = fx
|
|
||||||
.bcx
|
|
||||||
.ins()
|
|
||||||
.iconst(fx.pointer_type, i64::try_from(end.checked_sub(start).unwrap()).unwrap());
|
|
||||||
CValue::by_val_pair(ptr, len, layout)
|
CValue::by_val_pair(ptr, len, layout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user