Skip to content

rustllvm: Use target alignment for atomic load/store (fix incoming) #6649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1571,13 +1571,15 @@ pub mod llvm {
pub unsafe fn LLVMBuildAtomicLoad(B: BuilderRef,
PointerVal: ValueRef,
Name: *c_char,
Order: AtomicOrdering)
Order: AtomicOrdering,
Alignment: c_uint)
-> ValueRef;

pub unsafe fn LLVMBuildAtomicStore(B: BuilderRef,
Val: ValueRef,
Ptr: ValueRef,
Order: AtomicOrdering)
Order: AtomicOrdering,
Alignment: c_uint)
-> ValueRef;

pub unsafe fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
Expand Down
8 changes: 5 additions & 3 deletions src/librustc/middle/trans/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use lib::llvm::{Opcode, IntPredicate, RealPredicate, False};
use lib::llvm::{ValueRef, TypeRef, BasicBlockRef, BuilderRef, ModuleRef};
use lib;
use middle::trans::common::*;
use middle::trans::machine::llalign_of_min;
use syntax::codemap::span;

use core::hashmap::HashMap;
Expand Down Expand Up @@ -544,7 +545,8 @@ pub fn AtomicLoad(cx: block, PointerVal: ValueRef, order: AtomicOrdering) -> Val
return llvm::LLVMGetUndef(ccx.int_type);
}
count_insn(cx, "load.atomic");
return llvm::LLVMBuildAtomicLoad(B(cx), PointerVal, noname(), order);
let align = llalign_of_min(*ccx, ccx.int_type);
return llvm::LLVMBuildAtomicLoad(B(cx), PointerVal, noname(), order, align as c_uint);
}
}

Expand All @@ -558,7 +560,6 @@ pub fn LoadRangeAssert(cx: block, PointerVal: ValueRef, lo: c_ulonglong,
let min = llvm::LLVMConstInt(t, lo, signed);
let max = llvm::LLVMConstInt(t, hi, signed);


do vec::as_imm_buf([min, max]) |ptr, len| {
llvm::LLVMSetMetadata(value, lib::llvm::MD_range as c_uint,
llvm::LLVMMDNode(ptr, len as c_uint));
Expand Down Expand Up @@ -586,7 +587,8 @@ pub fn AtomicStore(cx: block, Val: ValueRef, Ptr: ValueRef, order: AtomicOrderin
val_str(cx.ccx().tn, Val),
val_str(cx.ccx().tn, Ptr));
count_insn(cx, "store.atomic");
llvm::LLVMBuildAtomicStore(B(cx), Val, Ptr, order);
let align = llalign_of_min(cx.ccx(), cx.ccx().int_type);
llvm::LLVMBuildAtomicStore(B(cx), Val, Ptr, order, align as c_uint);
}
}

Expand Down
14 changes: 8 additions & 6 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,22 +548,24 @@ extern "C" LLVMTypeRef LLVMMetadataType(void) {
extern "C" LLVMValueRef LLVMBuildAtomicLoad(LLVMBuilderRef B,
LLVMValueRef source,
const char* Name,
AtomicOrdering order) {
AtomicOrdering order,
unsigned alignment) {
LoadInst* li = new LoadInst(unwrap(source),0);
li->setVolatile(true);
li->setAtomic(order);
li->setAlignment(sizeof(intptr_t));
li->setAlignment(alignment);
return wrap(unwrap(B)->Insert(li, Name));
}

extern "C" LLVMValueRef LLVMBuildAtomicStore(LLVMBuilderRef B,
LLVMValueRef val,
LLVMValueRef target,
AtomicOrdering order) {
LLVMValueRef val,
LLVMValueRef target,
AtomicOrdering order,
unsigned alignment) {
StoreInst* si = new StoreInst(unwrap(val),unwrap(target));
si->setVolatile(true);
si->setAtomic(order);
si->setAlignment(sizeof(intptr_t));
si->setAlignment(alignment);
return wrap(unwrap(B)->Insert(si));
}

Expand Down