diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 1150ac66d3ea2..6c632b022af88 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -2727,27 +2727,30 @@ void SYCLIntegrationHeader::emitFwdDecl(raw_ostream &O, const Decl *D, auto *NS = dyn_cast_or_null(DC); if (!NS) { - const TagDecl *TD = isa(D) - ? cast(D)->getTemplatedDecl() - : dyn_cast(D); - if (!TD) - break; - - const bool KernelNameIsMissing = TD->getName().empty(); - if (KernelNameIsMissing) - Diag.Report(KernelLocation, diag::err_sycl_kernel_incorrectly_named) - << /* kernel name is missing */ 0; - else if (!DC->isTranslationUnit()) { - // defined class constituting the kernel name is not globally - // accessible - contradicts the spec - if (!UnnamedLambdaSupport) { - if (TD->isCompleteDefinition()) + if (!DC->isTranslationUnit()) { + const TagDecl *TD = isa(D) + ? cast(D)->getTemplatedDecl() + : dyn_cast(D); + + if (TD && !UnnamedLambdaSupport) { + // defined class constituting the kernel name is not globally + // accessible - contradicts the spec + const bool KernelNameIsMissing = TD->getName().empty(); + if (KernelNameIsMissing) { Diag.Report(KernelLocation, diag::err_sycl_kernel_incorrectly_named) - << /* kernel name is not globally-visible */ 1; - else - Diag.Report(KernelLocation, diag::warn_sycl_implicit_decl); - Diag.Report(D->getSourceRange().getBegin(), diag::note_previous_decl) - << TD->getName(); + << /* kernel name is missing */ 0; + // Don't emit note if kernel name was completely omitted + } else { + if (TD->isCompleteDefinition()) + Diag.Report(KernelLocation, + diag::err_sycl_kernel_incorrectly_named) + << /* kernel name is not globally-visible */ 1; + else + Diag.Report(KernelLocation, diag::warn_sycl_implicit_decl); + Diag.Report(D->getSourceRange().getBegin(), + diag::note_previous_decl) + << TD->getName(); + } } } break;