From ab949fdd64433749ebb7f8ef516ee2cdfe217a9d Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Sat, 17 Aug 2019 11:29:17 +0200 Subject: [PATCH] Cast only where necessary --- src/librustc_codegen_llvm/common.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/librustc_codegen_llvm/common.rs b/src/librustc_codegen_llvm/common.rs index a2026e1461d..19f18088579 100644 --- a/src/librustc_codegen_llvm/common.rs +++ b/src/librustc_codegen_llvm/common.rs @@ -333,20 +333,21 @@ fn from_const_alloc( offset: Size, ) -> PlaceRef<'tcx, &'ll Value> { assert_eq!(alloc.align, layout.align.abi); + let llty = self.type_ptr_to(layout.llvm_type(self)); let llval = if layout.size == Size::ZERO { let llval = self.const_usize(alloc.align.bytes()); - unsafe { llvm::LLVMConstIntToPtr(llval, self.type_ptr_to(self.type_i8p())) } + unsafe { llvm::LLVMConstIntToPtr(llval, llty) } } else { let init = const_alloc_to_llvm(self, alloc); let base_addr = self.static_addr_of(init, alloc.align, None); - unsafe { llvm::LLVMConstInBoundsGEP( + let llval = unsafe { llvm::LLVMConstInBoundsGEP( self.const_bitcast(base_addr, self.type_i8p()), &self.const_usize(offset.bytes()), 1, - )} + )}; + self.const_bitcast(llval, llty) }; - let llval = self.const_bitcast(llval, self.type_ptr_to(layout.llvm_type(self))); PlaceRef::new_sized(llval, layout, alloc.align) } -- GitLab