Skip to content

Commit ce9f490

Browse files
committed
Fix volatile_load
1 parent 16b3da8 commit ce9f490

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/builder.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
751751
loaded_value.to_rvalue()
752752
}
753753

754-
fn volatile_load(&mut self, _ty: Type<'gcc>, ptr: RValue<'gcc>) -> RValue<'gcc> {
755-
// TODO(antoyo): use ty.
756-
let ptr = self.context.new_cast(None, ptr, ptr.get_type().make_volatile());
754+
fn volatile_load(&mut self, ty: Type<'gcc>, ptr: RValue<'gcc>) -> RValue<'gcc> {
755+
let ptr = self.context.new_cast(None, ptr, ty.make_volatile().make_pointer());
757756
ptr.dereference(None).to_rvalue()
758757
}
759758

src/intrinsic/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,15 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
143143

144144
sym::volatile_load | sym::unaligned_volatile_load => {
145145
let tp_ty = fn_args.type_at(0);
146-
let mut ptr = args[0].immediate();
147-
if let PassMode::Cast { cast: ty, .. } = &fn_abi.ret.mode {
148-
ptr = self.pointercast(ptr, self.type_ptr_to(ty.gcc_type(self)));
149-
}
150-
let load = self.volatile_load(ptr.get_type(), ptr);
146+
let ptr = args[0].immediate();
147+
let load =
148+
if let PassMode::Cast { cast: ty, pad_i32: _ } = &fn_abi.ret.mode {
149+
let gcc_ty = ty.gcc_type(self);
150+
self.volatile_load(gcc_ty, ptr)
151+
}
152+
else {
153+
self.volatile_load(self.layout_of(tp_ty).gcc_type(self), ptr)
154+
};
151155
// TODO(antoyo): set alignment.
152156
self.to_immediate(load, self.layout_of(tp_ty))
153157
}

0 commit comments

Comments
 (0)