Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

561847 Variable copied when it could be moved in kernel.cpp

Open Beginner friendly
#23,463 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp
Domain
backend

Research direction

Start at the return statement in sycl/source/kernel.cpp around lines 246-256, where Queue is passed by value to impl->queryMaxNumWorkGroups. The other three call sites in sycl/source/detail/kernel_impl.hpp (around lines 422-444) already wrap the queue in std::move, so the fix is to match them. Done when that call uses std::move(Queue) and the SYCL build and existing tests still pass; the device-parameter refactor described in the issue is optional and larger.

Written by the indexing model from the issue text.

Description

bug Coverity
Describe the bug
250  impl->getAdapter().call_nocheck<sycl::detail::UrApiKind::urKernelSetExecInfo>(
251      impl->getHandleRef(), UR_KERNEL_EXEC_INFO_CACHE_CONFIG,
252      sizeof(ur_kernel_cache_config_t), nullptr, &(ExecInfo.CacheConfig));
253  sycl::queue Queue{Dev};
254  return impl->queryMaxNumWorkGroups<Dimensions>(

CID 561847: (#undefined of undefined): Variable copied when it could be moved (COPY_INSTEAD_OF_MOVE)
copy_constructor_call: Queue is passed-by-value as parameter to queryMaxNumWorkGroups, when it could be moved instead.[show details]
     	Use std::move(Queue) instead of Queue.

https://github.com/intel/llvm/blob/43d56c72d78f51a24fc25fec4ba4bd295dcb9925/sycl/source/kernel.cpp#L246-L256

To reproduce

Static analysis finding, reported by the Coverity Scan build of intel/llvm. No
runtime reproducer — the effect is a redundant refcount operation, not incorrect
behaviour.

Environment

N/A — static analysis finding, backend independent.

Additional context

The finding is valid. kernel_impl::queryMaxNumWorkGroups
takes its queue by value, and Queue is a local whose last use is this call —
the call is the return statement. So the copy constructor runs for nothing:
an atomic increment on the shared_ptr<queue_impl> plus the matching decrement
when Queue goes out of scope.

The three other call sites of the same function already use the moving form, at
kernel_impl.hpp:422,
:433
and :444,
where the queue-based ext_oneapi_get_info overloads forward with
std::move(Queue). kernel.cpp:255 is the one site of four that doesn't:

  return impl->queryMaxNumWorkGroups<Dimensions>(
      std::move(Queue), Range, Bytes + ExecInfo.DynamicWorkGroupMem);

There is a larger inefficiency at the same spot, which the one-line fix leaves
in place.
The only use of the queue in the callee is
kernel_impl.hpp:383:

  auto Device = Queue.get_device();

Everything afterwards uses only Device, including the
exceedsOccupancyResourceLimits fallback. Meanwhile kernel::queryMaxNumWorkGroups
already has the device — it is the Dev parameter — and line 253 constructs a
full sycl::queue from it just so the callee can unwrap it again. That
construction creates a queue_impl and a backend queue handle, i.e. a
urQueueCreate/urQueueRelease round trip per query call, which is far more
expensive than the copy Coverity flagged. It also gives an informational query a
side effect and an unrelated failure mode, since queue construction can throw for
reasons that have nothing to do with the query.

A cleaner fix would be to change kernel_impl::queryMaxNumWorkGroups to take a
const device & and have the three queue-based callers pass
Queue.get_device(), which removes the synthetic queue entirely and makes the
copy question moot. That is ABI-safe: the function is a template defined in a
detail header with no explicit instantiations of its own, so only internal
callers change and the exported instantiations of
kernel::queryMaxNumWorkGroups keep their signatures.

Either fix resolves the CID; the second also removes the queue construction.

AI (Claude Code): the finding is from the Coverity scan; the analysis and suggested fixes above are the agent's.

Dominant language
LLVM
Stars
1.5k
Forks
869
Avg merge
3d 1h
Merged PRs (30d)
194

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from intel/llvm

All issues in intel/llvm

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.