diff options
| author | Ralf Jung <post@ralfj.de> | 2023-09-15 15:59:47 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-09-19 20:17:43 +0200 |
| commit | dd48b5e393814e1dbde3e8eb21bc111d301da6f6 (patch) | |
| tree | a9f7b11f9fce69f2262b938e8bc582e64362352b | |
| parent | 247d38d174c08421fc6558e0e466e9499d533658 (diff) | |
| download | rust-dd48b5e393814e1dbde3e8eb21bc111d301da6f6.tar.gz rust-dd48b5e393814e1dbde3e8eb21bc111d301da6f6.zip | |
adjust constValue::Slice to work for arbitrary slice types
| -rw-r--r-- | src/constant.rs | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/constant.rs b/src/constant.rs index 02468684ba0..151674b2d6d 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -184,15 +184,11 @@ pub(crate) fn codegen_const_value<'tcx>( .offset_i64(fx, i64::try_from(offset.bytes()).unwrap()), layout, ), - ConstValue::Slice { data, start, end } => { + ConstValue::Slice { data, meta } => { let alloc_id = fx.tcx.reserve_and_set_memory_alloc(data); - let ptr = pointer_for_allocation(fx, alloc_id) - .offset_i64(fx, i64::try_from(start).unwrap()) - .get_addr(fx); - let len = fx - .bcx - .ins() - .iconst(fx.pointer_type, i64::try_from(end.checked_sub(start).unwrap()).unwrap()); + let ptr = pointer_for_allocation(fx, alloc_id).get_addr(fx); + // FIXME: the `try_from` here can actually fail, e.g. for very long ZST slices. + let len = fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(meta).unwrap()); CValue::by_val_pair(ptr, len, layout) } } |
