Skip to content

Commit 7077a87

Browse files
committed
Disallow applying the sycl_kernel_entry_point attribute to functions with a function-try-block.
The SYCL 2020 specification prohibits the use of C++ exceptions in device functions. Even if exceptions were not prohibited, it is unclear what the semantics would be for an exception that escapes the SYCL kernel entry point function; the boundary between host and device code could be an implicit noexcept boundary that results in program termination if violated, or the exception could perhaps be propagated to host code via the SYCL library. The semantics of function-try-blocks is that an exception raised in the function body that escapes to a function-try-block handler is implicitly rethrown. Pending support for C++ exceptions in device code and clear semantics for handling them at the host-device boundary, this change makes use of the sycl_kernel_entry_point attribute with a function defined with a function-try-block an error.
1 parent cef6177 commit 7077a87

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ following requirements.
487487
* Is not a C variadic function.
488488
* Is not a coroutine.
489489
* Is not defined as deleted or as defaulted.
490+
* Is not defined with a function try block.
490491
* Is not declared with the ``constexpr`` or ``consteval`` specifiers.
491492
* Is not declared with the ``[[noreturn]]`` attribute.
492493

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12457,7 +12457,8 @@ def err_sycl_entry_point_invalid : Error<
1245712457
"'sycl_kernel_entry_point' attribute cannot be applied to a"
1245812458
" %select{non-static member function|variadic function|deleted function|"
1245912459
"defaulted function|constexpr function|consteval function|"
12460-
"function declared with the 'noreturn' attribute|coroutine}0">;
12460+
"function declared with the 'noreturn' attribute|coroutine|"
12461+
"function defined with a function try block}0">;
1246112462
def err_sycl_entry_point_invalid_redeclaration : Error<
1246212463
"'sycl_kernel_entry_point' kernel name argument does not match prior"
1246312464
" declaration%diff{: $ vs $|}0,1">;

clang/lib/Sema/SemaDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15983,6 +15983,10 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
1598315983
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
1598415984
<< /*coroutine*/ 7;
1598515985
SKEPAttr->setInvalidAttr();
15986+
} else if (Body && isa<CXXTryStmt>(Body)) {
15987+
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
15988+
<< /*function defined with a function try block*/ 8;
15989+
SKEPAttr->setInvalidAttr();
1598615990
}
1598715991

1598815992
if (Body && !FD->isTemplated() && !SKEPAttr->isInvalidAttr()) {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,12 @@ auto bad36 = [] [[clang::sycl_kernel_entry_point(BADKN<36>)]] static {};
350350
// expected-error@+1 {{'sycl_kernel_entry_point' attribute cannot be applied to a coroutine}}
351351
auto bad37 = [] [[clang::sycl_kernel_entry_point(BADKN<37>)]] static -> void { co_return; };
352352
#endif
353+
354+
// expected-error@+1 {{'sycl_kernel_entry_point' attribute cannot be applied to a function defined with a function try block}}
355+
[[clang::sycl_kernel_entry_point(BADKN<38>)]]
356+
void bad38() try {} catch(...) {}
357+
358+
// expected-error@+2 {{'sycl_kernel_entry_point' attribute cannot be applied to a function defined with a function try block}}
359+
template<typename>
360+
[[clang::sycl_kernel_entry_point(BADKN<39>)]]
361+
void bad39() try {} catch(...) {}

0 commit comments

Comments
 (0)