Skip to content

Commit 87b7aac

Browse files
Fix: Allow nowait only once
1 parent 5168d4e commit 87b7aac

File tree

5 files changed

+13
-24
lines changed

5 files changed

+13
-24
lines changed

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

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,8 +1206,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
12061206
if (GetContext().directive == llvm::omp::Directive::OMPD_single) {
12071207
std::set<Symbol *> singleCopyprivateSyms;
12081208
std::set<Symbol *> endSingleCopyprivateSyms;
1209-
bool singleNowait{false};
1210-
bool endSingleNowait{false};
1209+
bool foundNowait{false};
12111210
parser::CharBlock NowaitSource;
12121211

12131212
auto catchCopyPrivateNowaitClauses = [&](const auto &dir, bool endDir) {
@@ -1240,23 +1239,11 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
12401239
}
12411240
}
12421241
} else if (clause.Id() == llvm::omp::Clause::OMPC_nowait) {
1243-
if (singleNowait) {
1244-
if (endDir) {
1245-
context_.Warn(common::UsageWarning::OpenMPUsage, clause.source,
1246-
"NOWAIT clause is already used on the SINGLE directive"_warn_en_US);
1247-
} else {
1248-
context_.Say(clause.source,
1249-
"At most one NOWAIT clause can appear on the SINGLE directive"_err_en_US);
1250-
}
1251-
} else if (endSingleNowait) {
1242+
if (foundNowait) {
12521243
context_.Say(clause.source,
1253-
"At most one NOWAIT clause can appear on the END SINGLE directive"_err_en_US);
1244+
"At most one NOWAIT clause can appear on the SINGLE directive"_err_en_US);
12541245
} else {
1255-
if (endDir) {
1256-
endSingleNowait = true;
1257-
} else {
1258-
singleNowait = true;
1259-
}
1246+
foundNowait = !endDir;
12601247
}
12611248
if (!NowaitSource.ToString().size()) {
12621249
NowaitSource = clause.source;

flang/test/Semantics/OpenMP/clause-validity01.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@
334334
!$omp single private(a) lastprivate(c) nowait
335335
a = 3.14
336336
!ERROR: COPYPRIVATE variable 'a' may not appear on a PRIVATE or FIRSTPRIVATE clause on a SINGLE construct
337-
!WARNING: NOWAIT clause is already used on the SINGLE directive
338-
!WARNING: NOWAIT clause is already used on the SINGLE directive
337+
!ERROR: At most one NOWAIT clause can appear on the SINGLE directive
338+
!ERROR: At most one NOWAIT clause can appear on the SINGLE directive
339339
!ERROR: At most one NOWAIT clause can appear on the END SINGLE directive
340340
!$omp end single copyprivate(a) nowait nowait
341341
c = 2

flang/test/Semantics/OpenMP/single03.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ subroutine omp_single
4444

4545
!$omp single nowait
4646
print *, "omp single", j
47-
!WARNING: NOWAIT clause is already used on the SINGLE directive
47+
!ERROR: At most one NOWAIT clause can appear on the SINGLE directive
4848
!$omp end single nowait
4949
!$omp end parallel
5050

flang/test/Semantics/OpenMP/single04.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ program single
5353
!$omp single copyprivate(x) nowait
5454
print *, x
5555
!WARNING: The COPYPRIVATE clause with 'x' is already used on the SINGLE directive
56-
!WARNING: NOWAIT clause is already used on the SINGLE directive
56+
!ERROR: At most one NOWAIT clause can appear on the SINGLE directive
5757
!$omp end single copyprivate(x) nowait
5858

5959
!$omp single copyprivate(x)
@@ -67,7 +67,7 @@ program single
6767
print *, x
6868
!WARNING: The COPYPRIVATE clause with 'x' is already used on the SINGLE directive
6969
!ERROR: 'z' appears in more than one COPYPRIVATE clause on the END SINGLE directive
70-
!WARNING: NOWAIT clause is already used on the SINGLE directive
70+
!ERROR: At most one NOWAIT clause can appear on the SINGLE directive
7171
!$omp end single copyprivate(x, z) copyprivate(z) nowait
7272

7373
!ERROR: NOWAIT clause must not be used with COPYPRIVATE clause on the SINGLE directive
@@ -76,6 +76,6 @@ program single
7676
!WARNING: The COPYPRIVATE clause with 'x' is already used on the SINGLE directive
7777
!WARNING: The COPYPRIVATE clause with 'y' is already used on the SINGLE directive
7878
!WARNING: The COPYPRIVATE clause with 'z' is already used on the SINGLE directive
79-
!WARNING: NOWAIT clause is already used on the SINGLE directive
79+
!ERROR: At most one NOWAIT clause can appear on the SINGLE directive
8080
!$omp end single copyprivate(x, y, z) nowait
8181
end program

llvm/include/llvm/Frontend/OpenMP/OMP.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,9 +998,11 @@ def OMP_Single : Directive<"single"> {
998998
VersionedClause<OMPC_Allocate>,
999999
VersionedClause<OMPC_CopyPrivate>,
10001000
VersionedClause<OMPC_FirstPrivate>,
1001-
VersionedClause<OMPC_NoWait>,
10021001
VersionedClause<OMPC_Private>,
10031002
];
1003+
let allowedOnceClauses = [
1004+
VersionedClause<OMPC_NoWait>,
1005+
];
10041006
let association = AS_Block;
10051007
let category = CA_Executable;
10061008
}

0 commit comments

Comments
 (0)