From 4013e094f59109779f1294adad96caa2eebf7e2d Mon Sep 17 00:00:00 2001 From: Tomasz Miąsko Date: Sat, 31 Jul 2021 00:00:00 +0000 Subject: Prepare gep for opaque pointers Implement gep using LLVMBuildGEP2 which takes an explicit type argument instead of deriving it from a pointer type. --- compiler/rustc_codegen_ssa/src/mir/intrinsic.rs | 4 +++- compiler/rustc_codegen_ssa/src/mir/place.rs | 4 ++-- compiler/rustc_codegen_ssa/src/traits/builder.rs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'compiler/rustc_codegen_ssa') diff --git a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs index 56ff1b3934c..b7ca19aba89 100644 --- a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs +++ b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs @@ -121,9 +121,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { bx.inbounds_gep(ptr, &[offset]) } sym::arith_offset => { + let ty = substs.type_at(0); + let layout = bx.layout_of(ty); let ptr = args[0].immediate(); let offset = args[1].immediate(); - bx.gep(ptr, &[offset]) + bx.gep(bx.backend_type(layout), ptr, &[offset]) } sym::copy => { copy_intrinsic( diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index b8940245400..40961839e3f 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -109,7 +109,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { 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. let byte_ptr = bx.pointercast(self.llval, bx.cx().type_i8p()); - bx.gep(byte_ptr, &[bx.const_usize(offset.bytes())]) + bx.gep(bx.cx().type_i8(), byte_ptr, &[bx.const_usize(offset.bytes())]) } Abi::Scalar(_) | Abi::ScalarPair(..) => { // All fields of Scalar and ScalarPair layouts must have been handled by this point. @@ -189,7 +189,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { // Cast and adjust pointer. let byte_ptr = bx.pointercast(self.llval, bx.cx().type_i8p()); - let byte_ptr = bx.gep(byte_ptr, &[offset]); + let byte_ptr = bx.gep(bx.cx().type_i8(), byte_ptr, &[offset]); // Finally, cast back to the type expected. let ll_fty = bx.cx().backend_type(field); diff --git a/compiler/rustc_codegen_ssa/src/traits/builder.rs b/compiler/rustc_codegen_ssa/src/traits/builder.rs index 6c3f52b1b19..5e8ebcf9682 100644 --- a/compiler/rustc_codegen_ssa/src/traits/builder.rs +++ b/compiler/rustc_codegen_ssa/src/traits/builder.rs @@ -176,7 +176,7 @@ pub trait BuilderMethods<'a, 'tcx>: size: Size, ); - fn gep(&mut self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value; + fn gep(&mut self, ty: Self::Type, 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, ty: Self::Type, ptr: Self::Value, idx: u64) -> Self::Value; -- cgit 1.4.1-3-g733a5