Skip to content

guard against self-exchange in the get_completion_scheduler query#1854

Merged
ericniebler merged 1 commit intoNVIDIA:mainfrom
ericniebler:get-completion-scheduler-self-exchange-bug
Feb 17, 2026
Merged

guard against self-exchange in the get_completion_scheduler query#1854
ericniebler merged 1 commit intoNVIDIA:mainfrom
ericniebler:get-completion-scheduler-self-exchange-bug

Conversation

@ericniebler
Copy link
Collaborator

in get_completion_scheduler_t, we have the following:

__prev = std::exchange(__sch, __read_query_t{}(__sch, __env...));

when __sch.query(get_completion_scheduler) returns a reference to *this, the code above is essentially doing std::exchange(__sch, __sch). std::exchange does:

template <class T, class U = T>
T exchange(T& old_value, U&& new_value) {
  auto old = std::move(old_value);
  old_value = std::forward<U>(new_value);
  return old;
}

when &old_value == &new_value, the first line puts new_value into a moved-from state. then we assign that moved-from object to old_value, which is UB in most cases, and never what you want to happen.

@ericniebler ericniebler force-pushed the get-completion-scheduler-self-exchange-bug branch from c5fe6f5 to 0e17846 Compare February 17, 2026 01:09
@ericniebler ericniebler merged commit 044d43b into NVIDIA:main Feb 17, 2026
22 checks passed
@ericniebler ericniebler deleted the get-completion-scheduler-self-exchange-bug branch February 17, 2026 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant