================
@@ -387,8 +397,162 @@ void
SemaSYCL::CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD) {
}
}
+ExprResult SemaSYCL::BuildSYCLKernelLaunchIdExpr(FunctionDecl *FD,
+ QualType KNT) {
+ // The current context must be the function definition context to ensure
+ // that name lookup is performed within the correct scope.
+ assert(SemaRef.CurContext == FD);
+
+ // An appropriate source location is required to emit diagnostics if
+ // lookup fails to produce an overload set. The desired location is the
+ // start of the function body, but that is not yet available since the
+ // body of the function has not yet been set when this function is called.
+ // The general location of the function is used instead.
+ SourceLocation Loc = FD->getLocation();
+
+ ASTContext &Ctx = SemaRef.getASTContext();
+ IdentifierInfo &SYCLKernelLaunchID =
+ Ctx.Idents.get("sycl_kernel_launch", tok::TokenKind::identifier);
+
+ // Establish a code synthesis context for the implicit name lookup of
+ // a template named 'sycl_kernel_launch'. In the event of an error, this
+ // ensures an appropriate diagnostic note is issued to explain why the
+ // lookup was performed.
+ Sema::CodeSynthesisContext CSC;
+ CSC.Kind = Sema::CodeSynthesisContext::SYCLKernelLaunchLookup;
+ CSC.Entity = FD;
+ Sema::ScopedCodeSynthesisContext ScopedCSC(SemaRef, CSC);
+
+ // Perform ordinary name lookup for a function or variable template that
+ // accepts a single type template argument.
+ LookupResult Result(SemaRef, &SYCLKernelLaunchID, Loc,
+ Sema::LookupOrdinaryName);
+ CXXScopeSpec EmptySS;
+ if (SemaRef.LookupTemplateName(Result, SemaRef.getCurScope(), EmptySS,
+ /*ObjectType*/ QualType(),
+ /*EnteringContext*/ false,
+ Sema::TemplateNameIsRequired))
+ return ExprError();
+ if (Result.isAmbiguous())
+ return ExprError();
+
+ TemplateArgumentListInfo TALI{Loc, Loc};
+ TemplateArgument KNTA = TemplateArgument(KNT);
+ TemplateArgumentLoc TAL =
+ SemaRef.getTrivialTemplateArgumentLoc(KNTA, QualType(), Loc);
+ TALI.addArgument(TAL);
+
+ ExprResult IdExpr;
+ if (SemaRef.isPotentialImplicitMemberAccess(EmptySS, Result,
+ /*IsAddressOfOperand*/ false))
+ // The lookup result allows for a possible implicit member access that
+ // would require an implicit or explicit 'this' argument.
+ IdExpr = SemaRef.BuildPossibleImplicitMemberExpr(
+ EmptySS, SourceLocation(), Result, &TALI, SemaRef.getCurScope());
+ else
+ IdExpr = SemaRef.BuildTemplateIdExpr(EmptySS, SourceLocation(), Result,
+ /*RequiresADL*/ true, &TALI);
+
+ // The resulting expression may be invalid if, for example, 'FD' is a
+ // non-static member function and sycl_kernel_launch lookup selects a
+ // member function (which would require a 'this' argument which is
+ // not available).
+ if (IdExpr.isInvalid())
+ return ExprError();
+
+ return IdExpr;
+}
+
namespace {
+// Constructs the arguments to be passed for the SYCL kernel launch call.
+// The first argument is a string literal that contains the SYCL kernel
+// name. The remaining arguments are the parameters of 'FD' passed as
+// move-elligible xvalues. Returns true on error and false otherwise.
+bool BuildSYCLKernelLaunchCallArgs(Sema &SemaRef, FunctionDecl *FD,
+ const SYCLKernelInfo *SKI,
+ SmallVectorImpl<Expr *> &Args,
+ SourceLocation Loc) {
+ // The current context must be the function definition context to ensure
+ // that parameter references occur within the correct scope.
+ assert(SemaRef.CurContext == FD);
----------------
AaronBallman wrote:
Good to add `&& "explanation"` to the assert.
https://github.com/llvm/llvm-project/pull/152403
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits