Skip to content

Commit 33e9a6b

Browse files
committed
Pass type when creating atomic load
Instead of determining it from the pointer type, explicitly pass the type to load.
1 parent 619c27a commit 33e9a6b

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,15 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
428428

429429
fn atomic_load(
430430
&mut self,
431+
ty: &'ll Type,
431432
ptr: &'ll Value,
432433
order: rustc_codegen_ssa::common::AtomicOrdering,
433434
size: Size,
434435
) -> &'ll Value {
435436
unsafe {
436437
let load = llvm::LLVMRustBuildAtomicLoad(
437438
self.llbuilder,
439+
ty,
438440
ptr,
439441
UNNAMED,
440442
AtomicOrdering::from_generic(order),

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,7 @@ extern "C" {
16311631
// Atomic Operations
16321632
pub fn LLVMRustBuildAtomicLoad(
16331633
B: &Builder<'a>,
1634+
ElementType: &'a Type,
16341635
PointerVal: &'a Value,
16351636
Name: *const c_char,
16361637
Order: AtomicOrdering,

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,15 +448,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
448448
if ty.is_unsafe_ptr() {
449449
// Some platforms do not support atomic operations on pointers,
450450
// so we cast to integer first...
451-
let ptr_llty = bx.type_ptr_to(bx.type_isize());
451+
let llty = bx.type_isize();
452+
let ptr_llty = bx.type_ptr_to(llty);
452453
source = bx.pointercast(source, ptr_llty);
453-
}
454-
let result = bx.atomic_load(source, order, size);
455-
if ty.is_unsafe_ptr() {
454+
let result = bx.atomic_load(llty, source, order, size);
456455
// ... and then cast the result back to a pointer
457456
bx.inttoptr(result, bx.backend_type(layout))
458457
} else {
459-
result
458+
bx.atomic_load(bx.backend_type(layout), source, order, size)
460459
}
461460
} else {
462461
return invalid_monomorphization(ty);

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ pub trait BuilderMethods<'a, 'tcx>:
139139

140140
fn load(&mut self, ptr: Self::Value, align: Align) -> Self::Value;
141141
fn volatile_load(&mut self, ptr: Self::Value) -> Self::Value;
142-
fn atomic_load(&mut self, ptr: Self::Value, order: AtomicOrdering, size: Size) -> Self::Value;
142+
fn atomic_load(
143+
&mut self,
144+
ty: Self::Type,
145+
ptr: Self::Value,
146+
order: AtomicOrdering,
147+
size: Size,
148+
) -> Self::Value;
143149
fn load_operand(&mut self, place: PlaceRef<'tcx, Self::Value>)
144150
-> OperandRef<'tcx, Self::Value>;
145151

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,10 @@ extern "C" void LLVMRustSetFastMath(LLVMValueRef V) {
349349
}
350350

351351
extern "C" LLVMValueRef
352-
LLVMRustBuildAtomicLoad(LLVMBuilderRef B, LLVMValueRef Source, const char *Name,
353-
LLVMAtomicOrdering Order) {
352+
LLVMRustBuildAtomicLoad(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Source,
353+
const char *Name, LLVMAtomicOrdering Order) {
354354
Value *Ptr = unwrap(Source);
355-
Type *Ty = Ptr->getType()->getPointerElementType();
356-
LoadInst *LI = unwrap(B)->CreateLoad(Ty, Ptr, Name);
355+
LoadInst *LI = unwrap(B)->CreateLoad(unwrap(Ty), Ptr, Name);
357356
LI->setAtomic(fromRust(Order));
358357
return wrap(LI);
359358
}

0 commit comments

Comments
 (0)