Skip to content

Fix wrong type for atomic functions #35

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

Merged
merged 1 commit into from
Jun 18, 2021
Merged
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
26 changes: 6 additions & 20 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,9 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
let dst = self.context.new_cast(None, dst, volatile_void_ptr_type);
let expected = self.context.new_cast(None, cmp.get_address(None), void_ptr_type);

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

Expand Down Expand Up @@ -1114,7 +1107,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
// FIXME: fix libgccjit to allow comparing an integer type with an aligned integer type because
// the following cast is required to avoid this error:
// 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))))
let int_type = self.cx.int_type_from_size(size.bytes());
let int_type = atomic_store.get_param(1).to_rvalue().get_type();
let value = self.context.new_cast(None, value, int_type);
self.llbb()
.add_eval(None, self.context.new_call(None, atomic_store, &[ptr, value, ordering]));
Expand Down Expand Up @@ -1555,15 +1548,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
let void_ptr_type = self.context.new_type::<*mut ()>();
let volatile_void_ptr_type = void_ptr_type.make_volatile();
let dst = self.context.new_cast(None, dst, volatile_void_ptr_type);
// NOTE: not sure why, but we need to cast to the signed type.
let new_src_type =
if size == 8 {
// TODO: use sized types (uint64_t, …) when libgccjit supports them.
self.cx.long_type
}
else {
src.get_type().to_signed(&self.cx)
};
// NOTE: not sure why, but we have the wrong type here.
let new_src_type = atomic_function.get_param(1).to_rvalue().get_type();
let src = self.context.new_cast(None, src, new_src_type);
let res = self.context.new_call(None, atomic_function, &[dst, src, order]);
self.context.new_cast(None, res, src.get_type())
Expand Down