[clang] [SYCL] Basic diagnostics for the sycl_kernel_entry_point attribute. (PR #120327)
Tom Honermann via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 23 22:01:19 PST 2024
================
@@ -15978,6 +15988,24 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
CheckCoroutineWrapper(FD);
}
+ // Diagnose invalid SYCL kernel entry point function declarations.
+ if (FD && !FD->isInvalidDecl() && !FD->isTemplated() &&
+ FD->hasAttr<SYCLKernelEntryPointAttr>()) {
+ if (FD->isDeleted()) {
+ Diag(FD->getAttr<SYCLKernelEntryPointAttr>()->getLocation(),
+ diag::err_sycl_entry_point_invalid)
+ << /*deleted function*/ 2;
+ } else if (FD->isDefaulted()) {
+ Diag(FD->getAttr<SYCLKernelEntryPointAttr>()->getLocation(),
+ diag::err_sycl_entry_point_invalid)
+ << /*defaulted function*/ 3;
+ } else if (FSI->isCoroutine()) {
+ Diag(FD->getAttr<SYCLKernelEntryPointAttr>()->getLocation(),
+ diag::err_sycl_entry_point_invalid)
+ << /*coroutine*/ 7;
----------------
tahonermann wrote:
Thanks for pointing me to those examples. For both `AttributeArgumentNType` and `AttributeDeclKind`, the production of the diagnostic is more complicated. For the first case, the diagnostic is produced in a lambda expression and the `%select` index is passed as an argument. For the second case, the `%select` index is computed by mapping from another enumeration using a switch statement. An enum definitely seems warranted for those cases. Similarly, for `Sema::checkTargetVersionAttr`, there are multiple `%select` indices involved in each diagnostic and the local enumeration does help with readability.
For simple diagnostics, where the `%select` index doesn't require computation and where the same index values are not used in multiple places, I think indirection through an enumeration isn't helpful, so I haven't made a change. If you still think a change is warranted, perhaps we can get a second opinion.
https://github.com/llvm/llvm-project/pull/120327
More information about the cfe-commits
mailing list