@@ -2834,10 +2834,15 @@ class SYCLKernelNameTypeVisitor
28342834 Sema &S;
28352835 SourceLocation KernelInvocationFuncLoc;
28362836 using InnerTypeVisitor = TypeVisitor<SYCLKernelNameTypeVisitor>;
2837- using InnerTAVisitor =
2837+ using InnerTemplArgVisitor =
28382838 ConstTemplateArgumentVisitor<SYCLKernelNameTypeVisitor>;
28392839 bool IsInvalid = false ;
28402840
2841+ void VisitTemplateArgs (ArrayRef<TemplateArgument> Args) {
2842+ for (auto &A : Args)
2843+ Visit (A);
2844+ }
2845+
28412846public:
28422847 SYCLKernelNameTypeVisitor (Sema &S, SourceLocation KernelInvocationFuncLoc)
28432848 : S(S), KernelInvocationFuncLoc(KernelInvocationFuncLoc) {}
@@ -2848,15 +2853,19 @@ class SYCLKernelNameTypeVisitor
28482853 if (T.isNull ())
28492854 return ;
28502855 const CXXRecordDecl *RD = T->getAsCXXRecordDecl ();
2851- if (!RD)
2856+ if (!RD) {
2857+ if (T->isNullPtrType ()) {
2858+ S.Diag (KernelInvocationFuncLoc, diag::err_sycl_kernel_incorrectly_named)
2859+ << /* kernel name cannot be a type in the std namespace */ 3 ;
2860+ IsInvalid = true ;
2861+ }
28522862 return ;
2863+ }
28532864 // If KernelNameType has template args visit each template arg via
28542865 // ConstTemplateArgumentVisitor
28552866 if (const auto *TSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
2856- const TemplateArgumentList &Args = TSD->getTemplateArgs ();
2857- for (unsigned I = 0 ; I < Args.size (); I++) {
2858- Visit (Args[I]);
2859- }
2867+ ArrayRef<TemplateArgument> Args = TSD->getTemplateArgs ().asArray ();
2868+ VisitTemplateArgs (Args);
28602869 } else {
28612870 InnerTypeVisitor::Visit (T.getTypePtr ());
28622871 }
@@ -2865,7 +2874,7 @@ class SYCLKernelNameTypeVisitor
28652874 void Visit (const TemplateArgument &TA) {
28662875 if (TA.isNull ())
28672876 return ;
2868- InnerTAVisitor ::Visit (TA);
2877+ InnerTemplArgVisitor ::Visit (TA);
28692878 }
28702879
28712880 void VisitEnumType (const EnumType *T) {
@@ -2886,22 +2895,31 @@ class SYCLKernelNameTypeVisitor
28862895 void VisitTagDecl (const TagDecl *Tag) {
28872896 bool UnnamedLambdaEnabled =
28882897 S.getASTContext ().getLangOpts ().SYCLUnnamedLambda ;
2889- if (! Tag->getDeclContext ()-> isTranslationUnit () &&
2890- !isa<NamespaceDecl>(Tag-> getDeclContext ()) && !UnnamedLambdaEnabled) {
2891- const bool KernelNameIsMissing = Tag-> getName (). empty ( );
2892- if (KernelNameIsMissing ) {
2898+ const DeclContext *DeclCtx = Tag->getDeclContext ();
2899+ if (DeclCtx && !UnnamedLambdaEnabled) {
2900+ auto *NameSpace = dyn_cast_or_null<NamespaceDecl>(DeclCtx );
2901+ if (NameSpace && NameSpace-> isStdNamespace () ) {
28932902 S.Diag (KernelInvocationFuncLoc, diag::err_sycl_kernel_incorrectly_named)
2894- << /* kernel name is missing */ 0 ;
2903+ << /* kernel name cannot be a type in the std namespace */ 3 ;
28952904 IsInvalid = true ;
2896- } else {
2905+ return ;
2906+ }
2907+ if (!DeclCtx->isTranslationUnit () && !isa<NamespaceDecl>(DeclCtx)) {
2908+ const bool KernelNameIsMissing = Tag->getName ().empty ();
2909+ if (KernelNameIsMissing) {
2910+ S.Diag (KernelInvocationFuncLoc,
2911+ diag::err_sycl_kernel_incorrectly_named)
2912+ << /* kernel name is missing */ 0 ;
2913+ IsInvalid = true ;
2914+ return ;
2915+ }
28972916 if (Tag->isCompleteDefinition ()) {
28982917 S.Diag (KernelInvocationFuncLoc,
28992918 diag::err_sycl_kernel_incorrectly_named)
29002919 << /* kernel name is not globally-visible */ 1 ;
29012920 IsInvalid = true ;
29022921 } else
29032922 S.Diag (KernelInvocationFuncLoc, diag::warn_sycl_implicit_decl);
2904-
29052923 S.Diag (Tag->getSourceRange ().getBegin (), diag::note_previous_decl)
29062924 << Tag->getName ();
29072925 }
@@ -2932,6 +2950,10 @@ class SYCLKernelNameTypeVisitor
29322950 VisitEnumType (ET);
29332951 }
29342952 }
2953+
2954+ void VisitPackTemplateArgument (const TemplateArgument &TA) {
2955+ VisitTemplateArgs (TA.getPackAsArray ());
2956+ }
29352957};
29362958
29372959void Sema::CheckSYCLKernelCall (FunctionDecl *KernelFunc, SourceRange CallLoc,
@@ -3337,12 +3359,6 @@ void SYCLIntegrationHeader::emitFwdDecl(raw_ostream &O, const Decl *D,
33373359 break ;
33383360 }
33393361
3340- if (NS->isStdNamespace ()) {
3341- Diag.Report (KernelLocation, diag::err_sycl_kernel_incorrectly_named)
3342- << /* name cannot be a type in the std namespace */ 3 ;
3343- return ;
3344- }
3345-
33463362 ++NamespaceCnt;
33473363 const StringRef NSInlinePrefix = NS->isInline () ? " inline " : " " ;
33483364 NSStr.insert (
@@ -3426,9 +3442,6 @@ void SYCLIntegrationHeader::emitForwardClassDecls(
34263442 const CXXRecordDecl *RD = T->getAsCXXRecordDecl ();
34273443
34283444 if (!RD) {
3429- if (T->isNullPtrType ())
3430- Diag.Report (KernelLocation, diag::err_sycl_kernel_incorrectly_named)
3431- << /* name cannot be a type in the std namespace */ 3 ;
34323445
34333446 return ;
34343447 }
0 commit comments