Skip to content

Commit e3446b9

Browse files
committed
[OpenACC] Fix bug with worker/vector/gang clause inside another
The original implementation rejected some valid constructs. The rule is supposed to be: Gang-on-Kernel cannot have a gang in its region Worker cannot have a worker or gang in its region Vector cannot have worker, gang, or vector in its region. The previous implementation improperly implemented that vector wasnt' allowed in the other two. This patch fixes it and adds testing for it.
1 parent 7347e5e commit e3446b9

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,34 +1077,6 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitVectorClause(
10771077
}
10781078
}
10791079

1080-
// OpenACC 3.3 2.9.2: When the parent compute construct is a kernels
1081-
// construct, the gang clause behaves as follows. ... The region of a loop
1082-
// with a gang clause may not contain another loop with a gang clause unless
1083-
// within a nested compute region.
1084-
if (SemaRef.LoopGangClauseOnKernelLoc.isValid()) {
1085-
// This handles the 'inner loop' diagnostic, but we cannot set that we're on
1086-
// one of these until we get to the end of the construct.
1087-
SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_in_clause_region)
1088-
<< OpenACCClauseKind::Vector << OpenACCClauseKind::Gang
1089-
<< /*skip kernels construct info*/ 0;
1090-
SemaRef.Diag(SemaRef.LoopGangClauseOnKernelLoc,
1091-
diag::note_acc_previous_clause_here);
1092-
return nullptr;
1093-
}
1094-
1095-
// OpenACC 3.3 2.9.3: The region of a loop with a 'worker' clause may not
1096-
// contain a loop with a gang or worker clause unless within a nested compute
1097-
// region.
1098-
if (SemaRef.LoopWorkerClauseLoc.isValid()) {
1099-
// This handles the 'inner loop' diagnostic, but we cannot set that we're on
1100-
// one of these until we get to the end of the construct.
1101-
SemaRef.Diag(Clause.getBeginLoc(), diag::err_acc_clause_in_clause_region)
1102-
<< OpenACCClauseKind::Vector << OpenACCClauseKind::Worker
1103-
<< /*skip kernels construct info*/ 0;
1104-
SemaRef.Diag(SemaRef.LoopWorkerClauseLoc,
1105-
diag::note_acc_previous_clause_here);
1106-
return nullptr;
1107-
}
11081080
// OpenACC 3.3 2.9.4: The region of a loop with a 'vector' clause may not
11091081
// contain a loop with a gang, worker, or vector clause unless within a nested
11101082
// compute region.

clang/test/SemaOpenACC/loop-construct-gang-clause.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,13 @@ void Kernels() {
284284
for(int i = 0; i < 5; ++i);
285285
}
286286

287+
#pragma acc kernels
288+
#pragma acc loop gang(num:1)
289+
for(int j = 0; j < 5; ++j) {
290+
#pragma acc loop worker(1) vector(1)
291+
for(int i = 0; i < 5; ++i);
292+
}
293+
287294
#pragma acc kernels
288295
#pragma acc loop gang(num:1)
289296
for(int j = 0; j < 5; ++j) {

clang/test/SemaOpenACC/loop-construct-worker-clause.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ void uses() {
138138
for(int k = 0; k < 5; ++k);
139139
}
140140

141+
#pragma acc loop worker
142+
for(int i= 0; i< 5; ++i) {
143+
#pragma acc loop vector
144+
for(int k = 0; k < 5; ++k);
145+
}
146+
141147
#pragma acc loop worker
142148
for(int i= 0; i< 5; ++i) {
143149
#pragma acc parallel

0 commit comments

Comments
 (0)