@@ -7443,6 +7443,24 @@ static bool checkForDuplicateAttribute(Sema &S, Decl *D,
7443
7443
return false ;
7444
7444
}
7445
7445
7446
+ // Checks if FPGA memory attributes apply on valid variables.
7447
+ // Returns true if an error occured.
7448
+ static bool CheckValidFPGAMemoryAttributesVar (Sema &S, Decl *D) {
7449
+ if (const auto *VD = dyn_cast<VarDecl>(D)) {
7450
+ if (!(isa<FieldDecl>(D) ||
7451
+ (VD->getKind () != Decl::ImplicitParam &&
7452
+ VD->getKind () != Decl::NonTypeTemplateParm &&
7453
+ (S.isTypeDecoratedWithDeclAttribute <SYCLDeviceGlobalAttr>(
7454
+ VD->getType ()) ||
7455
+ VD->getType ().isConstQualified () ||
7456
+ VD->getType ().getAddressSpace () == LangAS::opencl_constant ||
7457
+ VD->getStorageClass () == SC_Static || VD->hasLocalStorage ())))) {
7458
+ return true ;
7459
+ }
7460
+ }
7461
+ return false ;
7462
+ }
7463
+
7446
7464
void Sema::AddSYCLIntelNoGlobalWorkOffsetAttr (Decl *D,
7447
7465
const AttributeCommonInfo &CI,
7448
7466
Expr *E) {
@@ -7521,6 +7539,15 @@ static void handleSYCLIntelSinglePumpAttr(Sema &S, Decl *D,
7521
7539
}
7522
7540
}
7523
7541
7542
+ // Check attribute applies to field, constant variables, local variables,
7543
+ // static variables, non-static data members, and device_global variables.
7544
+ if ((D->getKind () == Decl::ParmVar) ||
7545
+ CheckValidFPGAMemoryAttributesVar (S, D)) {
7546
+ S.Diag (AL.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7547
+ << AL << /* agent memory arguments*/ 0 ;
7548
+ return ;
7549
+ }
7550
+
7524
7551
// If the declaration does not have an [[intel::fpga_memory]]
7525
7552
// attribute, this creates one as an implicit attribute.
7526
7553
if (!D->hasAttr <SYCLIntelMemoryAttr>())
@@ -7544,6 +7571,15 @@ static void handleSYCLIntelDoublePumpAttr(Sema &S, Decl *D,
7544
7571
}
7545
7572
}
7546
7573
7574
+ // Check attribute applies to field, constant variables, local variables,
7575
+ // static variables, non-static data members, and device_global variables.
7576
+ if ((D->getKind () == Decl::ParmVar) ||
7577
+ CheckValidFPGAMemoryAttributesVar (S, D)) {
7578
+ S.Diag (AL.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7579
+ << AL << /* agent memory arguments*/ 0 ;
7580
+ return ;
7581
+ }
7582
+
7547
7583
// If the declaration does not have an [[intel::fpga_memory]]
7548
7584
// attribute, this creates one as an implicit attribute.
7549
7585
if (!D->hasAttr <SYCLIntelMemoryAttr>())
@@ -7591,6 +7627,15 @@ static void handleSYCLIntelMemoryAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
7591
7627
D->dropAttr <SYCLIntelMemoryAttr>();
7592
7628
}
7593
7629
7630
+ // Check attribute applies to field, constant variables, local variables,
7631
+ // static variables, agent memory arguments, non-static data members,
7632
+ // and device_global variables.
7633
+ if (CheckValidFPGAMemoryAttributesVar (S, D)) {
7634
+ S.Diag (AL.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7635
+ << AL << /* agent memory arguments*/ 1 ;
7636
+ return ;
7637
+ }
7638
+
7594
7639
D->addAttr (::new (S.Context ) SYCLIntelMemoryAttr (S.Context , AL, Kind));
7595
7640
}
7596
7641
@@ -7623,6 +7668,15 @@ static void handleSYCLIntelRegisterAttr(Sema &S, Decl *D,
7623
7668
}
7624
7669
}
7625
7670
7671
+ // Check attribute applies to field, constant variables, local variables,
7672
+ // static variables, non-static data members, and device_global variables.
7673
+ if ((D->getKind () == Decl::ParmVar) ||
7674
+ CheckValidFPGAMemoryAttributesVar (S, D)) {
7675
+ S.Diag (A.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7676
+ << A << /* agent memory arguments*/ 0 ;
7677
+ return ;
7678
+ }
7679
+
7626
7680
if (checkIntelFPGARegisterAttrCompatibility (S, D, A))
7627
7681
return ;
7628
7682
@@ -7661,6 +7715,15 @@ void Sema::AddSYCLIntelBankWidthAttr(Decl *D, const AttributeCommonInfo &CI,
7661
7715
return ;
7662
7716
}
7663
7717
7718
+ // Check attribute applies to field, constant variables, local variables,
7719
+ // static variables, agent memory arguments, non-static data members,
7720
+ // and device_global variables.
7721
+ if (CheckValidFPGAMemoryAttributesVar (*this , D)) {
7722
+ Diag (CI.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7723
+ << CI << /* agent memory arguments*/ 1 ;
7724
+ return ;
7725
+ }
7726
+
7664
7727
// Check to see if there's a duplicate attribute with different values
7665
7728
// already applied to the declaration.
7666
7729
if (const auto *DeclAttr = D->getAttr <SYCLIntelBankWidthAttr>()) {
@@ -7745,6 +7808,15 @@ void Sema::AddSYCLIntelNumBanksAttr(Decl *D, const AttributeCommonInfo &CI,
7745
7808
}
7746
7809
}
7747
7810
7811
+ // Check attribute applies to constant variables, local variables,
7812
+ // static variables, agent memory arguments, non-static data members,
7813
+ // and device_global variables.
7814
+ if (CheckValidFPGAMemoryAttributesVar (*this , D)) {
7815
+ Diag (CI.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7816
+ << CI << /* agent memory arguments*/ 1 ;
7817
+ return ;
7818
+ }
7819
+
7748
7820
// Check to see if there's a duplicate attribute with different values
7749
7821
// already applied to the declaration.
7750
7822
if (const auto *DeclAttr = D->getAttr <SYCLIntelNumBanksAttr>()) {
@@ -7812,6 +7884,15 @@ static void handleIntelSimpleDualPortAttr(Sema &S, Decl *D,
7812
7884
}
7813
7885
}
7814
7886
7887
+ // Check attribute applies to field, constant variables, local variables,
7888
+ // static variables, agent memory arguments, non-static data members,
7889
+ // and device_global variables.
7890
+ if (CheckValidFPGAMemoryAttributesVar (S, D)) {
7891
+ S.Diag (AL.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7892
+ << AL << /* agent memory arguments*/ 1 ;
7893
+ return ;
7894
+ }
7895
+
7815
7896
if (!D->hasAttr <SYCLIntelMemoryAttr>())
7816
7897
D->addAttr (SYCLIntelMemoryAttr::CreateImplicit (
7817
7898
S.Context , SYCLIntelMemoryAttr::Default));
@@ -7837,6 +7918,16 @@ void Sema::AddSYCLIntelMaxReplicatesAttr(Decl *D, const AttributeCommonInfo &CI,
7837
7918
<< CI << /* positive*/ 0 ;
7838
7919
return ;
7839
7920
}
7921
+
7922
+ // Check attribute applies to field, constant variables, local variables,
7923
+ // static variables, agent memory arguments, non-static data members,
7924
+ // and device_global variables.
7925
+ if (CheckValidFPGAMemoryAttributesVar (*this , D)) {
7926
+ Diag (CI.getLoc (), diag::err_fpga_attribute_incorrect_variable)
7927
+ << CI << /* agent memory arguments*/ 1 ;
7928
+ return ;
7929
+ }
7930
+
7840
7931
// Check to see if there's a duplicate attribute with different values
7841
7932
// already applied to the declaration.
7842
7933
if (const auto *DeclAttr = D->getAttr <SYCLIntelMaxReplicatesAttr>()) {
@@ -7920,6 +8011,15 @@ static void handleSYCLIntelMergeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
7920
8011
return ;
7921
8012
}
7922
8013
8014
+ // Check attribute applies to field, constant variables, local variables,
8015
+ // static variables, non-static data members, and device_global variables.
8016
+ if ((D->getKind () == Decl::ParmVar) ||
8017
+ CheckValidFPGAMemoryAttributesVar (S, D)) {
8018
+ S.Diag (AL.getLoc (), diag::err_fpga_attribute_incorrect_variable)
8019
+ << AL << /* agent memory arguments*/ 0 ;
8020
+ return ;
8021
+ }
8022
+
7923
8023
if (!D->hasAttr <SYCLIntelMemoryAttr>())
7924
8024
D->addAttr (SYCLIntelMemoryAttr::CreateImplicit (
7925
8025
S.Context , SYCLIntelMemoryAttr::Default));
@@ -8005,6 +8105,15 @@ void Sema::AddSYCLIntelBankBitsAttr(Decl *D, const AttributeCommonInfo &CI,
8005
8105
D->addAttr (SYCLIntelNumBanksAttr::CreateImplicit (Context, NBE));
8006
8106
}
8007
8107
8108
+ // Check attribute applies to field, constant variables, local variables,
8109
+ // static variables, agent memory arguments, non-static data members,
8110
+ // and device_global variables.
8111
+ if (CheckValidFPGAMemoryAttributesVar (*this , D)) {
8112
+ Diag (CI.getLoc (), diag::err_fpga_attribute_incorrect_variable)
8113
+ << CI << /* agent memory arguments*/ 1 ;
8114
+ return ;
8115
+ }
8116
+
8008
8117
if (!D->hasAttr <SYCLIntelMemoryAttr>())
8009
8118
D->addAttr (SYCLIntelMemoryAttr::CreateImplicit (
8010
8119
Context, SYCLIntelMemoryAttr::Default));
@@ -8030,6 +8139,22 @@ void Sema::AddSYCLIntelPrivateCopiesAttr(Decl *D, const AttributeCommonInfo &CI,
8030
8139
<< CI << /* non-negative*/ 1 ;
8031
8140
return ;
8032
8141
}
8142
+
8143
+ // Check attribute applies to field as well as const variables, non-static
8144
+ // local variables, non-static data members, and device_global variables.
8145
+ if (const auto *VD = dyn_cast<VarDecl>(D)) {
8146
+ if (!(isa<FieldDecl>(D) ||
8147
+ (VD->getKind () != Decl::ImplicitParam &&
8148
+ VD->getKind () != Decl::NonTypeTemplateParm &&
8149
+ VD->getKind () != Decl::ParmVar &&
8150
+ (VD->hasLocalStorage () ||
8151
+ isTypeDecoratedWithDeclAttribute<SYCLDeviceGlobalAttr>(
8152
+ VD->getType ()))))) {
8153
+ Diag (CI.getLoc (), diag::err_fpga_attribute_invalid_decl) << CI;
8154
+ return ;
8155
+ }
8156
+ }
8157
+
8033
8158
// Check to see if there's a duplicate attribute with different values
8034
8159
// already applied to the declaration.
8035
8160
if (const auto *DeclAttr = D->getAttr <SYCLIntelPrivateCopiesAttr>()) {
@@ -8080,6 +8205,15 @@ void Sema::AddSYCLIntelForcePow2DepthAttr(Decl *D,
8080
8205
return ;
8081
8206
}
8082
8207
8208
+ // Check attribute applies to field, constant variables, local variables,
8209
+ // static variables, agent memory arguments, non-static data members,
8210
+ // and device_global variables.
8211
+ if (CheckValidFPGAMemoryAttributesVar (*this , D)) {
8212
+ Diag (CI.getLoc (), diag::err_fpga_attribute_incorrect_variable)
8213
+ << CI << /* agent memory arguments*/ 1 ;
8214
+ return ;
8215
+ }
8216
+
8083
8217
// Check to see if there's a duplicate attribute with different values
8084
8218
// already applied to the declaration.
8085
8219
if (const auto *DeclAttr = D->getAttr <SYCLIntelForcePow2DepthAttr>()) {
0 commit comments