Skip to content

Commit a2efaf0

Browse files
committed
Auto merge of rust-lang#118705 - WaffleLapkin:codegen-atomic-exhange-untuple, r=cjgillot
Change `rustc_codegen_ssa`'s `atomic_cmpxchg` interface to return a pair of values Doesn't change much, but a little nicer that way.
2 parents eca05c6 + 69b5a9f commit a2efaf0

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/builder.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
12961296
}
12971297

12981298
// Atomic Operations
1299-
fn atomic_cmpxchg(&mut self, dst: RValue<'gcc>, cmp: RValue<'gcc>, src: RValue<'gcc>, order: AtomicOrdering, failure_order: AtomicOrdering, weak: bool) -> RValue<'gcc> {
1299+
fn atomic_cmpxchg(&mut self, dst: RValue<'gcc>, cmp: RValue<'gcc>, src: RValue<'gcc>, order: AtomicOrdering, failure_order: AtomicOrdering, weak: bool) -> (RValue<'gcc>, RValue<'gcc>) {
13001300
let expected = self.current_func().new_local(None, cmp.get_type(), "expected");
13011301
self.llbb().add_assignment(None, expected, cmp);
13021302
// NOTE: gcc doesn't support a failure memory model that is stronger than the success
@@ -1310,20 +1310,12 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
13101310
};
13111311
let success = self.compare_exchange(dst, expected, src, order, failure_order, weak);
13121312

1313-
let pair_type = self.cx.type_struct(&[src.get_type(), self.bool_type], false);
1314-
let result = self.current_func().new_local(None, pair_type, "atomic_cmpxchg_result");
1315-
let align = Align::from_bits(64).expect("align"); // TODO(antoyo): use good align.
1313+
// NOTE: since success contains the call to the intrinsic, it must be added to the basic block before
1314+
// expected so that we store expected after the call.
1315+
let success_var = self.current_func().new_local(None, self.bool_type, "success");
1316+
self.llbb().add_assignment(None, success_var, success);
13161317

1317-
let value_type = result.to_rvalue().get_type();
1318-
if let Some(struct_type) = value_type.is_struct() {
1319-
self.store(success, result.access_field(None, struct_type.get_field(1)).get_address(None), align);
1320-
// NOTE: since success contains the call to the intrinsic, it must be stored before
1321-
// expected so that we store expected after the call.
1322-
self.store(expected.to_rvalue(), result.access_field(None, struct_type.get_field(0)).get_address(None), align);
1323-
}
1324-
// TODO(antoyo): handle when value is not a struct.
1325-
1326-
result.to_rvalue()
1318+
(expected.to_rvalue(), success_var.to_rvalue())
13271319
}
13281320

13291321
fn atomic_rmw(&mut self, op: AtomicRmwBinOp, dst: RValue<'gcc>, src: RValue<'gcc>, order: AtomicOrdering) -> RValue<'gcc> {

0 commit comments

Comments
 (0)