@@ -3095,6 +3095,22 @@ static bool checkWorkGroupSizeValues(Sema &S, Decl *D, const ParsedAttr &AL) {
3095
3095
return Result;
3096
3096
}
3097
3097
3098
+ static Expr *checkWorkSizeAttrExpr (Sema &S, const ParsedAttr &CI,
3099
+ Expr *E) {
3100
+ assert (E && " Attribute must have an argument." );
3101
+
3102
+ if (!E->isInstantiationDependent ()) {
3103
+ llvm::APSInt ArgVal;
3104
+ ExprResult ICE = S.VerifyIntegerConstantExpression (E, &ArgVal);
3105
+
3106
+ if (ICE.isInvalid ())
3107
+ return nullptr ;
3108
+
3109
+ E = ICE.get ();
3110
+ }
3111
+ return E;
3112
+ }
3113
+
3098
3114
// Handles reqd_work_group_size and max_work_group_size.
3099
3115
template <typename WorkGroupAttr>
3100
3116
static void handleWorkGroupSize (Sema &S, Decl *D, const ParsedAttr &AL) {
@@ -3132,27 +3148,28 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
3132
3148
3133
3149
ASTContext &Ctx = S.getASTContext ();
3134
3150
3135
- if (!XDimExpr->isValueDependent () || !YDimExpr-> isValueDependent () ||
3136
- !ZDimExpr->isValueDependent ()) {
3151
+ if (!XDimExpr->isValueDependent () &&
3152
+ !YDimExpr-> isValueDependent () && ! ZDimExpr->isValueDependent ()) {
3137
3153
Optional<llvm::APSInt> XDimVal = XDimExpr->getIntegerConstantExpr (Ctx);
3138
3154
Optional<llvm::APSInt> YDimVal = YDimExpr->getIntegerConstantExpr (Ctx);
3139
3155
Optional<llvm::APSInt> ZDimVal = ZDimExpr->getIntegerConstantExpr (Ctx);
3140
3156
3157
+ XDimExpr = checkWorkSizeAttrExpr (S, AL, XDimExpr);
3158
+ YDimExpr = checkWorkSizeAttrExpr (S, AL, YDimExpr);
3159
+ ZDimExpr = checkWorkSizeAttrExpr (S, AL, ZDimExpr);
3160
+
3161
+ if (!XDimExpr || !YDimExpr || !ZDimExpr)
3162
+ return ;
3163
+
3164
+ // Skip SEMA if we're in a template, this will be diagnosed later.
3165
+ if (S.getCurLexicalContext ()->isDependentContext ())
3166
+ return ;
3167
+
3141
3168
if (AL.getKind () == ParsedAttr::AT_ReqdWorkGroupSize) {
3142
3169
if (const auto *A = D->getAttr <SYCLIntelNumSimdWorkItemsAttr>()) {
3143
3170
int64_t NumSimdWorkItems =
3144
3171
A->getValue ()->getIntegerConstantExpr (Ctx)->getSExtValue ();
3145
3172
3146
- assert (NumSimdWorkItems && XDimVal &&
3147
- " Argument should be an integer constant expression" );
3148
- assert (NumSimdWorkItems && YDimVal &&
3149
- " Argument should be an integer constant expression" );
3150
- assert (NumSimdWorkItems && ZDimVal &&
3151
- " Argument should be an integer constant expression" );
3152
-
3153
- if (NumSimdWorkItems == 0 )
3154
- return ;
3155
-
3156
3173
if (!(XDimVal->getZExtValue () % NumSimdWorkItems == 0 ||
3157
3174
YDimVal->getZExtValue () % NumSimdWorkItems == 0 ||
3158
3175
ZDimVal->getZExtValue () % NumSimdWorkItems == 0 )) {
@@ -3169,24 +3186,17 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
3169
3186
Optional<llvm::APSInt> ExistingYDimVal = ExistingAttr->getYDimVal (Ctx);
3170
3187
Optional<llvm::APSInt> ExistingZDimVal = ExistingAttr->getZDimVal (Ctx);
3171
3188
3172
- assert (XDimVal && ExistingXDimVal &&
3173
- " Argument should be an integer constant expression" );
3174
- assert (YDimVal && ExistingYDimVal &&
3175
- " Argument should be an integer constant expression" );
3176
- assert (ZDimVal && ExistingZDimVal &&
3177
- " Argument should be an integer constant expression" );
3178
-
3179
3189
// Compare attribute arguments value and warn for a mismatch.
3180
3190
if (ExistingXDimVal != XDimVal || ExistingYDimVal != YDimVal ||
3181
3191
ExistingZDimVal != ZDimVal) {
3182
3192
S.Diag (AL.getLoc (), diag::warn_duplicate_attribute) << AL;
3183
3193
S.Diag (ExistingAttr->getLocation (), diag::note_conflicting_attribute);
3184
3194
}
3185
3195
}
3186
- }
3187
3196
3188
- if (!checkWorkGroupSizeValues (S, D, AL))
3189
- return ;
3197
+ if (!checkWorkGroupSizeValues (S, D, AL))
3198
+ return ;
3199
+ }
3190
3200
3191
3201
S.addIntelSYCLTripleArgFunctionAttr <WorkGroupAttr>(D, AL, XDimExpr, YDimExpr,
3192
3202
ZDimExpr);
@@ -3246,26 +3256,28 @@ static void handleNumSimdWorkItemsAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3246
3256
3247
3257
S.CheckDeprecatedSYCLAttributeSpelling (AL);
3248
3258
3249
- if (!E->isValueDependent ()) {
3259
+ if (!E->isValueDependent () || !E-> isInstantiationDependent () ) {
3250
3260
ASTContext &Ctx = S.getASTContext ();
3251
- Optional<llvm::APSInt> ArgVal = E->getIntegerConstantExpr (Ctx);
3261
+ llvm::APSInt ArgVal;
3262
+ ExprResult ICE = S.VerifyIntegerConstantExpression (E, &ArgVal);
3263
+
3264
+ if (ICE.isInvalid ())
3265
+ return ;
3266
+
3267
+ E = ICE.get ();
3268
+ int64_t NumSimdWorkItems = ArgVal.getSExtValue ();
3269
+
3270
+ if (NumSimdWorkItems == 0 ) {
3271
+ S.Diag (E->getExprLoc (), diag::err_attribute_argument_is_zero)
3272
+ << AL << E->getSourceRange ();
3273
+ return ;
3274
+ }
3252
3275
3253
3276
if (const auto *A = D->getAttr <ReqdWorkGroupSizeAttr>()) {
3254
3277
Optional<llvm::APSInt> XDimVal = A->getXDimVal (Ctx);
3255
3278
Optional<llvm::APSInt> YDimVal = A->getYDimVal (Ctx);
3256
3279
Optional<llvm::APSInt> ZDimVal = A->getZDimVal (Ctx);
3257
3280
3258
- assert (ArgVal && XDimVal &&
3259
- " Argument should be an integer constant expression" );
3260
- assert (ArgVal && YDimVal &&
3261
- " Argument should be an integer constant expression" );
3262
- assert (ArgVal && ZDimVal &&
3263
- " Argument should be an integer constant expression" );
3264
-
3265
- int64_t NumSimdWorkItems = ArgVal->getSExtValue ();
3266
- if (NumSimdWorkItems == 0 )
3267
- return ;
3268
-
3269
3281
if (!(XDimVal->getZExtValue () % NumSimdWorkItems == 0 ||
3270
3282
YDimVal->getZExtValue () % NumSimdWorkItems == 0 ||
3271
3283
ZDimVal->getZExtValue () % NumSimdWorkItems == 0 )) {
@@ -6035,14 +6047,14 @@ void Sema::addSYCLIntelPipeIOAttr(Decl *D, const AttributeCommonInfo &Attr,
6035
6047
Optional<llvm::APSInt> ArgVal = E->getIntegerConstantExpr (getASTContext ());
6036
6048
if (!ArgVal) {
6037
6049
Diag (E->getExprLoc (), diag::err_attribute_argument_type)
6038
- << Attr. getAttrName () << AANT_ArgumentIntegerConstant
6050
+ << Attr << AANT_ArgumentIntegerConstant
6039
6051
<< E->getSourceRange ();
6040
6052
return ;
6041
6053
}
6042
6054
int32_t ArgInt = ArgVal->getSExtValue ();
6043
6055
if (ArgInt < 0 ) {
6044
6056
Diag (E->getExprLoc (), diag::err_attribute_requires_positive_integer)
6045
- << Attr. getAttrName () << /* non-negative*/ 1 ;
6057
+ << Attr << /* non-negative*/ 1 ;
6046
6058
return ;
6047
6059
}
6048
6060
}
0 commit comments