@@ -5363,27 +5363,37 @@ void OmpStructureChecker::CheckArraySection(
5363
5363
if (const auto *triplet{
5364
5364
std::get_if<parser::SubscriptTriplet>(&subscript.u )}) {
5365
5365
if (std::get<0 >(triplet->t ) && std::get<1 >(triplet->t )) {
5366
+ std::optional<int64_t > strideVal{std::nullopt};
5367
+ if (const auto &strideExpr = std::get<2 >(triplet->t )) {
5368
+ // OpenMP 6.0 Section 5.2.5: Array Sections
5369
+ // Restrictions: if a stride expression is specified it must be
5370
+ // positive. A stride of 0 doesn't make sense.
5371
+ strideVal = GetIntValue (strideExpr);
5372
+ if (strideVal && *strideVal < 1 ) {
5373
+ context_.Say (GetContext ().clauseSource ,
5374
+ " '%s' in %s clause must have a positive stride" _err_en_US,
5375
+ name.ToString (),
5376
+ parser::ToUpperCaseLetters (getClauseName (clause).str ()));
5377
+ }
5378
+ }
5366
5379
const auto &lower{std::get<0 >(triplet->t )};
5367
5380
const auto &upper{std::get<1 >(triplet->t )};
5368
5381
if (lower && upper) {
5369
5382
const auto lval{GetIntValue (lower)};
5370
5383
const auto uval{GetIntValue (upper)};
5371
- if (lval && uval && *uval < *lval) {
5372
- context_.Say (GetContext ().clauseSource ,
5373
- " '%s' in %s clause"
5374
- " is a zero size array section" _err_en_US,
5375
- name.ToString (),
5376
- parser::ToUpperCaseLetters (getClauseName (clause).str ()));
5377
- break ;
5378
- } else if (std::get<2 >(triplet->t )) {
5379
- const auto &strideExpr{std::get<2 >(triplet->t )};
5380
- if (strideExpr) {
5381
- if (clause == llvm::omp::Clause::OMPC_depend) {
5382
- context_.Say (GetContext ().clauseSource ,
5383
- " Stride should not be specified for array section in "
5384
- " DEPEND "
5385
- " clause" _err_en_US);
5386
- }
5384
+ if (lval && uval) {
5385
+ int64_t sectionLen = *uval - *lval;
5386
+ if (strideVal) {
5387
+ sectionLen = sectionLen / *strideVal;
5388
+ }
5389
+
5390
+ if (sectionLen < 1 ) {
5391
+ context_.Say (GetContext ().clauseSource ,
5392
+ " '%s' in %s clause"
5393
+ " is a zero size array section" _err_en_US,
5394
+ name.ToString (),
5395
+ parser::ToUpperCaseLetters (getClauseName (clause).str ()));
5396
+ break ;
5387
5397
}
5388
5398
}
5389
5399
}
0 commit comments