From 2f5e8ad701085504df6c04eae363b7f7677af691 Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Wed, 14 Oct 2020 21:52:29 -0700 Subject: [PATCH 01/12] [SYCL] Emit diagnostics using Visitor class implementation --- clang/lib/Sema/SemaSYCL.cpp | 19 +++++++++++-------- clang/test/SemaSYCL/unnamed-kernel.cpp | 3 ++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 6e8fb9fd139e7..62b3667b674c9 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -2886,8 +2886,17 @@ class SYCLKernelNameTypeVisitor void VisitTagDecl(const TagDecl *Tag) { bool UnnamedLambdaEnabled = S.getASTContext().getLangOpts().SYCLUnnamedLambda; - if (!Tag->getDeclContext()->isTranslationUnit() && - !isa(Tag->getDeclContext()) && !UnnamedLambdaEnabled) { + const DeclContext *DC = Tag->getDeclContext(); + if (DC) { + auto *NS = dyn_cast_or_null(DC); + if (NS && NS->isStdNamespace()) { + S.Diag(KernelInvocationFuncLoc, diag::err_sycl_kernel_incorrectly_named) + << /* name cannot be a type in the std namespace */ 3; + IsInvalid = true; + } + } + if (!DC->isTranslationUnit() && !isa(DC) && + !UnnamedLambdaEnabled) { const bool KernelNameIsMissing = Tag->getName().empty(); if (KernelNameIsMissing) { S.Diag(KernelInvocationFuncLoc, diag::err_sycl_kernel_incorrectly_named) @@ -3352,12 +3361,6 @@ void SYCLIntegrationHeader::emitFwdDecl(raw_ostream &O, const Decl *D, break; } - if (NS->isStdNamespace()) { - Diag.Report(KernelLocation, diag::err_sycl_kernel_incorrectly_named) - << /* name cannot be a type in the std namespace */ 3; - return; - } - ++NamespaceCnt; const StringRef NSInlinePrefix = NS->isInline() ? "inline " : ""; NSStr.insert( diff --git a/clang/test/SemaSYCL/unnamed-kernel.cpp b/clang/test/SemaSYCL/unnamed-kernel.cpp index b90a82d87f933..2ae830f23c01f 100644 --- a/clang/test/SemaSYCL/unnamed-kernel.cpp +++ b/clang/test/SemaSYCL/unnamed-kernel.cpp @@ -70,7 +70,8 @@ struct MyWrapper { }); #ifndef __SYCL_UNNAMED_LAMBDA__ - // expected-error@+3 {{kernel name cannot be a type in the "std" namespace}} + // expected-error@Inputs/sycl.hpp:220 {{kernel name cannot be a type in the "std" namespace}} + // expected-note@+3{{in instantiation of function template specialization}} #endif q.submit([&](cl::sycl::handler &h) { h.single_task([] {}); From d50f24b5d306de6d70380851d044837746170322 Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Fri, 16 Oct 2020 15:38:05 -0700 Subject: [PATCH 02/12] [SYCL] Fix failing tests --- clang/lib/Sema/SemaSYCL.cpp | 53 +++++++-------- .../test/CodeGenSYCL/stdtypes_kernel_type.cpp | 65 +++++++++---------- clang/test/SemaSYCL/unnamed-kernel.cpp | 4 +- 3 files changed, 58 insertions(+), 64 deletions(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 62b3667b674c9..2414c53f28d7a 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -2848,8 +2848,12 @@ class SYCLKernelNameTypeVisitor if (T.isNull()) return; const CXXRecordDecl *RD = T->getAsCXXRecordDecl(); - if (!RD) + if (!RD) { + if (T->isNullPtrType()) + S.Diag(KernelInvocationFuncLoc, diag::err_sycl_kernel_incorrectly_named) + << /* kernel name cannot be a type in the std namespace */ 3; return; + } // If KernelNameType has template args visit each template arg via // ConstTemplateArgumentVisitor if (const auto *TSD = dyn_cast(RD)) { @@ -2887,32 +2891,33 @@ class SYCLKernelNameTypeVisitor bool UnnamedLambdaEnabled = S.getASTContext().getLangOpts().SYCLUnnamedLambda; const DeclContext *DC = Tag->getDeclContext(); - if (DC) { + if (DC && !UnnamedLambdaEnabled) { auto *NS = dyn_cast_or_null(DC); if (NS && NS->isStdNamespace()) { S.Diag(KernelInvocationFuncLoc, diag::err_sycl_kernel_incorrectly_named) - << /* name cannot be a type in the std namespace */ 3; - IsInvalid = true; - } - } - if (!DC->isTranslationUnit() && !isa(DC) && - !UnnamedLambdaEnabled) { - const bool KernelNameIsMissing = Tag->getName().empty(); - if (KernelNameIsMissing) { - S.Diag(KernelInvocationFuncLoc, diag::err_sycl_kernel_incorrectly_named) - << /* kernel name is missing */ 0; + << /* kernel name cannot be a type in the std namespace */ 3; IsInvalid = true; } else { - if (Tag->isCompleteDefinition()) { - S.Diag(KernelInvocationFuncLoc, - diag::err_sycl_kernel_incorrectly_named) - << /* kernel name is not globally-visible */ 1; - IsInvalid = true; - } else - S.Diag(KernelInvocationFuncLoc, diag::warn_sycl_implicit_decl); - - S.Diag(Tag->getSourceRange().getBegin(), diag::note_previous_decl) - << Tag->getName(); + if (!DC->isTranslationUnit() && !isa(DC)) { + const bool KernelNameIsMissing = Tag->getName().empty(); + if (KernelNameIsMissing) { + S.Diag(KernelInvocationFuncLoc, + diag::err_sycl_kernel_incorrectly_named) + << /* kernel name is missing */ 0; + IsInvalid = true; + } else { + if (Tag->isCompleteDefinition()) { + S.Diag(KernelInvocationFuncLoc, + diag::err_sycl_kernel_incorrectly_named) + << /* kernel name is not globally-visible */ 1; + IsInvalid = true; + } else + S.Diag(KernelInvocationFuncLoc, diag::warn_sycl_implicit_decl); + + S.Diag(Tag->getSourceRange().getBegin(), diag::note_previous_decl) + << Tag->getName(); + } + } } } } @@ -3444,10 +3449,6 @@ void SYCLIntegrationHeader::emitForwardClassDecls( const CXXRecordDecl *RD = T->getAsCXXRecordDecl(); if (!RD) { - if (T->isNullPtrType()) - Diag.Report(KernelLocation, diag::err_sycl_kernel_incorrectly_named) - << /* name cannot be a type in the std namespace */ 3; - return; } diff --git a/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp b/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp index 04eeb22b94f66..2f2bf393a3cc1 100644 --- a/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp +++ b/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp @@ -1,29 +1,6 @@ -// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-int-header=%t.h -DCHECK_ERROR -verify %s -// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -fsycl-int-header=%t.h %s -// RUN: FileCheck -input-file=%t.h %s -// -// CHECK: #include -// CHECK-NEXT: #include -// -// CHECK: static constexpr -// CHECK-NEXT: const char* const kernel_names[] = { -// CHECK-NEXT: "_ZTSm", -// CHECK-NEXT: "_ZTSl" -// CHECK-NEXT: }; -// -// CHECK: static constexpr -// CHECK-NEXT: const kernel_param_desc_t kernel_signatures[] = { -// CHECK-NEXT: //--- _ZTSm -// CHECK-EMPTY: -// CHECK-NEXT: //--- _ZTSl -// CHECK-EMPTY: -// CHECK-NEXT: }; - -// CHECK: template <> struct KernelInfo { -// CHECK: template <> struct KernelInfo { - -void usage() { -} +// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -sycl-std=2020 -DCHECK_ERROR -verify %s + +#include "sycl.hpp" namespace std { typedef long unsigned int size_t; @@ -36,22 +13,38 @@ class U; template struct Templated_kernel_name; -template -__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { - kernelFunc(); -} +using namespace cl::sycl; +queue q; int main() { #ifdef CHECK_ERROR - kernel_single_task([=]() {}); // expected-error {{kernel name cannot be a type in the "std" namespace}} - kernel_single_task([=]() {}); // expected-error {{kernel name cannot be a type in the "std" namespace}} - kernel_single_task>([=]() {}); // expected-error {{kernel name cannot be a type in the "std" namespace}} - kernel_single_task>([=]() {}); // expected-error {{kernel name cannot be a type in the "std" namespace}} + // expected-error@Inputs/sycl.hpp:328 4 {{kernel name cannot be a type in the "std" namespace}} + q.submit([&](cl::sycl::handler &h) { + // expected-note@+1{{in instantiation of function template specialization}} + h.single_task([=] {}); + }); + q.submit([&](cl::sycl::handler &h) { + // expected-note@+1{{in instantiation of function template specialization}} + h.single_task([=] {}); + }); + q.submit([&](cl::sycl::handler &h) { + // expected-note@+1{{in instantiation of function template specialization}} + h.single_task>([=] {}); + }); + q.submit([&](cl::sycl::handler &h) { + // expected-note@+1{{in instantiation of function template specialization}} + h.single_task>([=] {}); + }); + #endif // Although in the std namespace, these resolve to builtins such as `int` that are allowed in kernel names - kernel_single_task([=]() {}); - kernel_single_task([=]() {}); + q.submit([&](cl::sycl::handler &h) { + h.single_task([=] {}); + }); + q.submit([&](cl::sycl::handler &h) { + h.single_task([=] {}); + }); return 0; } diff --git a/clang/test/SemaSYCL/unnamed-kernel.cpp b/clang/test/SemaSYCL/unnamed-kernel.cpp index 2ae830f23c01f..e8df9198503bc 100644 --- a/clang/test/SemaSYCL/unnamed-kernel.cpp +++ b/clang/test/SemaSYCL/unnamed-kernel.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-int-header=%t.h -fsyntax-only -Wno-sycl-2017-compat -verify %s -// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-int-header=%t.h -fsycl-unnamed-lambda -fsyntax-only -Wno-sycl-2017-compat -verify %s +// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -Wno-sycl-2017-compat -verify %s +// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-unnamed-lambda -fsyntax-only -Wno-sycl-2017-compat -verify %s #include "Inputs/sycl.hpp" #ifdef __SYCL_UNNAMED_LAMBDA__ From 660cb959fd9bb6681901ced626af08725eee3f17 Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Fri, 16 Oct 2020 15:48:13 -0700 Subject: [PATCH 03/12] Use cl::sycl namespace --- clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp b/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp index 2f2bf393a3cc1..312834272d58d 100644 --- a/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp +++ b/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp @@ -19,19 +19,19 @@ queue q; int main() { #ifdef CHECK_ERROR // expected-error@Inputs/sycl.hpp:328 4 {{kernel name cannot be a type in the "std" namespace}} - q.submit([&](cl::sycl::handler &h) { + q.submit([&](handler &h) { // expected-note@+1{{in instantiation of function template specialization}} h.single_task([=] {}); }); - q.submit([&](cl::sycl::handler &h) { + q.submit([&](handler &h) { // expected-note@+1{{in instantiation of function template specialization}} h.single_task([=] {}); }); - q.submit([&](cl::sycl::handler &h) { + q.submit([&](handler &h) { // expected-note@+1{{in instantiation of function template specialization}} h.single_task>([=] {}); }); - q.submit([&](cl::sycl::handler &h) { + q.submit([&](handler &h) { // expected-note@+1{{in instantiation of function template specialization}} h.single_task>([=] {}); }); @@ -39,10 +39,10 @@ int main() { #endif // Although in the std namespace, these resolve to builtins such as `int` that are allowed in kernel names - q.submit([&](cl::sycl::handler &h) { + q.submit([&](handler &h) { h.single_task([=] {}); }); - q.submit([&](cl::sycl::handler &h) { + q.submit([&](handler &h) { h.single_task([=] {}); }); From a6d0df09d63a8b8c47550e4f693d24d6fc197f6e Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Sun, 18 Oct 2020 08:52:11 -0700 Subject: [PATCH 04/12] set IsInvalid=true for null ptr type kernel name --- clang/lib/Sema/SemaSYCL.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 2414c53f28d7a..f3312b480f790 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -2852,6 +2852,7 @@ class SYCLKernelNameTypeVisitor if (T->isNullPtrType()) S.Diag(KernelInvocationFuncLoc, diag::err_sycl_kernel_incorrectly_named) << /* kernel name cannot be a type in the std namespace */ 3; + IsInvalid = true; return; } // If KernelNameType has template args visit each template arg via From 7cd339d5e13cb9d7dfed123eb27bbbefc361fc69 Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Sun, 18 Oct 2020 11:26:52 -0700 Subject: [PATCH 05/12] Revert IsInvalid=true for nullptr type kernel name --- clang/lib/Sema/SemaSYCL.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index f3312b480f790..2414c53f28d7a 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -2852,7 +2852,6 @@ class SYCLKernelNameTypeVisitor if (T->isNullPtrType()) S.Diag(KernelInvocationFuncLoc, diag::err_sycl_kernel_incorrectly_named) << /* kernel name cannot be a type in the std namespace */ 3; - IsInvalid = true; return; } // If KernelNameType has template args visit each template arg via From 55d4311cb13825363bcf22c91c6e8c1a8d3bbceb Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Thu, 22 Oct 2020 12:21:38 -0700 Subject: [PATCH 06/12] Fix CodeGenSYCL/template-template-parameter.cpp --- clang/lib/Sema/SemaSYCL.cpp | 13 ++++++++----- .../CodeGenSYCL/template-template-parameter.cpp | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 2414c53f28d7a..b7bc8347a198c 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -2852,6 +2852,7 @@ class SYCLKernelNameTypeVisitor if (T->isNullPtrType()) S.Diag(KernelInvocationFuncLoc, diag::err_sycl_kernel_incorrectly_named) << /* kernel name cannot be a type in the std namespace */ 3; + IsInvalid = true; return; } // If KernelNameType has template args visit each template arg via @@ -2890,21 +2891,23 @@ class SYCLKernelNameTypeVisitor void VisitTagDecl(const TagDecl *Tag) { bool UnnamedLambdaEnabled = S.getASTContext().getLangOpts().SYCLUnnamedLambda; - const DeclContext *DC = Tag->getDeclContext(); - if (DC && !UnnamedLambdaEnabled) { - auto *NS = dyn_cast_or_null(DC); - if (NS && NS->isStdNamespace()) { + const DeclContext *DeclCtx = Tag->getDeclContext(); + if (DeclCtx && !UnnamedLambdaEnabled) { + auto *NameSpace = dyn_cast_or_null(DeclCtx); + if (NameSpace && NameSpace->isStdNamespace()) { S.Diag(KernelInvocationFuncLoc, diag::err_sycl_kernel_incorrectly_named) << /* kernel name cannot be a type in the std namespace */ 3; IsInvalid = true; + return; } else { - if (!DC->isTranslationUnit() && !isa(DC)) { + if (!DeclCtx->isTranslationUnit() && !isa(DeclCtx)) { const bool KernelNameIsMissing = Tag->getName().empty(); if (KernelNameIsMissing) { S.Diag(KernelInvocationFuncLoc, diag::err_sycl_kernel_incorrectly_named) << /* kernel name is missing */ 0; IsInvalid = true; + return; } else { if (Tag->isCompleteDefinition()) { S.Diag(KernelInvocationFuncLoc, diff --git a/clang/test/CodeGenSYCL/template-template-parameter.cpp b/clang/test/CodeGenSYCL/template-template-parameter.cpp index 6d5c0491d8941..0ad72ae400ff5 100644 --- a/clang/test/CodeGenSYCL/template-template-parameter.cpp +++ b/clang/test/CodeGenSYCL/template-template-parameter.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-int-header=%t.h %s +// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-int-bb=%t.h -sycl-std=2020 %s // RUN: FileCheck -input-file=%t.h %s #include "Inputs/sycl.hpp" From 643bc9419ed1dba59a358206d020c92d491515ce Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Fri, 23 Oct 2020 15:43:15 -0700 Subject: [PATCH 07/12] Add Visitor method to handle template parameter pack in kernel names --- clang/lib/Sema/SemaSYCL.cpp | 21 +++++++++++++------ .../test/CodeGenSYCL/stdtypes_kernel_type.cpp | 9 ++++++-- .../template-template-parameter.cpp | 2 +- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index b7bc8347a198c..65ce55231ed74 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -2838,6 +2838,11 @@ class SYCLKernelNameTypeVisitor ConstTemplateArgumentVisitor; bool IsInvalid = false; + void VisitTemplateArgs(ArrayRef Args) { + for (size_t I = 0, E = Args.size(); I < E; ++I) + Visit(Args[I]); + } + public: SYCLKernelNameTypeVisitor(Sema &S, SourceLocation KernelInvocationFuncLoc) : S(S), KernelInvocationFuncLoc(KernelInvocationFuncLoc) {} @@ -2849,19 +2854,18 @@ class SYCLKernelNameTypeVisitor return; const CXXRecordDecl *RD = T->getAsCXXRecordDecl(); if (!RD) { - if (T->isNullPtrType()) + if (T->isNullPtrType()) { S.Diag(KernelInvocationFuncLoc, diag::err_sycl_kernel_incorrectly_named) << /* kernel name cannot be a type in the std namespace */ 3; - IsInvalid = true; + IsInvalid = true; + } return; } // If KernelNameType has template args visit each template arg via // ConstTemplateArgumentVisitor if (const auto *TSD = dyn_cast(RD)) { - const TemplateArgumentList &Args = TSD->getTemplateArgs(); - for (unsigned I = 0; I < Args.size(); I++) { - Visit(Args[I]); - } + ArrayRef Args = TSD->getTemplateArgs().asArray(); + VisitTemplateArgs(Args); } else { InnerTypeVisitor::Visit(T.getTypePtr()); } @@ -2949,6 +2953,10 @@ class SYCLKernelNameTypeVisitor VisitEnumType(ET); } } + + void VisitPackTemplateArgument(const TemplateArgument &TA) { + VisitTemplateArgs(TA.getPackAsArray()); + } }; void Sema::CheckSYCLKernelCall(FunctionDecl *KernelFunc, SourceRange CallLoc, @@ -3452,6 +3460,7 @@ void SYCLIntegrationHeader::emitForwardClassDecls( const CXXRecordDecl *RD = T->getAsCXXRecordDecl(); if (!RD) { + return; } diff --git a/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp b/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp index 312834272d58d..c2f6680e0e967 100644 --- a/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp +++ b/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp @@ -13,12 +13,14 @@ class U; template struct Templated_kernel_name; +template class TemplParamPack; + using namespace cl::sycl; queue q; int main() { #ifdef CHECK_ERROR - // expected-error@Inputs/sycl.hpp:328 4 {{kernel name cannot be a type in the "std" namespace}} + // expected-error@Inputs/sycl.hpp:328 5 {{kernel name cannot be a type in the "std" namespace}} q.submit([&](handler &h) { // expected-note@+1{{in instantiation of function template specialization}} h.single_task([=] {}); @@ -35,7 +37,10 @@ int main() { // expected-note@+1{{in instantiation of function template specialization}} h.single_task>([=] {}); }); - + q.submit([&](handler &cgh) { + // expected-note@+1{{in instantiation of function template specialization}} + cgh.single_task>([]() {}); + }); #endif // Although in the std namespace, these resolve to builtins such as `int` that are allowed in kernel names diff --git a/clang/test/CodeGenSYCL/template-template-parameter.cpp b/clang/test/CodeGenSYCL/template-template-parameter.cpp index 0ad72ae400ff5..1a23e30a590b5 100644 --- a/clang/test/CodeGenSYCL/template-template-parameter.cpp +++ b/clang/test/CodeGenSYCL/template-template-parameter.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-int-bb=%t.h -sycl-std=2020 %s +// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsycl-int-header=%t.h -sycl-std=2020 %s // RUN: FileCheck -input-file=%t.h %s #include "Inputs/sycl.hpp" From 954bbfb402213b1d65b13d126bcb4ed6b0290132 Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Mon, 26 Oct 2020 15:54:48 -0700 Subject: [PATCH 08/12] Address review comments --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 1 + clang/lib/Sema/SemaSYCL.cpp | 15 +++++++-------- clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp | 5 +++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index bbc1c8029328f..fa998df0f60bb 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -14,6 +14,7 @@ let Component = "Sema" in { let CategoryName = "Semantic Issue" in { def note_previous_decl : Note<"%0 declared here">; def note_entity_declared_at : Note<"%0 declared here">; +def note_nullptr_used : Note<"nullptr is a prvalue of type std::nullptr_t">; def note_callee_decl : Note<"%0 declared here">; def note_defined_here : Note<"%0 defined here">; diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 65ce55231ed74..173d1a7cc29e7 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -2834,13 +2834,13 @@ class SYCLKernelNameTypeVisitor Sema &S; SourceLocation KernelInvocationFuncLoc; using InnerTypeVisitor = TypeVisitor; - using InnerTAVisitor = + using InnerTemplArgVisitor = ConstTemplateArgumentVisitor; bool IsInvalid = false; void VisitTemplateArgs(ArrayRef Args) { - for (size_t I = 0, E = Args.size(); I < E; ++I) - Visit(Args[I]); + for (auto &A : Args) + Visit(A); } public: @@ -2857,6 +2857,7 @@ class SYCLKernelNameTypeVisitor if (T->isNullPtrType()) { S.Diag(KernelInvocationFuncLoc, diag::err_sycl_kernel_incorrectly_named) << /* kernel name cannot be a type in the std namespace */ 3; + S.Diag(KernelInvocationFuncLoc, diag::note_nullptr_used); IsInvalid = true; } return; @@ -2874,7 +2875,7 @@ class SYCLKernelNameTypeVisitor void Visit(const TemplateArgument &TA) { if (TA.isNull()) return; - InnerTAVisitor::Visit(TA); + InnerTemplArgVisitor::Visit(TA); } void VisitEnumType(const EnumType *T) { @@ -2903,7 +2904,7 @@ class SYCLKernelNameTypeVisitor << /* kernel name cannot be a type in the std namespace */ 3; IsInvalid = true; return; - } else { + } if (!DeclCtx->isTranslationUnit() && !isa(DeclCtx)) { const bool KernelNameIsMissing = Tag->getName().empty(); if (KernelNameIsMissing) { @@ -2912,7 +2913,7 @@ class SYCLKernelNameTypeVisitor << /* kernel name is missing */ 0; IsInvalid = true; return; - } else { + } if (Tag->isCompleteDefinition()) { S.Diag(KernelInvocationFuncLoc, diag::err_sycl_kernel_incorrectly_named) @@ -2923,9 +2924,7 @@ class SYCLKernelNameTypeVisitor S.Diag(Tag->getSourceRange().getBegin(), diag::note_previous_decl) << Tag->getName(); - } } - } } } diff --git a/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp b/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp index c2f6680e0e967..37419ad01973b 100644 --- a/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp +++ b/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp @@ -1,6 +1,6 @@ -// RUN: %clang_cc1 -fsycl -fsycl-is-device -internal-isystem %S/Inputs -sycl-std=2020 -DCHECK_ERROR -verify %s +// RUN: %clang_cc1 -fsycl -fsycl-is-device -sycl-std=2020 -DCHECK_ERROR -verify %s -#include "sycl.hpp" +#include "Inputs/sycl.hpp" namespace std { typedef long unsigned int size_t; @@ -21,6 +21,7 @@ queue q; int main() { #ifdef CHECK_ERROR // expected-error@Inputs/sycl.hpp:328 5 {{kernel name cannot be a type in the "std" namespace}} + // expected-note@Inputs/sycl.hpp:328 3 {{nullptr is a prvalue of type std::nullptr_t}} q.submit([&](handler &h) { // expected-note@+1{{in instantiation of function template specialization}} h.single_task([=] {}); From 5379751c89cb52d0b069cde81cb99ec90c2e7825 Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Mon, 26 Oct 2020 16:04:40 -0700 Subject: [PATCH 09/12] clang-format fix --- clang/lib/Sema/SemaSYCL.cpp | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index dc3f2f34fc071..e8815e82e4d59 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -2905,26 +2905,25 @@ class SYCLKernelNameTypeVisitor IsInvalid = true; return; } - if (!DeclCtx->isTranslationUnit() && !isa(DeclCtx)) { - const bool KernelNameIsMissing = Tag->getName().empty(); - if (KernelNameIsMissing) { - S.Diag(KernelInvocationFuncLoc, - diag::err_sycl_kernel_incorrectly_named) - << /* kernel name is missing */ 0; - IsInvalid = true; - return; - } - if (Tag->isCompleteDefinition()) { - S.Diag(KernelInvocationFuncLoc, - diag::err_sycl_kernel_incorrectly_named) - << /* kernel name is not globally-visible */ 1; - IsInvalid = true; - } else - S.Diag(KernelInvocationFuncLoc, diag::warn_sycl_implicit_decl); - - S.Diag(Tag->getSourceRange().getBegin(), diag::note_previous_decl) - << Tag->getName(); + if (!DeclCtx->isTranslationUnit() && !isa(DeclCtx)) { + const bool KernelNameIsMissing = Tag->getName().empty(); + if (KernelNameIsMissing) { + S.Diag(KernelInvocationFuncLoc, + diag::err_sycl_kernel_incorrectly_named) + << /* kernel name is missing */ 0; + IsInvalid = true; + return; } + if (Tag->isCompleteDefinition()) { + S.Diag(KernelInvocationFuncLoc, + diag::err_sycl_kernel_incorrectly_named) + << /* kernel name is not globally-visible */ 1; + IsInvalid = true; + } else + S.Diag(KernelInvocationFuncLoc, diag::warn_sycl_implicit_decl); + S.Diag(Tag->getSourceRange().getBegin(), diag::note_previous_decl) + << Tag->getName(); + } } } From 44e36d36a5bae847d3ccd4c4cbcf00286ad6a334 Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Tue, 27 Oct 2020 11:25:01 -0700 Subject: [PATCH 10/12] Remove note --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 1 - clang/lib/Sema/SemaSYCL.cpp | 1 - clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp | 1 - 3 files changed, 3 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index fa998df0f60bb..bbc1c8029328f 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -14,7 +14,6 @@ let Component = "Sema" in { let CategoryName = "Semantic Issue" in { def note_previous_decl : Note<"%0 declared here">; def note_entity_declared_at : Note<"%0 declared here">; -def note_nullptr_used : Note<"nullptr is a prvalue of type std::nullptr_t">; def note_callee_decl : Note<"%0 declared here">; def note_defined_here : Note<"%0 defined here">; diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index e8815e82e4d59..faec8a1b1298f 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -2857,7 +2857,6 @@ class SYCLKernelNameTypeVisitor if (T->isNullPtrType()) { S.Diag(KernelInvocationFuncLoc, diag::err_sycl_kernel_incorrectly_named) << /* kernel name cannot be a type in the std namespace */ 3; - S.Diag(KernelInvocationFuncLoc, diag::note_nullptr_used); IsInvalid = true; } return; diff --git a/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp b/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp index 37419ad01973b..5a3c7745fb9cf 100644 --- a/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp +++ b/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp @@ -21,7 +21,6 @@ queue q; int main() { #ifdef CHECK_ERROR // expected-error@Inputs/sycl.hpp:328 5 {{kernel name cannot be a type in the "std" namespace}} - // expected-note@Inputs/sycl.hpp:328 3 {{nullptr is a prvalue of type std::nullptr_t}} q.submit([&](handler &h) { // expected-note@+1{{in instantiation of function template specialization}} h.single_task([=] {}); From b316aa53d4348b510cf5bf8e8d876d8850c8bdee Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Wed, 28 Oct 2020 07:56:30 -0700 Subject: [PATCH 11/12] Move test from CodeGenSYCL to SemaSYCL --- clang/test/{CodeGenSYCL => SemaSYCL}/stdtypes_kernel_type.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename clang/test/{CodeGenSYCL => SemaSYCL}/stdtypes_kernel_type.cpp (100%) diff --git a/clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp b/clang/test/SemaSYCL/stdtypes_kernel_type.cpp similarity index 100% rename from clang/test/CodeGenSYCL/stdtypes_kernel_type.cpp rename to clang/test/SemaSYCL/stdtypes_kernel_type.cpp From 2b5b3e9e88aa956d37601f47e0f697a6268af1a1 Mon Sep 17 00:00:00 2001 From: Srividya Sundaram Date: Wed, 28 Oct 2020 08:48:28 -0700 Subject: [PATCH 12/12] Fix incorrect line number in Inputs/sycl.hpp --- clang/test/SemaSYCL/stdtypes_kernel_type.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/SemaSYCL/stdtypes_kernel_type.cpp b/clang/test/SemaSYCL/stdtypes_kernel_type.cpp index 5a3c7745fb9cf..c4e84e86bea69 100644 --- a/clang/test/SemaSYCL/stdtypes_kernel_type.cpp +++ b/clang/test/SemaSYCL/stdtypes_kernel_type.cpp @@ -20,7 +20,7 @@ queue q; int main() { #ifdef CHECK_ERROR - // expected-error@Inputs/sycl.hpp:328 5 {{kernel name cannot be a type in the "std" namespace}} + // expected-error@Inputs/sycl.hpp:220 5 {{kernel name cannot be a type in the "std" namespace}} q.submit([&](handler &h) { // expected-note@+1{{in instantiation of function template specialization}} h.single_task([=] {});