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 | ea22adbabdd0f5fbc033101eaeed6d3e304ede08 (patch) | |
| tree | 9977ba50327f6e04a3752f9a84d6f5110454b3ad /compiler/rustc_codegen_cranelift/src | |
| parent | 0692db1a9082380e027f354912229dfd6af37e78 (diff) | |
| download | rust-ea22adbabdd0f5fbc033101eaeed6d3e304ede08.tar.gz rust-ea22adbabdd0f5fbc033101eaeed6d3e304ede08.zip | |
adjust constValue::Slice to work for arbitrary slice types
Diffstat (limited to 'compiler/rustc_codegen_cranelift/src')
| -rw-r--r-- | compiler/rustc_codegen_cranelift/src/constant.rs | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs index 02468684ba0..151674b2d6d 100644 --- a/compiler/rustc_codegen_cranelift/src/constant.rs +++ b/compiler/rustc_codegen_cranelift/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) } } |
