Skip to content

Commit 82333cc

Browse files
authored
Merge pull request #35 from antoyo/fix/wrong-types-atomic
Fix wrong type for atomic functions
2 parents a958af8 + 79e80a9 commit 82333cc

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

src/builder.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,9 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
149149
let dst = self.context.new_cast(None, dst, volatile_void_ptr_type);
150150
let expected = self.context.new_cast(None, cmp.get_address(None), void_ptr_type);
151151

152-
// NOTE: not sure why, but we need to cast to the signed type.
153-
let new_src_type =
154-
if size == 64 {
155-
// TODO: use sized types (uint64_t, …) when libgccjit supports them.
156-
self.cx.long_type
157-
}
158-
else {
159-
src.get_type().to_signed(&self.cx)
160-
};
161-
let src = self.context.new_cast(None, src, new_src_type);
152+
// NOTE: not sure why, but we have the wrong type here.
153+
let int_type = compare_exchange.get_param(2).to_rvalue().get_type();
154+
let src = self.context.new_cast(None, src, int_type);
162155
self.context.new_call(None, compare_exchange, &[dst, expected, src, weak, order, failure_order])
163156
}
164157

@@ -1114,7 +1107,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
11141107
// FIXME: fix libgccjit to allow comparing an integer type with an aligned integer type because
11151108
// the following cast is required to avoid this error:
11161109
// gcc_jit_context_new_call: mismatching types for argument 2 of function "__atomic_store_4": assignment to param arg1 (type: int) from loadedValue3577 (type: unsigned int __attribute__((aligned(4))))
1117-
let int_type = self.cx.int_type_from_size(size.bytes());
1110+
let int_type = atomic_store.get_param(1).to_rvalue().get_type();
11181111
let value = self.context.new_cast(None, value, int_type);
11191112
self.llbb()
11201113
.add_eval(None, self.context.new_call(None, atomic_store, &[ptr, value, ordering]));
@@ -1555,15 +1548,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
15551548
let void_ptr_type = self.context.new_type::<*mut ()>();
15561549
let volatile_void_ptr_type = void_ptr_type.make_volatile();
15571550
let dst = self.context.new_cast(None, dst, volatile_void_ptr_type);
1558-
// NOTE: not sure why, but we need to cast to the signed type.
1559-
let new_src_type =
1560-
if size == 8 {
1561-
// TODO: use sized types (uint64_t, …) when libgccjit supports them.
1562-
self.cx.long_type
1563-
}
1564-
else {
1565-
src.get_type().to_signed(&self.cx)
1566-
};
1551+
// NOTE: not sure why, but we have the wrong type here.
1552+
let new_src_type = atomic_function.get_param(1).to_rvalue().get_type();
15671553
let src = self.context.new_cast(None, src, new_src_type);
15681554
let res = self.context.new_call(None, atomic_function, &[dst, src, order]);
15691555
self.context.new_cast(None, res, src.get_type())

0 commit comments

Comments
 (0)