Skip to content

Commit 7532add

Browse files
Rollup merge of #157127 - scottmcm:tweak-layout-of-alternative, r=nikic
cg_LLVM: Stop needing an alloca for volatile loads This ended up also being reimplementing it to not use `load` of the `llvm_type`, since without doing that everything blew up horribly. cc the zulip conversation [#t-opsem > Defining volatile splitting @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/136281-t-opsem/topic/Defining.20volatile.20splitting/near/597451615). And while I'm here, improve the tests to check that the unaligned ones are actually unaligned, since `unaligned_volatile_load::<u8>` doesn't actually test anything. r? @nikic cc @RalfJung MCP tracking issue rust-lang/rust#153250
2 parents a292cee + 515a89c commit 7532add

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/builder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
993993
loaded_value.to_rvalue()
994994
}
995995

996-
fn volatile_load(&mut self, ty: Type<'gcc>, ptr: RValue<'gcc>) -> RValue<'gcc> {
996+
fn volatile_load(&mut self, ty: Type<'gcc>, ptr: RValue<'gcc>, _: Align) -> RValue<'gcc> {
997+
// FIXME(antoyo): set alignment.
997998
let ptr = self.context.new_cast(self.location, ptr, ty.make_volatile().make_pointer());
998999
// (FractalFir): We insert a local here, to ensure this volatile load can't move across
9991000
// blocks.

src/intrinsic/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod simd;
55
use std::iter;
66

77
use gccjit::{ComparisonOp, Function, FunctionType, RValue, ToRValue, Type, UnaryOp};
8-
use rustc_abi::{BackendRepr, HasDataLayout, WrappingRange};
8+
use rustc_abi::{Align, BackendRepr, HasDataLayout, WrappingRange};
99
use rustc_codegen_ssa::base::wants_msvc_seh;
1010
use rustc_codegen_ssa::common::IntPredicate;
1111
use rustc_codegen_ssa::errors::InvalidMonomorphization;
@@ -368,8 +368,9 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
368368

369369
sym::volatile_load | sym::unaligned_volatile_load => {
370370
let ptr = args[0].immediate();
371-
let load = self.volatile_load(result.layout.gcc_type(self), ptr);
372-
// FIXME(antoyo): set alignment.
371+
let abi_align = result_layout.align.abi;
372+
let ptr_align = if name == sym::volatile_load { abi_align } else { Align::ONE };
373+
let load = self.volatile_load(result.layout.gcc_type(self), ptr, ptr_align);
373374
if let BackendRepr::Scalar(scalar) = result.layout.backend_repr {
374375
self.to_immediate_scalar(load, scalar)
375376
} else {

0 commit comments

Comments
 (0)