@@ -6973,19 +6973,40 @@ static bool checkForDuplicateAttribute(Sema &S, Decl *D,
6973
6973
// Checks if FPGA memory attributes apply on valid variables.
6974
6974
// Returns true if an error occured.
6975
6975
static 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 ;
6987
6979
}
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 ;
6989
7010
}
6990
7011
6991
7012
void Sema::AddSYCLIntelNoGlobalWorkOffsetAttr (Decl *D,
@@ -7069,9 +7090,8 @@ static void handleSYCLIntelSinglePumpAttr(Sema &S, Decl *D,
7069
7090
// Check attribute applies to field, constant variables, local variables,
7070
7091
// static variables, non-static data members, and device_global variables
7071
7092
// 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)) {
7075
7095
S.Diag (AL.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7076
7096
<< AL << /* agent memory arguments*/ 0 ;
7077
7097
return ;
@@ -7103,9 +7123,8 @@ static void handleSYCLIntelDoublePumpAttr(Sema &S, Decl *D,
7103
7123
// Check attribute applies to field, constant variables, local variables,
7104
7124
// static variables, non-static data members, and device_global variables
7105
7125
// 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)) {
7109
7128
S.Diag (AL.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7110
7129
<< AL << /* agent memory arguments*/ 0 ;
7111
7130
return ;
@@ -7158,8 +7177,7 @@ static void handleSYCLIntelMemoryAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
7158
7177
// Check attribute applies to field, constant variables, local variables,
7159
7178
// static variables, agent memory arguments, non-static data members,
7160
7179
// and device_global variables for the device compilation.
7161
- if (S.Context .getLangOpts ().SYCLIsDevice &&
7162
- CheckValidFPGAMemoryAttributesVar (S, D)) {
7180
+ if (CheckValidFPGAMemoryAttributesVar (S, D)) {
7163
7181
S.Diag (AL.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7164
7182
<< AL << /* agent memory arguments*/ 1 ;
7165
7183
return ;
@@ -7187,9 +7205,8 @@ static void handleSYCLIntelRegisterAttr(Sema &S, Decl *D,
7187
7205
// Check attribute applies to field, constant variables, local variables,
7188
7206
// static variables, non-static data members, and device_global variables
7189
7207
// 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)) {
7193
7210
S.Diag (A.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7194
7211
<< A << /* agent memory arguments*/ 0 ;
7195
7212
return ;
@@ -7233,8 +7250,7 @@ void Sema::AddSYCLIntelBankWidthAttr(Decl *D, const AttributeCommonInfo &CI,
7233
7250
// Check attribute applies to field, constant variables, local variables,
7234
7251
// static variables, agent memory arguments, non-static data members,
7235
7252
// and device_global variables for the device compilation.
7236
- if (Context.getLangOpts ().SYCLIsDevice &&
7237
- CheckValidFPGAMemoryAttributesVar (*this , D)) {
7253
+ if (CheckValidFPGAMemoryAttributesVar (*this , D)) {
7238
7254
Diag (CI.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7239
7255
<< CI << /* agent memory arguments*/ 1 ;
7240
7256
return ;
@@ -7327,8 +7343,7 @@ void Sema::AddSYCLIntelNumBanksAttr(Decl *D, const AttributeCommonInfo &CI,
7327
7343
// Check attribute applies to constant variables, local variables,
7328
7344
// static variables, agent memory arguments, non-static data members,
7329
7345
// and device_global variables for the device compilation.
7330
- if (Context.getLangOpts ().SYCLIsDevice &&
7331
- CheckValidFPGAMemoryAttributesVar (*this , D)) {
7346
+ if (CheckValidFPGAMemoryAttributesVar (*this , D)) {
7332
7347
Diag (CI.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7333
7348
<< CI << /* agent memory arguments*/ 1 ;
7334
7349
return ;
@@ -7404,8 +7419,7 @@ static void handleIntelSimpleDualPortAttr(Sema &S, Decl *D,
7404
7419
// Check attribute applies to field, constant variables, local variables,
7405
7420
// static variables, agent memory arguments, non-static data members,
7406
7421
// and device_global variables for the device compilation.
7407
- if (S.Context .getLangOpts ().SYCLIsDevice &&
7408
- CheckValidFPGAMemoryAttributesVar (S, D)) {
7422
+ if (CheckValidFPGAMemoryAttributesVar (S, D)) {
7409
7423
S.Diag (AL.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7410
7424
<< AL << /* agent memory arguments*/ 1 ;
7411
7425
return ;
@@ -7440,8 +7454,7 @@ void Sema::AddSYCLIntelMaxReplicatesAttr(Decl *D, const AttributeCommonInfo &CI,
7440
7454
// Check attribute applies to field, constant variables, local variables,
7441
7455
// static variables, agent memory arguments, non-static data members,
7442
7456
// and device_global variables for the device compilation.
7443
- if (Context.getLangOpts ().SYCLIsDevice &&
7444
- CheckValidFPGAMemoryAttributesVar (*this , D)) {
7457
+ if (CheckValidFPGAMemoryAttributesVar (*this , D)) {
7445
7458
Diag (CI.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7446
7459
<< CI << /* agent memory arguments*/ 1 ;
7447
7460
return ;
@@ -7533,9 +7546,8 @@ static void handleSYCLIntelMergeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
7533
7546
// Check attribute applies to field, constant variables, local variables,
7534
7547
// static variables, non-static data members, and device_global variables
7535
7548
// 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)) {
7539
7551
S.Diag (AL.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7540
7552
<< AL << /* agent memory arguments*/ 0 ;
7541
7553
return ;
@@ -7629,8 +7641,7 @@ void Sema::AddSYCLIntelBankBitsAttr(Decl *D, const AttributeCommonInfo &CI,
7629
7641
// Check attribute applies to field, constant variables, local variables,
7630
7642
// static variables, agent memory arguments, non-static data members,
7631
7643
// and device_global variables for the device compilation.
7632
- if (Context.getLangOpts ().SYCLIsDevice &&
7633
- CheckValidFPGAMemoryAttributesVar (*this , D)) {
7644
+ if (CheckValidFPGAMemoryAttributesVar (*this , D)) {
7634
7645
Diag (CI.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7635
7646
<< CI << /* agent memory arguments*/ 1 ;
7636
7647
return ;
@@ -7732,8 +7743,7 @@ void Sema::AddSYCLIntelForcePow2DepthAttr(Decl *D,
7732
7743
// Check attribute applies to field, constant variables, local variables,
7733
7744
// static variables, agent memory arguments, non-static data members,
7734
7745
// and device_global variables for the device compilation.
7735
- if (Context.getLangOpts ().SYCLIsDevice &&
7736
- CheckValidFPGAMemoryAttributesVar (*this , D)) {
7746
+ if (CheckValidFPGAMemoryAttributesVar (*this , D)) {
7737
7747
Diag (CI.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7738
7748
<< CI << /* agent memory arguments*/ 1 ;
7739
7749
return ;
0 commit comments