-
Notifications
You must be signed in to change notification settings - Fork 823
[clang][SYCL] Skip allocation diagnostic in unevaluated contexts #21614
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
Open
schittir
wants to merge
5
commits into
intel:sycl
Choose a base branch
from
schittir:unevaluated_context
base: sycl
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+140
−1
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2dd5b52
Skip allocation diagnostic in unevaluated contexts
schittir 2b83e3a
Update comments
schittir 4749875
Add template test case
schittir 099e6e3
Remove unnecessary static_asserts
schittir 73125ae
Remove asserts outside the kernel and restore the ones within it.
schittir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
138 changes: 138 additions & 0 deletions
138
clang/test/SemaSYCL/new-operator-unevaluated-context.cpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| // RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -verify -fsyntax-only -std=c++20 -triple spir64 -Wno-unused-value %s | ||
|
|
||
| // Tests that the "SYCL kernel cannot allocate storage" diagnostic is not | ||
| // emitted in unevaluated contexts such as C++20 concepts, requires clauses, | ||
| // decltype, sizeof, etc. | ||
|
|
||
| #include "sycl.hpp" | ||
|
|
||
| namespace std { | ||
| class type_info; | ||
| typedef __typeof__(sizeof(int)) size_t; | ||
| } // namespace std | ||
|
|
||
| // Stub implementation for operator new | ||
| void *operator new(std::size_t) { | ||
| return reinterpret_cast<void *>(1); | ||
| } | ||
|
|
||
|
|
||
| template <typename T> | ||
| concept Allocatable = requires { | ||
| // No error expected - this is in an unevaluated context | ||
| ::new T; | ||
| }; | ||
|
|
||
| template <typename T> | ||
| concept AllocatableArray = requires { | ||
| // No error expected - this is in an unevaluated context | ||
| ::new T[10]; | ||
| }; | ||
|
|
||
| template <typename T> | ||
| requires requires { ::new T; } | ||
| void test_requires_clause() {} | ||
|
|
||
| template <typename T> | ||
| requires requires { ::new T[5]; } | ||
| void test_requires_clause_array() {} | ||
|
|
||
|
|
||
| void test_decltype() { | ||
| // No error expected - inside decltype | ||
| decltype(new int) ptr1; | ||
| decltype(new int[10]) ptr2; | ||
| } | ||
|
|
||
|
|
||
| void test_sizeof() { | ||
| // No error expected - inside sizeof | ||
| constexpr std::size_t s1 = sizeof(new int); | ||
| constexpr std::size_t s2 = sizeof(new int[10]); | ||
| } | ||
|
|
||
|
|
||
| void test_alignof() { | ||
| // No error expected - inside alignof of the result type | ||
| constexpr std::size_t a1 = alignof(int*); | ||
| using PtrType = decltype(new int); | ||
| constexpr std::size_t a2 = alignof(PtrType); | ||
| } | ||
|
|
||
|
|
||
| void test_noexcept() noexcept(noexcept(new int)) {} | ||
|
|
||
|
|
||
| // Usage in kernel should emit diagnostic | ||
| void actual_allocation() { | ||
| // expected-error@+1 {{SYCL kernel cannot allocate storage}} | ||
| int *ptr = new int; | ||
| } | ||
|
|
||
| void actual_array_allocation() { | ||
| // expected-error@+1 {{SYCL kernel cannot allocate storage}} | ||
| int *ptr = new int[10]; | ||
| } | ||
|
|
||
| template <typename T> | ||
| void actual_allocation() { | ||
| // expected-error@+1 {{SYCL kernel cannot allocate storage}} | ||
| T *ptr = new T; | ||
| } | ||
|
|
||
| template <typename T> | ||
| void actual_array_allocation() { | ||
| // expected-error@+1 {{SYCL kernel cannot allocate storage}} | ||
| T *ptr = new T[10]; | ||
| } | ||
|
|
||
|
|
||
| int main() { | ||
| sycl::queue q; | ||
|
|
||
| q.submit([&](sycl::handler &h) { | ||
| h.single_task<class TestConcepts>([]() { | ||
| // These should all work without errors | ||
| static_assert(Allocatable<int>); | ||
| static_assert(AllocatableArray<double>); | ||
|
|
||
| test_requires_clause<int>(); | ||
| test_requires_clause_array<float>(); | ||
|
|
||
| test_decltype(); | ||
| test_sizeof(); | ||
| test_alignof(); | ||
| test_noexcept(); | ||
| }); | ||
| }); | ||
|
|
||
| q.submit([&](sycl::handler &h) { | ||
| h.single_task<class TestActualAlloc>([&]() { | ||
| // expected-note@Inputs/sycl.hpp:322 {{called by 'kernel_single_task<TestActualAlloc}} | ||
| actual_allocation(); // expected-note {{called by 'operator()'}} | ||
| }); | ||
| }); | ||
|
|
||
| q.submit([&](sycl::handler &h) { | ||
| h.single_task<class TestActualArrayAlloc>([&]() { | ||
| // expected-note@Inputs/sycl.hpp:322 {{called by 'kernel_single_task<TestActualArrayAlloc}} | ||
| actual_array_allocation(); // expected-note {{called by 'operator()'}} | ||
| }); | ||
| }); | ||
|
|
||
| q.submit([&](sycl::handler &h) { | ||
| h.single_task<class TestTemplatedAlloc>([&]() { | ||
| // expected-note@Inputs/sycl.hpp:* {{called by 'kernel_single_task}} | ||
| actual_allocation<int>(); // expected-note {{called by 'operator()'}} | ||
| }); | ||
| }); | ||
|
|
||
| q.submit([&](sycl::handler &h) { | ||
| h.single_task<class TestTemplatedArrayAlloc>([&]() { | ||
| // expected-note@Inputs/sycl.hpp:* {{called by 'kernel_single_task}} | ||
| actual_array_allocation<float>(); // expected-note {{called by 'operator()'}} | ||
| }); | ||
| }); | ||
|
|
||
| return 0; | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.