diff options
| author | Ralf Jung <post@ralfj.de> | 2021-07-12 18:22:15 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2021-07-14 18:17:46 +0200 |
| commit | d4f7dd670226a4235ea4cf900c14eb9c6a536843 (patch) | |
| tree | fb5b4287bd53cee0633df3b455ebffa753be6b06 /compiler/rustc_codegen_llvm/src | |
| parent | 5aff6dd07a562a2cba3c57fc3460a72acb6bef46 (diff) | |
| download | rust-d4f7dd670226a4235ea4cf900c14eb9c6a536843.tar.gz rust-d4f7dd670226a4235ea4cf900c14eb9c6a536843.zip | |
CTFE/Miri engine Pointer type overhaul: make Scalar-to-Pointer conversion infallible
This resolves all the problems we had around "normalizing" the representation of a Scalar in case it carries a Pointer value: we can just use Pointer if we want to have a value taht we are sure is already normalized.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/common.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/consts.rs | 2 |
2 files changed, 5 insertions, 4 deletions
diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index df5ad8ecc27..a73932ee1b5 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -244,7 +244,8 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { } } Scalar::Ptr(ptr) => { - let (base_addr, base_addr_space) = match self.tcx.global_alloc(ptr.alloc_id) { + let (alloc_id, offset) = ptr.into_parts(); + let (base_addr, base_addr_space) = match self.tcx.global_alloc(alloc_id) { GlobalAlloc::Memory(alloc) => { let init = const_alloc_to_llvm(self, alloc); let value = match alloc.mutability { @@ -252,7 +253,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { _ => self.static_addr_of(init, alloc.align, None), }; if !self.sess().fewer_names() { - llvm::set_value_name(value, format!("{:?}", ptr.alloc_id).as_bytes()); + llvm::set_value_name(value, format!("{:?}", alloc_id).as_bytes()); } (value, AddressSpace::DATA) } @@ -269,7 +270,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { let llval = unsafe { llvm::LLVMConstInBoundsGEP( self.const_bitcast(base_addr, self.type_i8p_ext(base_addr_space)), - &self.const_usize(ptr.offset.bytes()), + &self.const_usize(offset.bytes()), 1, ) }; diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index e50d5506e22..71a387bfcac 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -25,7 +25,7 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll let pointer_size = dl.pointer_size.bytes() as usize; let mut next_offset = 0; - for &(offset, ((), alloc_id)) in alloc.relocations().iter() { + for &(offset, alloc_id) in alloc.relocations().iter() { let offset = offset.bytes(); assert_eq!(offset as usize as u64, offset); let offset = offset as usize; |
