Skip to content

Commit a010ef8

Browse files
chichunchenalexey-bataev
authored andcommitted
Add map-type check for target and target data directive, by Chi Chun
Chen Reviewers: ABataev, jdoerfert Reviewed By: ABataev Subscribers: cfe-commits, dreachem, sandoval Tags: #clang Differential Revision: https://reviews.llvm.org/D77581
1 parent 3d1424b commit a010ef8

12 files changed

+77
-4
lines changed

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16998,6 +16998,21 @@ static void checkMappableExpressionList(
1699816998
continue;
1699916999
}
1700017000

17001+
// target, target data
17002+
// OpenMP 5.0 [2.12.2, Restrictions, p. 163]
17003+
// OpenMP 5.0 [2.12.5, Restrictions, p. 174]
17004+
// A map-type in a map clause must be to, from, tofrom or alloc
17005+
if ((DKind == OMPD_target_data ||
17006+
isOpenMPTargetExecutionDirective(DKind)) &&
17007+
!(MapType == OMPC_MAP_to || MapType == OMPC_MAP_from ||
17008+
MapType == OMPC_MAP_tofrom || MapType == OMPC_MAP_alloc)) {
17009+
SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive)
17010+
<< (IsMapTypeImplicit ? 1 : 0)
17011+
<< getOpenMPSimpleClauseTypeName(OMPC_map, MapType)
17012+
<< getOpenMPDirectiveName(DKind);
17013+
continue;
17014+
}
17015+
1700117016
// OpenMP 4.5 [2.15.5.1, Restrictions, p.3]
1700217017
// A list item cannot appear in both a map clause and a data-sharing
1700317018
// attribute clause on the same construct

clang/test/Analysis/cfg-openmp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,10 @@ void ttd(int argc) {
462462
// CHECK-DAG: [[#TTD+4]]: rd
463463
// CHECK-DAG: [[#TTD+5]]: [B3.[[#TTDB+2]]]
464464
// CHECK-DAG: [[#TTD+6]]: [B3.[[#TTDB]]]
465-
// CHECK-DAG: [[#TTD+7]]: #pragma omp target teams distribute if(cond) firstprivate(fp) reduction(+: rd) map(release: map)
465+
// CHECK-DAG: [[#TTD+7]]: #pragma omp target teams distribute if(cond) firstprivate(fp) reduction(+: rd) map(alloc: map)
466466
// CHECK-DAG: for (int i = 0;
467467
// CHECK-DAG: [B3.[[#TTDB+3]]];
468-
#pragma omp target teams distribute if(cond) firstprivate(fp) reduction(+:rd) map(release:map)
468+
#pragma omp target teams distribute if(cond) firstprivate(fp) reduction(+:rd) map(alloc:map)
469469
for (int i = 0; i < 10; ++i)
470470
argc = x;
471471
}
@@ -486,10 +486,10 @@ void ttdpf(int argc) {
486486
// CHECK-DAG: [[#TTDPF+4]]: rd
487487
// CHECK-DAG: [[#TTDPF+5]]: [B3.[[#TTDPFB+2]]]
488488
// CHECK-DAG: [[#TTDPF+6]]: [B3.[[#TTDPFB]]]
489-
// CHECK-DAG: [[#TTDPF+7]]: #pragma omp target teams distribute parallel for if(cond) firstprivate(fp) reduction(+: rd) map(delete: map)
489+
// CHECK-DAG: [[#TTDPF+7]]: #pragma omp target teams distribute parallel for if(cond) firstprivate(fp) reduction(+: rd) map(alloc: map)
490490
// CHECK-DAG: for (int i = 0;
491491
// CHECK-DAG: [B3.[[#TTDPFB+3]]];
492-
#pragma omp target teams distribute parallel for if(cond) firstprivate(fp) reduction(+:rd) map(delete:map)
492+
#pragma omp target teams distribute parallel for if(cond) firstprivate(fp) reduction(+:rd) map(alloc:map)
493493
for (int i = 0; i < 10; ++i)
494494
argc = x;
495495
}

clang/test/OpenMP/target_data_messages.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,13 @@ int main(int argc, char **argv) {
3535
{
3636
foo();
3737
}
38+
#pragma omp target data map(delete: a) // expected-error {{map type 'delete' is not allowed for '#pragma omp target data'}}
39+
{
40+
foo();
41+
}
42+
#pragma omp target data map(release: a) // expected-error {{map type 'release' is not allowed for '#pragma omp target data'}}
43+
{
44+
foo();
45+
}
3846
return 0;
3947
}

clang/test/OpenMP/target_map_messages.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,11 @@ int main(int argc, char **argv) {
732732
#pragma omp target map(*(1+*a+*a)) // expected-error {{indirection requires pointer operand ('int' invalid)}}
733733
{}
734734

735+
#pragma omp target map(delete: a) // expected-error {{map type 'delete' is not allowed for '#pragma omp target'}}
736+
{}
737+
#pragma omp target map(release: a) // expected-error {{map type 'release' is not allowed for '#pragma omp target'}}
738+
{}
739+
735740
return tmain<int, 3>(argc)+tmain<from, 4>(argc); // expected-note {{in instantiation of function template specialization 'tmain<int, 3>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<int, 4>' requested here}}
736741
}
737742
#endif

clang/test/OpenMP/target_parallel_for_map_messages.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ int main(int argc, char **argv) {
288288
for (i = 0; i < argc; ++i) foo();
289289
#pragma omp target parallel for map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
290290
for (i = 0; i < argc; ++i) foo();
291+
#pragma omp target parallel for map(delete: j) // expected-error {{map type 'delete' is not allowed for '#pragma omp target parallel for'}}
292+
for (i = 0; i < argc; ++i)
293+
foo();
294+
#pragma omp target parallel for map(release: j) // expected-error {{map type 'release' is not allowed for '#pragma omp target parallel for'}}
295+
for (i = 0; i < argc; ++i)
296+
foo();
291297

292298
return tmain<int, 3>(argc)+tmain<from, 4>(argc); // expected-note {{in instantiation of function template specialization 'tmain<int, 3>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<int, 4>' requested here}}
293299
}

clang/test/OpenMP/target_parallel_for_simd_map_messages.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ int main(int argc, char **argv) {
288288
for (i = 0; i < argc; ++i) foo();
289289
#pragma omp target parallel for simd map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
290290
for (i = 0; i < argc; ++i) foo();
291+
#pragma omp target parallel for simd map(delete: j) // expected-error {{map type 'delete' is not allowed for '#pragma omp target parallel for simd'}}
292+
for (i = 0; i < argc; ++i)
293+
foo();
294+
#pragma omp target parallel for simd map(release: j) // expected-error {{map type 'release' is not allowed for '#pragma omp target parallel for simd'}}
295+
for (i = 0; i < argc; ++i)
296+
foo();
291297

292298
return tmain<int, 3>(argc)+tmain<from, 4>(argc); // expected-note {{in instantiation of function template specialization 'tmain<int, 3>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<int, 4>' requested here}}
293299
}

clang/test/OpenMP/target_parallel_map_messages.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ int main(int argc, char **argv) {
287287
foo();
288288
#pragma omp target parallel map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
289289
foo();
290+
#pragma omp target parallel map(delete: j) // expected-error {{map type 'delete' is not allowed for '#pragma omp target parallel'}}
291+
foo();
292+
#pragma omp target parallel map(release: j) // expected-error {{map type 'release' is not allowed for '#pragma omp target parallel'}}
293+
foo();
290294

291295
return tmain<int, 3>(argc)+tmain<from, 4>(argc); // expected-note {{in instantiation of function template specialization 'tmain<int, 3>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<int, 4>' requested here}}
292296
}

clang/test/OpenMP/target_simd_map_messages.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,12 @@ int main(int argc, char **argv) {
276276
for (i = 0; i < argc; ++i) foo();
277277
#pragma omp target simd map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
278278
for (i = 0; i < argc; ++i) foo();
279+
#pragma omp target simd map(delete: j) // expected-error {{map type 'delete' is not allowed for '#pragma omp target simd'}}
280+
for (i = 0; i < argc; ++i)
281+
foo();
282+
#pragma omp target simd map(release: j) // expected-error {{map type 'release' is not allowed for '#pragma omp target simd'}}
283+
for (i = 0; i < argc; ++i)
284+
foo();
279285

280286
return tmain<int, 3>(argc)+tmain<from, 4>(argc); // expected-note {{in instantiation of function template specialization 'tmain<int, 3>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<int, 4>' requested here}}
281287
}

clang/test/OpenMP/target_teams_distribute_map_messages.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ int main(int argc, char **argv) {
288288
for (i = 0; i < argc; ++i) foo();
289289
#pragma omp target teams distribute map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
290290
for (i = 0; i < argc; ++i) foo();
291+
#pragma omp target teams distribute map(delete: j) // expected-error {{map type 'delete' is not allowed for '#pragma omp target teams distribute'}}
292+
for (i = 0; i < argc; ++i)
293+
foo();
294+
#pragma omp target teams distribute map(release: j) // expected-error {{map type 'release' is not allowed for '#pragma omp target teams distribute'}}
295+
for (i = 0; i < argc; ++i)
296+
foo();
291297

292298
return tmain<int, 3>(argc)+tmain<from, 4>(argc); // expected-note {{in instantiation of function template specialization 'tmain<int, 3>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<int, 4>' requested here}}
293299
}

clang/test/OpenMP/target_teams_distribute_parallel_for_map_messages.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ int main(int argc, char **argv) {
288288
for (i = 0; i < argc; ++i) foo();
289289
#pragma omp target teams distribute parallel for map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
290290
for (i = 0; i < argc; ++i) foo();
291+
#pragma omp target teams distribute parallel for map(delete: j) // expected-error {{map type 'delete' is not allowed for '#pragma omp target teams distribute parallel for'}}
292+
for (i = 0; i < argc; ++i)
293+
foo();
294+
#pragma omp target teams distribute parallel for map(release: j) // expected-error {{map type 'release' is not allowed for '#pragma omp target teams distribute parallel for'}}
295+
for (i = 0; i < argc; ++i)
296+
foo();
291297

292298
return tmain<int, 3>(argc)+tmain<from, 4>(argc); // expected-note {{in instantiation of function template specialization 'tmain<int, 3>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<int, 4>' requested here}}
293299
}

clang/test/OpenMP/target_teams_distribute_parallel_for_simd_map_messages.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ int main(int argc, char **argv) {
288288
for (i = 0; i < argc; ++i) foo();
289289
#pragma omp target teams distribute parallel for simd map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
290290
for (i = 0; i < argc; ++i) foo();
291+
#pragma omp target teams distribute parallel for simd map(delete: j) // expected-error {{map type 'delete' is not allowed for '#pragma omp target teams distribute parallel for simd'}}
292+
for (i = 0; i < argc; ++i)
293+
foo();
294+
#pragma omp target teams distribute parallel for simd map(release: j) // expected-error {{map type 'release' is not allowed for '#pragma omp target teams distribute parallel for simd'}}
295+
for (i = 0; i < argc; ++i)
296+
foo();
291297

292298
return tmain<int, 3>(argc)+tmain<from, 4>(argc); // expected-note {{in instantiation of function template specialization 'tmain<int, 3>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<int, 4>' requested here}}
293299
}

clang/test/OpenMP/target_teams_map_messages.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,11 @@ int main(int argc, char **argv) {
580580
#pragma omp target teams map(*(1+*a+*a)) // expected-error {{indirection requires pointer operand ('int' invalid)}}
581581
{}
582582

583+
#pragma omp target teams map(delete: j) // expected-error {{map type 'delete' is not allowed for '#pragma omp target teams'}}
584+
{}
585+
#pragma omp target teams map(release: j) // expected-error {{map type 'release' is not allowed for '#pragma omp target teams'}}
586+
{}
587+
583588
return tmain<int, 3>(argc)+tmain<from, 4>(argc); // expected-note {{in instantiation of function template specialization 'tmain<int, 3>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<int, 4>' requested here}}
584589
}
585590
#endif

0 commit comments

Comments
 (0)