@@ -6973,19 +6973,40 @@ static bool checkForDuplicateAttribute(Sema &S, Decl *D,
69736973// Checks if FPGA memory attributes apply on valid variables.
69746974// Returns true if an error occured.
69756975static bool CheckValidFPGAMemoryAttributesVar (Sema &S, Decl *D) {
6976- if (const auto *VD = dyn_cast<VarDecl>(D)) {
6977- if (!(isa<FieldDecl>(D) ||
6978- (VD->getKind () != Decl::ImplicitParam &&
6979- VD->getKind () != Decl::NonTypeTemplateParm &&
6980- (S.SYCL ().isTypeDecoratedWithDeclAttribute <SYCLDeviceGlobalAttr>(
6981- VD->getType ()) ||
6982- VD->getType ().isConstQualified () ||
6983- VD->getType ().getAddressSpace () == LangAS::opencl_constant ||
6984- VD->getStorageClass () == SC_Static || VD->hasLocalStorage ())))) {
6985- return true ;
6986- }
6976+ // Check for SYCL device compilation context.
6977+ if (!S.Context .getLangOpts ().SYCLIsDevice ) {
6978+ return false ;
69876979 }
6988- return false ;
6980+
6981+ const auto *VD = dyn_cast<VarDecl>(D);
6982+ if (!VD)
6983+ return false ;
6984+
6985+ // Exclude implicit parameters and non-type template parameters.
6986+ if (VD->getKind () == Decl::ImplicitParam ||
6987+ VD->getKind () == Decl::NonTypeTemplateParm)
6988+ return false ;
6989+
6990+ // Check for non-static data member.
6991+ if (isa<FieldDecl>(D))
6992+ return false ;
6993+
6994+ // Check for SYCL device global attribute decoration.
6995+ if (S.SYCL ().isTypeDecoratedWithDeclAttribute <SYCLDeviceGlobalAttr>(
6996+ VD->getType ()))
6997+ return false ;
6998+
6999+ // Check for constant variables and variables in the OpenCL constant
7000+ // address space.
7001+ if (VD->getType ().isConstQualified () ||
7002+ VD->getType ().getAddressSpace () == LangAS::opencl_constant)
7003+ return false ;
7004+
7005+ // Check for static storage class or local storage.
7006+ if (VD->getStorageClass () == SC_Static || VD->hasLocalStorage ())
7007+ return false ;
7008+
7009+ return true ;
69897010}
69907011
69917012void Sema::AddSYCLIntelNoGlobalWorkOffsetAttr (Decl *D,
@@ -7069,9 +7090,8 @@ static void handleSYCLIntelSinglePumpAttr(Sema &S, Decl *D,
70697090 // Check attribute applies to field, constant variables, local variables,
70707091 // static variables, non-static data members, and device_global variables
70717092 // for the device compilation.
7072- if (S.Context .getLangOpts ().SYCLIsDevice &&
7073- ((D->getKind () == Decl::ParmVar) ||
7074- CheckValidFPGAMemoryAttributesVar (S, D))) {
7093+ if ((D->getKind () == Decl::ParmVar) ||
7094+ CheckValidFPGAMemoryAttributesVar (S, D)) {
70757095 S.Diag (AL.getLoc (), diag::err_fpga_attribute_incorrect_variable)
70767096 << AL << /* agent memory arguments*/ 0 ;
70777097 return ;
@@ -7103,9 +7123,8 @@ static void handleSYCLIntelDoublePumpAttr(Sema &S, Decl *D,
71037123 // Check attribute applies to field, constant variables, local variables,
71047124 // static variables, non-static data members, and device_global variables
71057125 // for the device compilation.
7106- if (S.Context .getLangOpts ().SYCLIsDevice &&
7107- ((D->getKind () == Decl::ParmVar) ||
7108- CheckValidFPGAMemoryAttributesVar (S, D))) {
7126+ if ((D->getKind () == Decl::ParmVar) ||
7127+ CheckValidFPGAMemoryAttributesVar (S, D)) {
71097128 S.Diag (AL.getLoc (), diag::err_fpga_attribute_incorrect_variable)
71107129 << AL << /* agent memory arguments*/ 0 ;
71117130 return ;
@@ -7158,8 +7177,7 @@ static void handleSYCLIntelMemoryAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
71587177 // Check attribute applies to field, constant variables, local variables,
71597178 // static variables, agent memory arguments, non-static data members,
71607179 // and device_global variables for the device compilation.
7161- if (S.Context .getLangOpts ().SYCLIsDevice &&
7162- CheckValidFPGAMemoryAttributesVar (S, D)) {
7180+ if (CheckValidFPGAMemoryAttributesVar (S, D)) {
71637181 S.Diag (AL.getLoc (), diag::err_fpga_attribute_incorrect_variable)
71647182 << AL << /* agent memory arguments*/ 1 ;
71657183 return ;
@@ -7187,9 +7205,8 @@ static void handleSYCLIntelRegisterAttr(Sema &S, Decl *D,
71877205 // Check attribute applies to field, constant variables, local variables,
71887206 // static variables, non-static data members, and device_global variables
71897207 // for the device compilation.
7190- if (S.Context .getLangOpts ().SYCLIsDevice &&
7191- ((D->getKind () == Decl::ParmVar) ||
7192- CheckValidFPGAMemoryAttributesVar (S, D))) {
7208+ if ((D->getKind () == Decl::ParmVar) ||
7209+ CheckValidFPGAMemoryAttributesVar (S, D)) {
71937210 S.Diag (A.getLoc (), diag::err_fpga_attribute_incorrect_variable)
71947211 << A << /* agent memory arguments*/ 0 ;
71957212 return ;
@@ -7233,8 +7250,7 @@ void Sema::AddSYCLIntelBankWidthAttr(Decl *D, const AttributeCommonInfo &CI,
72337250 // Check attribute applies to field, constant variables, local variables,
72347251 // static variables, agent memory arguments, non-static data members,
72357252 // and device_global variables for the device compilation.
7236- if (Context.getLangOpts ().SYCLIsDevice &&
7237- CheckValidFPGAMemoryAttributesVar (*this , D)) {
7253+ if (CheckValidFPGAMemoryAttributesVar (*this , D)) {
72387254 Diag (CI.getLoc (), diag::err_fpga_attribute_incorrect_variable)
72397255 << CI << /* agent memory arguments*/ 1 ;
72407256 return ;
@@ -7327,8 +7343,7 @@ void Sema::AddSYCLIntelNumBanksAttr(Decl *D, const AttributeCommonInfo &CI,
73277343 // Check attribute applies to constant variables, local variables,
73287344 // static variables, agent memory arguments, non-static data members,
73297345 // and device_global variables for the device compilation.
7330- if (Context.getLangOpts ().SYCLIsDevice &&
7331- CheckValidFPGAMemoryAttributesVar (*this , D)) {
7346+ if (CheckValidFPGAMemoryAttributesVar (*this , D)) {
73327347 Diag (CI.getLoc (), diag::err_fpga_attribute_incorrect_variable)
73337348 << CI << /* agent memory arguments*/ 1 ;
73347349 return ;
@@ -7404,8 +7419,7 @@ static void handleIntelSimpleDualPortAttr(Sema &S, Decl *D,
74047419 // Check attribute applies to field, constant variables, local variables,
74057420 // static variables, agent memory arguments, non-static data members,
74067421 // and device_global variables for the device compilation.
7407- if (S.Context .getLangOpts ().SYCLIsDevice &&
7408- CheckValidFPGAMemoryAttributesVar (S, D)) {
7422+ if (CheckValidFPGAMemoryAttributesVar (S, D)) {
74097423 S.Diag (AL.getLoc (), diag::err_fpga_attribute_incorrect_variable)
74107424 << AL << /* agent memory arguments*/ 1 ;
74117425 return ;
@@ -7440,8 +7454,7 @@ void Sema::AddSYCLIntelMaxReplicatesAttr(Decl *D, const AttributeCommonInfo &CI,
74407454 // Check attribute applies to field, constant variables, local variables,
74417455 // static variables, agent memory arguments, non-static data members,
74427456 // and device_global variables for the device compilation.
7443- if (Context.getLangOpts ().SYCLIsDevice &&
7444- CheckValidFPGAMemoryAttributesVar (*this , D)) {
7457+ if (CheckValidFPGAMemoryAttributesVar (*this , D)) {
74457458 Diag (CI.getLoc (), diag::err_fpga_attribute_incorrect_variable)
74467459 << CI << /* agent memory arguments*/ 1 ;
74477460 return ;
@@ -7533,9 +7546,8 @@ static void handleSYCLIntelMergeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
75337546 // Check attribute applies to field, constant variables, local variables,
75347547 // static variables, non-static data members, and device_global variables
75357548 // for the device compilation.
7536- if (S.Context .getLangOpts ().SYCLIsDevice &&
7537- ((D->getKind () == Decl::ParmVar) ||
7538- CheckValidFPGAMemoryAttributesVar (S, D))) {
7549+ if ((D->getKind () == Decl::ParmVar) ||
7550+ CheckValidFPGAMemoryAttributesVar (S, D)) {
75397551 S.Diag (AL.getLoc (), diag::err_fpga_attribute_incorrect_variable)
75407552 << AL << /* agent memory arguments*/ 0 ;
75417553 return ;
@@ -7629,8 +7641,7 @@ void Sema::AddSYCLIntelBankBitsAttr(Decl *D, const AttributeCommonInfo &CI,
76297641 // Check attribute applies to field, constant variables, local variables,
76307642 // static variables, agent memory arguments, non-static data members,
76317643 // and device_global variables for the device compilation.
7632- if (Context.getLangOpts ().SYCLIsDevice &&
7633- CheckValidFPGAMemoryAttributesVar (*this , D)) {
7644+ if (CheckValidFPGAMemoryAttributesVar (*this , D)) {
76347645 Diag (CI.getLoc (), diag::err_fpga_attribute_incorrect_variable)
76357646 << CI << /* agent memory arguments*/ 1 ;
76367647 return ;
@@ -7732,8 +7743,7 @@ void Sema::AddSYCLIntelForcePow2DepthAttr(Decl *D,
77327743 // Check attribute applies to field, constant variables, local variables,
77337744 // static variables, agent memory arguments, non-static data members,
77347745 // and device_global variables for the device compilation.
7735- if (Context.getLangOpts ().SYCLIsDevice &&
7736- CheckValidFPGAMemoryAttributesVar (*this , D)) {
7746+ if (CheckValidFPGAMemoryAttributesVar (*this , D)) {
77377747 Diag (CI.getLoc (), diag::err_fpga_attribute_incorrect_variable)
77387748 << CI << /* agent memory arguments*/ 1 ;
77397749 return ;
0 commit comments