Skip to content

Using atomic_ref operator= causes compiler error #4172

@Pennycook

Description

@Pennycook

Describe the bug
Although operator= is defined in atomic_ref.hpp, the compiler does not consider it a viable overload.

To Reproduce
Change the test in https://github.com/intel/llvm/blob/sycl/sycl/test/atomic_ref/store.cpp to use operator= instead:

    q.submit([&](handler &cgh) {
      auto st = store_buf.template get_access<access::mode::read_write>(cgh);
      cgh.parallel_for<store_kernel<T>>(range<1>(N), [=](item<1> it) {
        size_t gid = it.get_id(0);
        auto atm = atomic_ref<T, memory_order::relaxed, memory_scope::device,
                              access::address_space::global_space>(st[0]);
        atm = T(gid);
      });
    });

Trying to compile the test gives the following error (repeated several times for each type in the test):

store.cpp:31:13: error: no viable overloaded '='
        atm = T(gid);
        ~~~ ^ ~~~~~~
store.cpp:54:3: note: in instantiation of function template specialization 'store_test<int>' requested here
  store_test<int>(q, N);
  ^
/home/sjpennyc/llvm/build//bin/../include/sycl/CL/sycl/ONEAPI/atomic_ref.hpp:662:7: note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'int' to 'const sycl::ONEAPI::atomic_ref<int, sycl::ONEAPI::memory_order::relaxed, sycl::ONEAPI::memory_scope::device, sycl::access::address_space::global_space>' for 1st argument
class atomic_ref : public detail::atomic_ref_impl<T, DefaultOrder, DefaultScope,

Environment:

  • OS: Linux
  • Target device and vendor: All devices
  • DPC++ version: Last tested with 66ef4eb
  • Dependencies version: N/A

Additional context
We didn't catch this because we don't have tests for all of the operators in atomic_ref. We should add tests for operator T() and operator=(T) at least, since they're intended to be short-hands for load and store (which we do test).

I've tried to fix this myself, but can't make sense of the error. I thought perhaps that operator= needed to be defined in some additional classes in the hierarchy, but nothing I've tried so far has worked. Opening an issue so we don't lose track of this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions