================
@@ -16412,28 +16438,54 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt
*Body, bool IsInstantiation,
FD->getAttr<SYCLKernelEntryPointAttr>();
if (FD->isDefaulted()) {
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
- << SKEPAttr << /*defaulted function*/ 3;
+ << SKEPAttr << /*defaulted function*/ 2;
SKEPAttr->setInvalidAttr();
} else if (FD->isDeleted()) {
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
- << SKEPAttr << /*deleted function*/ 2;
+ << SKEPAttr << /*deleted function*/ 1;
SKEPAttr->setInvalidAttr();
} else if (FSI->isCoroutine()) {
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
- << SKEPAttr << /*coroutine*/ 7;
+ << SKEPAttr << /*coroutine*/ 5;
SKEPAttr->setInvalidAttr();
} else if (Body && isa<CXXTryStmt>(Body)) {
Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
- << SKEPAttr << /*function defined with a function try block*/ 8;
+ << SKEPAttr << /*function defined with a function try block*/ 9;
SKEPAttr->setInvalidAttr();
}
- if (Body && !FD->isTemplated() && !SKEPAttr->isInvalidAttr()) {
- StmtResult SR =
- SYCL().BuildSYCLKernelCallStmt(FD, cast<CompoundStmt>(Body));
- if (SR.isInvalid())
- return nullptr;
- Body = SR.get();
+ // Build an unresolved SYCL kernel call statement for a function template,
+ // validate that a SYCL kernel call statement was instantiated for an
+ // (implicit or explicit) instantiation of a function template, or
otherwise
+ // build a (resolved) SYCL kernel call statement for a non-templated
+ // function or an explicit specialization.
+ if (Body && !SKEPAttr->isInvalidAttr()) {
+ StmtResult SR;
+ if (FD->isTemplateInstantiation()) {
+ // The function body should already be a SYCLKernelCallStmt in this
+ // case, but might not be if errors previous occurred.
+ SR = Body;
+ } else if (!getCurFunction()->SYCLKernelLaunchIdExpr) {
+ // If name lookup for a template named sycl_kernel_launch failed
+ // earlier, don't try to build a SYCL kernel call statement as that
+ // would cause additional errors to be issued; just proceed with the
+ // original function body.
+ SR = Body;
+ } else if (FD->isTemplated()) {
+ SR = SYCL().BuildUnresolvedSYCLKernelCallStmt(
+ cast<CompoundStmt>(Body),
getCurFunction()->SYCLKernelLaunchIdExpr);
+ } else {
+ SR = SYCL().BuildSYCLKernelCallStmt(
+ FD, cast<CompoundStmt>(Body),
+ getCurFunction()->SYCLKernelLaunchIdExpr);
+ }
+ // If construction of the replacement body fails, just continue with the
+ // original function body. An early error return here is not valid; the
+ // current declaration context and function scopes must be popped before
+ // returning.
+ if (SR.isUsable()) {
+ Body = SR.get();
+ }
----------------
Fznamznon wrote:
Style nit
```suggestion
if (SR.isUsable())
Body = SR.get();
```
https://github.com/llvm/llvm-project/pull/152403
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits