Skip to content

Commit c3b1395

Browse files
Add Semantic check for Flang OpenMP 4.5 - 2.7.1 schedule clause
Semantic check for the positive chunk size. Test Cases: omp-do-schedule01.f90 omp-do-schedule02.f90 omp-do-schedule03.f90 omp-do-schedule04.f90 Reviewed by: Kiran Chandramohan @kiranchandramohan Differential Revision: https://reviews.llvm.org/D89546
1 parent 454579e commit c3b1395

File tree

6 files changed

+98
-4
lines changed

6 files changed

+98
-4
lines changed

flang/lib/Semantics/check-directive-structure.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ class DirectiveStructureChecker : public virtual BaseChecker {
248248
void RequiresConstantPositiveParameter(
249249
const C &clause, const parser::ScalarIntConstantExpr &i);
250250

251-
void RequiresPositiveParameter(
252-
const C &clause, const parser::ScalarIntExpr &i);
251+
void RequiresPositiveParameter(const C &clause,
252+
const parser::ScalarIntExpr &i, llvm::StringRef paramName = "parameter");
253253

254254
void OptionalConstantPositiveParameter(
255255
const C &clause, const std::optional<parser::ScalarIntConstantExpr> &o);
@@ -462,12 +462,13 @@ void DirectiveStructureChecker<D, C, PC, ClauseEnumSize>::CheckRequired(C c) {
462462
template <typename D, typename C, typename PC, std::size_t ClauseEnumSize>
463463
void DirectiveStructureChecker<D, C, PC,
464464
ClauseEnumSize>::RequiresPositiveParameter(const C &clause,
465-
const parser::ScalarIntExpr &i) {
465+
const parser::ScalarIntExpr &i, llvm::StringRef paramName) {
466466
if (const auto v{GetIntValue(i)}) {
467467
if (*v <= 0) {
468468
context_.Say(GetContext().clauseSource,
469-
"The parameter of the %s clause must be "
469+
"The %s of the %s clause must be "
470470
"a positive integer expression"_err_en_US,
471+
paramName.str(),
471472
parser::ToUpperCaseLetters(getClauseName(clause).str()));
472473
}
473474
}

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,11 @@ void OmpStructureChecker::Enter(const parser::OmpScheduleClause &x) {
578578
parser::ToUpperCaseLetters(
579579
parser::OmpScheduleClause::EnumToString(kind)));
580580
}
581+
if (const auto &chunkExpr{
582+
std::get<std::optional<parser::ScalarIntExpr>>(x.t)}) {
583+
RequiresPositiveParameter(
584+
llvm::omp::Clause::OMPC_schedule, *chunkExpr, "chunk size");
585+
}
581586
}
582587

583588
if (ScheduleModifierHasType(
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
! RUN: %S/test_errors.sh %s %t %f18 -fopenmp
2+
! OpenMP Version 4.5
3+
! 2.7.1 Schedule Clause
4+
program omp_doSchedule
5+
integer :: i,n
6+
real :: a(100), y(100), z(100)
7+
!ERROR: The chunk size of the SCHEDULE clause must be a positive integer expression
8+
!$omp do schedule(static, -1)
9+
do i=2,n+1
10+
y(i) = z(i-1) + a(i)
11+
end do
12+
!$omp end do
13+
end program omp_doSchedule
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
!RUN: %S/test_errors.sh %s %t %f18 -fopenmp
2+
! OpenMP Version 4.5
3+
! 2.7.1 Schedule Clause
4+
program omp_doSchedule
5+
integer :: i,n
6+
real :: a(100), y(100), z(100)
7+
integer,parameter :: b = 10
8+
integer,parameter :: c = 11
9+
!ERROR: The chunk size of the SCHEDULE clause must be a positive integer expression
10+
!$omp do schedule(static,b-c)
11+
do i=2,n+1
12+
y(i) = z(i-1) + a(i)
13+
end do
14+
!$omp end do
15+
end program omp_doSchedule
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
! RUN: %S/test_symbols.sh %s %t %f18 -fopenmp
2+
! OpenMP Version 4.5
3+
! 2.7.1 Schedule Clause
4+
! Test that does not catch non constant integer expressions like xx - xx.
5+
!DEF: /ompdoschedule MainProgram
6+
program ompdoschedule
7+
!DEF: /ompdoschedule/a ObjectEntity REAL(4)
8+
!DEF: /ompdoschedule/y ObjectEntity REAL(4)
9+
!DEF: /ompdoschedule/z ObjectEntity REAL(4)
10+
real a(100),y(100),z(100)
11+
!DEF: /ompdoschedule/b ObjectEntity INTEGER(4)
12+
!DEF: /ompdoschedule/i ObjectEntity INTEGER(4)
13+
!DEF: /ompdoschedule/n ObjectEntity INTEGER(4)
14+
integer b,i,n
15+
!REF: /ompdoschedule/b
16+
b = 10
17+
!$omp do schedule(static,b-b)
18+
!DEF: /ompdoschedule/Block1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
19+
!REF: /ompdoschedule/n
20+
do i = 2,n+1
21+
!REF: /ompdoschedule/y
22+
!REF: /ompdoschedule/Block1/i
23+
!REF: /ompdoschedule/z
24+
!REF: /ompdoschedule/a
25+
y(i) = z(i-1) + a(i)
26+
end do
27+
!$omp end do
28+
end program ompdoschedule
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
! RUN: %S/test_symbols.sh %s %t %f18 -fopenmp
2+
! OpenMP Version 4.5
3+
! 2.7.1 Schedule Clause
4+
! Test that does not catch non constant integer expressions like xx - yy.
5+
6+
!DEF: /tds (Subroutine) Subprogram
7+
subroutine tds
8+
implicit none
9+
!DEF: /tds/a ObjectEntity REAL(4)
10+
!DEF: /tds/y ObjectEntity REAL(4)
11+
!DEF: /tds/z ObjectEntity REAL(4)
12+
real a(100),y(100),z(100)
13+
!DEF: /tds/i ObjectEntity INTEGER(4)
14+
!DEF: /tds/j ObjectEntity INTEGER(4)
15+
!DEF: /tds/k ObjectEntity INTEGER(4)
16+
integer i,j,k
17+
18+
!REF: /tds/j
19+
j = 11
20+
!REF: /tds/k
21+
k = 12
22+
!$omp do schedule(static,j-k)
23+
!DEF: /tds/Block1/i (OmpPrivate,OmpPreDetermined) HostAssoc INTEGER(4)
24+
do i = 1,10
25+
!REF: /tds/y
26+
!REF: /tds/Block1/i
27+
!REF: /tds/z
28+
!REF: /tds/a
29+
y(i) = z(i-1)+a(i)
30+
end do
31+
!$omp end do
32+
end subroutine tds

0 commit comments

Comments
 (0)