Skip to content

Commit 69740b2

Browse files
committed
Prohibited use of the sycl_kernel_entry_point attribute with a non-static member function with an explicit object parameter.
1 parent 8a4fc3f commit 69740b2

File tree

5 files changed

+50
-14
lines changed

5 files changed

+50
-14
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ following requirements.
551551

552552
* Has a non-deduced ``void`` return type.
553553
* Is not a constructor or destructor.
554+
* Is not a non-static member function with an explicit object parameter.
554555
* Is not a C variadic function.
555556
* Is not a coroutine.
556557
* Is not defined as deleted or as defaulted.

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13066,7 +13066,8 @@ def err_sycl_entry_point_invalid : Error<
1306613066
"constructor|destructor|coroutine|"
1306713067
"constexpr function|consteval function|"
1306813068
"function declared with the 'noreturn' attribute|"
13069-
"function defined with a function try block}1">;
13069+
"function defined with a function try block|"
13070+
"function with an explicit object parameter}1">;
1307013071
def err_sycl_entry_point_invalid_redeclaration : Error<
1307113072
"the %0 kernel name argument does not match prior"
1307213073
" declaration%diff{: $ vs $|}1,2">;

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,13 @@ void SemaSYCL::CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD) {
325325
<< SKEPAttr << /*destructor*/ 4;
326326
SKEPAttr->setInvalidAttr();
327327
}
328+
if (const auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
329+
if (MD->isExplicitObjectMemberFunction()) {
330+
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
331+
<< SKEPAttr << /*function with an explicit object parameter*/ 10;
332+
SKEPAttr->setInvalidAttr();
333+
}
334+
}
328335

329336
if (FD->isVariadic()) {
330337
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)

clang/test/SemaSYCL/sycl-kernel-entry-point-attr-appertainment.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,29 @@ struct B42 {
377377
// expected-warning@+1 {{declaration does not declare anything}}
378378
[[clang::sycl_kernel_entry_point(BADKN<42>)]];
379379
};
380+
381+
#if __cplusplus >= 202302L
382+
struct B43 {
383+
// expected-error@+2 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a function with an explicit object parameter}}
384+
template<typename KNT>
385+
[[clang::sycl_kernel_entry_point(KNT)]]
386+
void bad43(this B43) {}
387+
};
388+
#endif
389+
390+
#if __cplusplus >= 202302L
391+
struct B44 {
392+
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a function with an explicit object parameter}}
393+
[[clang::sycl_kernel_entry_point(BADKN<44>)]]
394+
void bad44(this B44);
395+
};
396+
#endif
397+
398+
#if __cplusplus >= 202302L
399+
template<typename KNT>
400+
struct B45 {
401+
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a function with an explicit object parameter}}
402+
[[clang::sycl_kernel_entry_point(KNT)]]
403+
void bad45(this B45);
404+
};
405+
#endif

clang/test/SemaSYCL/sycl-kernel-entry-point-attr-this.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -std=c++17 -fsycl-is-host -verify %s
22
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -std=c++17 -fsycl-is-device -verify %s
3-
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -std=c++20 -fsycl-is-host -verify -DCXX20 %s
4-
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -std=c++20 -fsycl-is-device -verify -DCXX20 %s
5-
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -std=c++23 -fsycl-is-host -verify -DCXX23 %s
6-
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -std=c++23 -fsycl-is-device -verify -DCXX23 %s
3+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -std=c++20 -fsycl-is-host -verify %s
4+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -std=c++20 -fsycl-is-device -verify %s
5+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -std=c++23 -fsycl-is-host -verify %s
6+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -std=c++23 -fsycl-is-device -verify %s
77

88
// These tests validate diagnostics for invalid use of 'this' in the body of
99
// a function declared with the sycl_kernel_entry_point attribute.
@@ -82,7 +82,7 @@ struct S7 {
8282
template void S7<KN<7,0>, false>::ok7();
8383
template void S7<KN<7,1>, true>::ok7();
8484

85-
#if defined(CXX20)
85+
#if __cplusplus >= 202002L
8686
template<typename KN, typename T>
8787
struct S8 {
8888
void mf(T);
@@ -98,14 +98,6 @@ struct S9 {
9898
template void S9<KN<9>, int>::ok9();
9999
#endif
100100

101-
#if defined(CXX23)
102-
struct S10 {
103-
[[clang::sycl_kernel_entry_point(KN<10>)]] void ok10(this S10 self) {
104-
(void)self;
105-
}
106-
};
107-
#endif
108-
109101

110102
////////////////////////////////////////////////////////////////////////////////
111103
// Invalid declarations.
@@ -185,3 +177,12 @@ struct B8 {
185177
};
186178
// expected-note@+1 {{in instantiation of member function 'B8<BADKN<8>>::bad8' requested here}}
187179
template void B8<BADKN<8>>::bad8();
180+
181+
#if __cplusplus >= 202302L
182+
struct B9 {
183+
// expected-error@+1 {{the 'clang::sycl_kernel_entry_point' attribute cannot be applied to a function with an explicit object parameter}}
184+
[[clang::sycl_kernel_entry_point(BADKN<9>)]] void bad9(this B9 self) {
185+
(void)self;
186+
}
187+
};
188+
#endif

0 commit comments

Comments
 (0)