-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL] the first kernel function declaration should be added with attribute #18405
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
base: sycl
Are you sure you want to change the base?
[SYCL] the first kernel function declaration should be added with attribute #18405
Conversation
clang/lib/Sema/SemaSYCL.cpp
Outdated
} | ||
bool FirstDecl = true; | ||
clang::SourceLocation Loc = FD->getLocation(); | ||
while (!Redecls.empty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK a FunctionDecl should have a member isFirstDecl
. Can we just loop over FD->redecls()
, and issue an error in case an attribute is applied to a decl returning false from isFirstDecl
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reworked
@@ -12676,7 +12676,8 @@ def err_free_function_variadic_args : Error< | |||
"free function kernel cannot be a variadic function">; | |||
def err_free_function_return_type : Error< | |||
"SYCL free function kernel should have return type 'void'">; | |||
|
|||
def err_free_function_first_occurrence_missing_attr: Error< | |||
"the first occurrence of kernel free function should be declared with attribute add_ir_attributes_function with 'sycl-nd-range-kernel' or 'sycl-single-task-kernel'">; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"the first occurrence of kernel free function should be declared with attribute add_ir_attributes_function with 'sycl-nd-range-kernel' or 'sycl-single-task-kernel'">; | |
"the first occurrence of SYCL kernel free function should be declared with 'sycl-nd-range-kernel' or 'sycl-single-task-kernel' compile time properties">; |
for (const auto &NameValuePair : NameValuePairs) { | ||
if (NameValuePair.first == "sycl-nd-range-kernel" || | ||
NameValuePair.first == "sycl-single-task-kernel") { | ||
clang::SourceLocation Loc = FD->getLocation(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure clang nns is not required here.
clang::SourceLocation Loc = FD->getLocation(); | |
SourceLocation Loc = FD->getLocation(); |
@@ -10,6 +10,22 @@ foo(int start, ...) { // expected-error {{free function kernel cannot be a varia | |||
foo1(int start, ...) { // expected-error {{free function kernel cannot be a variadic function}} | |||
} | |||
|
|||
// expected-note@+1 {{conflicting attribute is here}} | |||
[[__sycl_detail__::add_ir_attributes_function("sycl-single-task-kernel", 1)]] void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please extend the testing with the following cases:
- There are more than 2 redeclarations and the attribute is not on the first one
- Templated free function
- Overloads with the same name, different set of arguments and attributes applied to each should not trigger the diag
Docs Defining a free function kernel contains:
The property must appear on the first declaration of the function in the translation unit. Redeclarations of the function may optionally be decorated with the same property if the property argument is the same. The effect is the same regardless of whether redeclarations are so decorated.
This PR changes
isFreeFunction
to define if the first occurrence of kernel free function has attribute or not. New clang diagnostics was added to highlight that first occurrence does not have attribute but the next has.