@@ -207,11 +207,6 @@ static std::enable_if_t<std::is_base_of_v<Attr, T>, SourceLocation>
207
207
getAttrLoc (const T &AL) {
208
208
return AL.getLocation ();
209
209
}
210
- template <typename T,
211
- std::enable_if_t <std::is_same_v<AttributeCommonInfo, T>, bool > = true >
212
- static SourceLocation getAttrLoc (const T &AL) {
213
- return AL.getScopeLoc ();
214
- }
215
210
static SourceLocation getAttrLoc (const ParsedAttr &AL) { return AL.getLoc (); }
216
211
217
212
// / If Expr is a valid integer constant, get the value of the integer
@@ -4452,6 +4447,25 @@ void Sema::AddSYCLIntelMaxGlobalWorkDimAttr(Decl *D,
4452
4447
D->addAttr (::new (Context) SYCLIntelMaxGlobalWorkDimAttr (Context, CI, E));
4453
4448
}
4454
4449
4450
+ // Check that the value is a non-negative integer constant that can fit in
4451
+ // 32-bits. Issue correct error message and return false on failure.
4452
+ bool static check32BitInt (const Expr *E, Sema &S, llvm::APSInt &I,
4453
+ const AttributeCommonInfo &CI) {
4454
+ if (!I.isIntN (32 )) {
4455
+ S.Diag (E->getExprLoc (), diag::err_ice_too_large)
4456
+ << llvm::toString (I, 10 , false ) << 32 << /* Unsigned */ 1 ;
4457
+ return false ;
4458
+ }
4459
+
4460
+ if (I.isSigned () && I.isNegative ()) {
4461
+ S.Diag (E->getExprLoc (), diag::err_attribute_requires_positive_integer)
4462
+ << CI << /* Non-negative */ 1 ;
4463
+ return false ;
4464
+ }
4465
+
4466
+ return true ;
4467
+ }
4468
+
4455
4469
void Sema::AddSYCLIntelMinWorkGroupsPerComputeUnitAttr (
4456
4470
Decl *D, const AttributeCommonInfo &CI, Expr *E) {
4457
4471
if (Context.getLangOpts ().SYCLIsDevice &&
@@ -4461,20 +4475,15 @@ void Sema::AddSYCLIntelMinWorkGroupsPerComputeUnitAttr(
4461
4475
return ;
4462
4476
}
4463
4477
if (!E->isValueDependent ()) {
4464
- uint32_t Val;
4465
- if (!checkUInt32Argument (*this , CI, E, Val, UINT_MAX /* Idx */ ,
4466
- true /* StrictlyUnsigned */ ))
4467
- return ;
4468
-
4469
4478
// Validate that we have an integer constant expression and then store the
4470
4479
// converted constant expression into the semantic attribute so that we
4471
4480
// don't have to evaluate it again later.
4472
4481
llvm::APSInt ArgVal;
4473
4482
ExprResult Res = VerifyIntegerConstantExpression (E, &ArgVal);
4474
4483
if (Res.isInvalid ())
4475
4484
return ;
4476
- if (Val != ArgVal)
4477
- llvm_unreachable ( " Values must not differ. " ) ;
4485
+ if (! check32BitInt (E, * this , ArgVal, CI) )
4486
+ return ;
4478
4487
E = Res.get ();
4479
4488
4480
4489
// Check to see if there's a duplicate attribute with different values
@@ -4526,21 +4535,16 @@ void Sema::AddSYCLIntelMaxWorkGroupsPerMultiprocessorAttr(
4526
4535
}
4527
4536
}
4528
4537
if (!E->isValueDependent ()) {
4529
- uint32_t Val;
4530
- if (!checkUInt32Argument (*this , CI, E, Val, UINT_MAX /* Idx */ ,
4531
- true /* StrictlyUnsigned */ ))
4532
- return ;
4533
-
4534
4538
// Validate that we have an integer constant expression and then store the
4535
4539
// converted constant expression into the semantic attribute so that we
4536
4540
// don't have to evaluate it again later.
4537
4541
llvm::APSInt ArgVal;
4538
4542
ExprResult Res = VerifyIntegerConstantExpression (E, &ArgVal);
4539
4543
if (Res.isInvalid ())
4540
4544
return ;
4545
+ if (!check32BitInt (E, *this , ArgVal, CI))
4546
+ return ;
4541
4547
E = Res.get ();
4542
- if (Val != ArgVal)
4543
- llvm_unreachable (" Values must not differ." );
4544
4548
4545
4549
// Check to see if there's a duplicate attribute with different values
4546
4550
// already applied to the declaration.
0 commit comments