@@ -1637,6 +1637,18 @@ static std::string eraseAnonNamespace(std::string S) {
16371637 return S;
16381638}
16391639
1640+ static bool checkEnumTemplateParameter (const EnumDecl *ED,
1641+ DiagnosticsEngine &Diag,
1642+ SourceLocation KernelLocation) {
1643+ if (!ED->isScoped () && !ED->isFixed ()) {
1644+ Diag.Report (KernelLocation, diag::err_sycl_kernel_incorrectly_named) << 2 ;
1645+ Diag.Report (ED->getSourceRange ().getBegin (), diag::note_entity_declared_at)
1646+ << ED;
1647+ return false ;
1648+ }
1649+ return true ;
1650+ }
1651+
16401652// Emits a forward declaration
16411653void SYCLIntegrationHeader::emitFwdDecl (raw_ostream &O, const Decl *D,
16421654 SourceLocation KernelLocation) {
@@ -1774,8 +1786,20 @@ void SYCLIntegrationHeader::emitForwardClassDecls(
17741786
17751787 switch (Arg.getKind ()) {
17761788 case TemplateArgument::ArgKind::Type:
1777- emitForwardClassDecls (O, Arg.getAsType (), KernelLocation, Printed);
1789+ case TemplateArgument::ArgKind::Integral: {
1790+ QualType T = (Arg.getKind () == TemplateArgument::ArgKind::Type)
1791+ ? Arg.getAsType ()
1792+ : Arg.getIntegralType ();
1793+
1794+ // Handle Kernel Name Type templated using enum type and value.
1795+ if (const auto *ET = T->getAs <EnumType>()) {
1796+ const EnumDecl *ED = ET->getDecl ();
1797+ if (checkEnumTemplateParameter (ED, Diag, KernelLocation))
1798+ emitFwdDecl (O, ED, KernelLocation);
1799+ } else if (Arg.getKind () == TemplateArgument::ArgKind::Type)
1800+ emitForwardClassDecls (O, T, KernelLocation, Printed);
17781801 break ;
1802+ }
17791803 case TemplateArgument::ArgKind::Pack: {
17801804 ArrayRef<TemplateArgument> Pack = Arg.getPackAsArray ();
17811805
@@ -1808,15 +1832,6 @@ void SYCLIntegrationHeader::emitForwardClassDecls(
18081832 }
18091833 break ;
18101834 }
1811- case TemplateArgument::ArgKind::Integral: {
1812- // Handle Kernel Name Type templated using enum.
1813- QualType T = Arg.getIntegralType ();
1814- if (const auto *ET = T->getAs <EnumType>()) {
1815- const EnumDecl *ED = ET->getDecl ();
1816- emitFwdDecl (O, ED, KernelLocation);
1817- }
1818- break ;
1819- }
18201835 default :
18211836 break ; // nop
18221837 }
0 commit comments