Skip to content

Commit 630d35f

Browse files
committed
[OpenMP][Sema] Emit a Sema error when -fopenmp-target-xteam-scan is missing
Emit an error when the 'scan' directive is nested inside the 'target teams distribute parallel for' directive while the flag '-fopenmp-target-xteam-scan' has not been turned on to enable the Xteam Scan Codegen. Added a test for the same. Change-Id: Ib8a8eab177c7dbb2b5fa3f964465e5b5d74db662
1 parent 04b5e07 commit 630d35f

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11657,6 +11657,8 @@ def note_omp_previous_inscan_reduction : Note<
1165711657
"'reduction' clause with 'inscan' modifier is used here">;
1165811658
def err_omp_multivar_xteam_scan_unsupported : Error<
1165911659
"multiple list items are not yet supported with the 'inclusive' or the 'exclusive' clauses that appear with the 'scan' directive">;
11660+
def err_omp_xteam_scan_prohibited : Error<
11661+
"'scan' directive is not supported inside target regions. Use flag '-fopenmp-target-xteam-scan' to enable it">;
1166011662
def err_omp_expected_predefined_allocator : Error<
1166111663
"expected one of the predefined allocators for the variables with the static "
1166211664
"storage: 'omp_default_mem_alloc', 'omp_large_cap_mem_alloc', "

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5400,6 +5400,13 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack,
54005400
Recommend = ShouldBeInTargetRegion;
54015401
} else if (CurrentRegion == OMPD_scan) {
54025402
if (SemaRef.LangOpts.OpenMP >= 50) {
5403+
// Make sure that the '-fopenmp-target-xteam-scan' flag is passed to
5404+
// enable the Xteam-Scan Codegen, if the 'scan' directive is found to be
5405+
// nested inside the 'target teams distribute parallel for' directive
5406+
if (ParentRegion == OMPD_target_teams_distribute_parallel_for &&
5407+
!SemaRef.getLangOpts().OpenMPTargetXteamScan)
5408+
SemaRef.Diag(StartLoc, diag::err_omp_xteam_scan_prohibited)
5409+
<< getOpenMPDirectiveName(CurrentRegion) << Recommend;
54035410
// OpenMP spec 5.0 and 5.1 require scan to be directly enclosed by for,
54045411
// simd, or for simd. This has to take into account combined directives.
54055412
// In 5.2 this seems to be implied by the fact that the specified

clang/test/OpenMP/Inputs/nesting_of_regions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9271,7 +9271,7 @@ void foo() {
92719271
}
92729272
#pragma omp target teams distribute parallel for
92739273
for (int i = 0; i < 10; ++i) {
9274-
#pragma omp scan // omp45-error {{region cannot be closely nested inside 'target teams distribute parallel for' region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}} omp51-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
9274+
#pragma omp scan // omp45-error {{region cannot be closely nested inside 'target teams distribute parallel for' region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}} omp51-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}} omp50-error {{'scan' directive is not supported inside target regions. Use flag '-fopenmp-target-xteam-scan' to enable it}} omp51-error {{'scan' directive is not supported inside target regions. Use flag '-fopenmp-target-xteam-scan' to enable it}}
92759275
bar();
92769276
}
92779277
#pragma omp target teams distribute parallel for
@@ -18547,7 +18547,7 @@ void foo() {
1854718547
}
1854818548
#pragma omp target teams distribute parallel for
1854918549
for (int i = 0; i < 10; ++i) {
18550-
#pragma omp scan // omp45-error {{region cannot be closely nested inside 'target teams distribute parallel for' region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}} omp51-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}}
18550+
#pragma omp scan // omp45-error {{region cannot be closely nested inside 'target teams distribute parallel for' region}} omp50-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}} omp51-error {{exactly one of 'inclusive' or 'exclusive' clauses is expected}} omp50-error {{'scan' directive is not supported inside target regions. Use flag '-fopenmp-target-xteam-scan' to enable it}} omp51-error {{'scan' directive is not supported inside target regions. Use flag '-fopenmp-target-xteam-scan' to enable it}}
1855118551
bar();
1855218552
}
1855318553
#pragma omp target teams distribute parallel for

clang/test/OpenMP/xteam_scan_messages.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
1+
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-target-xteam-scan %s -Wuninitialized
22

3-
// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
3+
// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-target-xteam-scan %s -Wuninitialized
4+
5+
// RUN: %clang_cc1 -verify=missing-flag,expected -fopenmp %s -Wuninitialized
6+
7+
// RUN: %clang_cc1 -verify=missing-flag,expected -fopenmp-simd %s -Wuninitialized
48

59
#define NUM_TEAMS 256
610
#define NUM_THREADS 256
@@ -16,7 +20,9 @@ int main() {
1620
for(int i = 0; i < N; i++) {
1721
sum1 += in[i];
1822
sum2 += 2*in[i];
19-
#pragma omp scan inclusive(sum1,sum2) // expected-error {{multiple list items are not yet supported with the 'inclusive' or the 'exclusive' clauses that appear with the 'scan' directive}}
23+
// missing-flag-error@+2 {{'scan' directive is not supported inside target regions. Use flag '-fopenmp-target-xteam-scan' to enable it}}
24+
// expected-error@+1 {{multiple list items are not yet supported with the 'inclusive' or the 'exclusive' clauses that appear with the 'scan' directive}}
25+
#pragma omp scan inclusive(sum1,sum2)
2026
out1[i] = sum1;
2127
out2[i] = sum2;
2228
}
@@ -25,10 +31,13 @@ int main() {
2531
for(int i = 0; i < N; i++) {
2632
out1[i] = sum1;
2733
out2[i] = sum2;
28-
#pragma omp scan exclusive(sum1,sum2) // expected-error {{multiple list items are not yet supported with the 'inclusive' or the 'exclusive' clauses that appear with the 'scan' directive}}
34+
// missing-flag-error@+2 {{'scan' directive is not supported inside target regions. Use flag '-fopenmp-target-xteam-scan' to enable it}}
35+
// expected-error@+1 {{multiple list items are not yet supported with the 'inclusive' or the 'exclusive' clauses that appear with the 'scan' directive}}
36+
#pragma omp scan exclusive(sum1,sum2)
2937
sum1 += in[i];
3038
sum2 += 2*in[i];
3139
}
3240

41+
3342
return 0;
3443
}

0 commit comments

Comments
 (0)