From 838042aa4e9f7b313cd79420d7613dc5af5343e5 Mon Sep 17 00:00:00 2001 From: Tomasz Miąsko Date: Sun, 1 Aug 2021 00:00:00 +0000 Subject: Prepare struct_gep for opaque pointers Imlement struct_gep using LLVMBuildStructGEP2 which takes an explicit type argument instead of deriving it from a pointer type. --- compiler/rustc_codegen_ssa/src/mir/operand.rs | 5 +++-- compiler/rustc_codegen_ssa/src/mir/place.rs | 8 ++++++-- compiler/rustc_codegen_ssa/src/traits/builder.rs | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) (limited to 'compiler/rustc_codegen_ssa/src') diff --git a/compiler/rustc_codegen_ssa/src/mir/operand.rs b/compiler/rustc_codegen_ssa/src/mir/operand.rs index 3e8386bc88f..cfb2befdf91 100644 --- a/compiler/rustc_codegen_ssa/src/mir/operand.rs +++ b/compiler/rustc_codegen_ssa/src/mir/operand.rs @@ -311,14 +311,15 @@ impl<'a, 'tcx, V: CodegenObject> OperandValue { Abi::ScalarPair(ref a, ref b) => (a, b), _ => bug!("store_with_flags: invalid ScalarPair layout: {:#?}", dest.layout), }; + let ty = bx.backend_type(dest.layout); let b_offset = a_scalar.value.size(bx).align_to(b_scalar.value.align(bx).abi); - let llptr = bx.struct_gep(dest.llval, 0); + let llptr = bx.struct_gep(ty, dest.llval, 0); let val = bx.from_immediate(a); let align = dest.align; bx.store_with_flags(val, llptr, align, flags); - let llptr = bx.struct_gep(dest.llval, 1); + let llptr = bx.struct_gep(ty, dest.llval, 1); let val = bx.from_immediate(b); let align = dest.align.restrict_for_offset(b_offset); bx.store_with_flags(val, llptr, align, flags); diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index 66d9d1a1e0c..b8940245400 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -103,7 +103,8 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { if offset == a.value.size(bx.cx()).align_to(b.value.align(bx.cx()).abi) => { // Offset matches second field. - bx.struct_gep(self.llval, 1) + let ty = bx.backend_type(self.layout); + bx.struct_gep(ty, self.llval, 1) } Abi::Scalar(_) | Abi::ScalarPair(..) | Abi::Vector { .. } if field.is_zst() => { // ZST fields are not included in Scalar, ScalarPair, and Vector layouts, so manually offset the pointer. @@ -119,7 +120,10 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { self.layout ); } - _ => bx.struct_gep(self.llval, bx.cx().backend_field_index(self.layout, ix)), + _ => { + let ty = bx.backend_type(self.layout); + bx.struct_gep(ty, self.llval, bx.cx().backend_field_index(self.layout, ix)) + } }; PlaceRef { // HACK(eddyb): have to bitcast pointers until LLVM removes pointee types. diff --git a/compiler/rustc_codegen_ssa/src/traits/builder.rs b/compiler/rustc_codegen_ssa/src/traits/builder.rs index f0c232a97bc..6c3f52b1b19 100644 --- a/compiler/rustc_codegen_ssa/src/traits/builder.rs +++ b/compiler/rustc_codegen_ssa/src/traits/builder.rs @@ -178,7 +178,7 @@ pub trait BuilderMethods<'a, 'tcx>: fn gep(&mut self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value; fn inbounds_gep(&mut self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value; - fn struct_gep(&mut self, ptr: Self::Value, idx: u64) -> Self::Value; + fn struct_gep(&mut self, ty: Self::Type, ptr: Self::Value, idx: u64) -> Self::Value; fn trunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value; fn sext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value; -- cgit 1.4.1-3-g733a5