[SYCL] Make sub_group non-user-constructible in preview mode - #23042
Open
KornevNikita wants to merge 2 commits into
Open
[SYCL] Make sub_group non-user-constructible in preview mode#23042KornevNikita wants to merge 2 commits into
KornevNikita wants to merge 2 commits into
Conversation
SYCL 2020 section 4.9.1.8 specifies sycl::sub_group with a deleted default
constructor, but the implementation declared it protected and defaulted
instead. That is not equivalent: a constructor that is defaulted on its first
declaration is not user-provided, so in C++17 sub_group remained an aggregate
and `sycl::sub_group{}` was a well-formed aggregate initialization, bypassing
the access check altogether.
Delete the default constructor and add a protected one taking a private tag.
Being user-provided, it also makes the class a non-aggregate, which closes the
C++17 loophole. sub_group objects are now created through that constructor in
nd_item::get_sub_group() and ext::oneapi::this_work_item::get_sub_group(),
both of which are already friends.
Applications may rely on the current permissive behavior, so the change is
guarded by __INTEL_PREVIEW_BREAKING_CHANGES.
Also stop the deprecated ext::oneapi::sub_group from initializing its base
through a private default constructor: copy-initializing the base works in
both modes and needs no guard.
Add a conformance test checking the SYCL 2020 synopsis, the common by-value
semantics, and that the class can be constructed neither directly nor as an
aggregate.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SYCL 2020 section 4.9.1.8 specifies
sycl::sub_groupwith a deleted defaultconstructor, but the implementation declared it
protectedand defaultedinstead. That is not equivalent: a constructor that is defaulted on its first
declaration is not user-provided, so in C++17
sub_groupremained anaggregate and
sycl::sub_group{}was a well-formed aggregate initializationthat bypassed the access check altogether:
This patch deletes the default constructor and adds a
protectedone taking aprivate tag. Being user-provided, it also makes the class a non-aggregate,
which closes the C++17 loophole.
sub_groupobjects are now created throughthat constructor in
nd_item::get_sub_group()andext::oneapi::this_work_item::get_sub_group(), both of which are alreadyfriends.
Applications may rely on the current permissive behavior, so the change is
guarded by
__INTEL_PREVIEW_BREAKING_CHANGES.The deprecated
ext::oneapi::sub_groupalso stops initializing its basethrough a private default constructor: copy-initializing the base works in
both modes and needs no guard.
Testing
New
sycl/test/basic_tests/sub_group_interface.cppchecks the SYCL 2020synopsis, the common by-value semantics, and that the class can be constructed
neither directly nor as an aggregate. It runs in four configurations:
{C++17, C++20} x {default,
-fpreview-breaking-changes}.Verified that legitimate ways of obtaining a sub-group still compile in all
four configurations (
nd_item::get_sub_group(), the free function queries,khr::this_sub_group(), copy/assign/compare, implicit conversion to thedeprecated
ext::oneapi::sub_group, group algorithms), and thatsycl::sub_group{}still compiles outside of preview mode.🤖 Generated with Claude Code