Skip to content

Commit

Permalink
Rollup merge of rust-lang#98385 - m-ou-se:llvm-12-memory-order, r=pet…
Browse files Browse the repository at this point in the history
…rochenkov

Work around llvm 12's memory ordering restrictions.

Older llvm has the pre-C++17 restriction on success and failure memory ordering, requiring the former to be at least as strong as the latter. So, for llvm 12, this upgrades the success ordering to a stronger one if necessary.

See rust-lang#68464
  • Loading branch information
JohnTitor authored Jun 26, 2022
2 parents 645e5c4 + 9033576 commit 7c39776
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,11 +1064,25 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
dst: &'ll Value,
cmp: &'ll Value,
src: &'ll Value,
order: rustc_codegen_ssa::common::AtomicOrdering,
mut order: rustc_codegen_ssa::common::AtomicOrdering,
failure_order: rustc_codegen_ssa::common::AtomicOrdering,
weak: bool,
) -> &'ll Value {
let weak = if weak { llvm::True } else { llvm::False };
if llvm_util::get_version() < (13, 0, 0) {
use rustc_codegen_ssa::common::AtomicOrdering::*;
// Older llvm has the pre-C++17 restriction on
// success and failure memory ordering,
// requiring the former to be at least as strong as the latter.
// So, for llvm 12, we upgrade the success ordering to a stronger
// one if necessary.
match (order, failure_order) {
(Relaxed, Acquire) => order = Acquire,
(Release, Acquire) => order = AcquireRelease,
(_, SequentiallyConsistent) => order = SequentiallyConsistent,
_ => {}
}
}
unsafe {
llvm::LLVMRustBuildAtomicCmpXchg(
self.llbuilder,
Expand Down

0 comments on commit 7c39776

Please sign in to comment.