Skip to content

Commit ab949fd

Browse files
committed
Cast only where necessary
1 parent 1fb854a commit ab949fd

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/librustc_codegen_llvm/common.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -333,20 +333,21 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
333333
offset: Size,
334334
) -> PlaceRef<'tcx, &'ll Value> {
335335
assert_eq!(alloc.align, layout.align.abi);
336+
let llty = self.type_ptr_to(layout.llvm_type(self));
336337
let llval = if layout.size == Size::ZERO {
337338
let llval = self.const_usize(alloc.align.bytes());
338-
unsafe { llvm::LLVMConstIntToPtr(llval, self.type_ptr_to(self.type_i8p())) }
339+
unsafe { llvm::LLVMConstIntToPtr(llval, llty) }
339340
} else {
340341
let init = const_alloc_to_llvm(self, alloc);
341342
let base_addr = self.static_addr_of(init, alloc.align, None);
342343

343-
unsafe { llvm::LLVMConstInBoundsGEP(
344+
let llval = unsafe { llvm::LLVMConstInBoundsGEP(
344345
self.const_bitcast(base_addr, self.type_i8p()),
345346
&self.const_usize(offset.bytes()),
346347
1,
347-
)}
348+
)};
349+
self.const_bitcast(llval, llty)
348350
};
349-
let llval = self.const_bitcast(llval, self.type_ptr_to(layout.llvm_type(self)));
350351
PlaceRef::new_sized(llval, layout, alloc.align)
351352
}
352353

0 commit comments

Comments
 (0)