Skip to content

Commit 351c683

Browse files
committed
Use the given pointee type in <Builder as BuilderMethods>::load
This commit updates this method implementation to return an `RValue` of the given pointee type. While this parameter does not seem to have much significance at the moment, it will likely become important as cg_llvm and cg_ssa migrate to LLVM opaque pointers and get rid of pointercasts.
1 parent a225f0a commit 351c683

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/builder.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -652,18 +652,17 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
652652
unimplemented!();
653653
}
654654

655-
fn load(&mut self, _pointee_ty: Type<'gcc>, ptr: RValue<'gcc>, _align: Align) -> RValue<'gcc> {
656-
// TODO(antoyo): use ty.
655+
fn load(&mut self, pointee_ty: Type<'gcc>, ptr: RValue<'gcc>, _align: Align) -> RValue<'gcc> {
657656
let block = self.llbb();
658657
let function = block.get_function();
659658
// NOTE: instead of returning the dereference here, we have to assign it to a variable in
660659
// the current basic block. Otherwise, it could be used in another basic block, causing a
661660
// dereference after a drop, for instance.
662661
// TODO(antoyo): handle align of the load instruction.
662+
let ptr = self.context.new_cast(None, ptr, pointee_ty.make_pointer());
663663
let deref = ptr.dereference(None).to_rvalue();
664-
let value_type = deref.get_type();
665664
unsafe { RETURN_VALUE_COUNT += 1 };
666-
let loaded_value = function.new_local(None, value_type, &format!("loadedValue{}", unsafe { RETURN_VALUE_COUNT }));
665+
let loaded_value = function.new_local(None, pointee_ty, &format!("loadedValue{}", unsafe { RETURN_VALUE_COUNT }));
667666
block.add_assignment(None, loaded_value, deref);
668667
loaded_value.to_rvalue()
669668
}

0 commit comments

Comments
 (0)