Skip to content

Commit 9033576

Browse files
committed
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.
1 parent 392d272 commit 9033576

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1064,11 +1064,25 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
10641064
dst: &'ll Value,
10651065
cmp: &'ll Value,
10661066
src: &'ll Value,
1067-
order: rustc_codegen_ssa::common::AtomicOrdering,
1067+
mut order: rustc_codegen_ssa::common::AtomicOrdering,
10681068
failure_order: rustc_codegen_ssa::common::AtomicOrdering,
10691069
weak: bool,
10701070
) -> &'ll Value {
10711071
let weak = if weak { llvm::True } else { llvm::False };
1072+
if llvm_util::get_version() < (13, 0, 0) {
1073+
use rustc_codegen_ssa::common::AtomicOrdering::*;
1074+
// Older llvm has the pre-C++17 restriction on
1075+
// success and failure memory ordering,
1076+
// requiring the former to be at least as strong as the latter.
1077+
// So, for llvm 12, we upgrade the success ordering to a stronger
1078+
// one if necessary.
1079+
match (order, failure_order) {
1080+
(Relaxed, Acquire) => order = Acquire,
1081+
(Release, Acquire) => order = AcquireRelease,
1082+
(_, SequentiallyConsistent) => order = SequentiallyConsistent,
1083+
_ => {}
1084+
}
1085+
}
10721086
unsafe {
10731087
llvm::LLVMRustBuildAtomicCmpXchg(
10741088
self.llbuilder,

0 commit comments

Comments
 (0)