Skip to content

Commit 071dca2

Browse files
committed
[OpenMP] Require trivially copyable type for mapping
A trivially copyable type provides a trivial copy constructor and a trivial copy assignment operator. This is enough for the runtime to memcpy the data to the device. Additionally there must be no virtual functions or virtual base classes and the destructor is guaranteed to be trivial, ie performs no action. The runtime does not require trivial default constructors because on alloc the memory is undefined. Thus, weaken the warning to be only issued if the mapped type is not trivially copyable. Differential Revision: https://reviews.llvm.org/D71134
1 parent 9db13b5 commit 071dca2

31 files changed

+161
-161
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9600,7 +9600,7 @@ def err_omp_reduction_vla_unsupported : Error<
96009600
def err_omp_linear_distribute_var_non_loop_iteration : Error<
96019601
"only loop iteration variables are allowed in 'linear' clause in distribute directives">;
96029602
def warn_omp_non_trivial_type_mapped : Warning<
9603-
"Non-trivial type %0 is mapped, only trivial types are guaranteed to be mapped correctly">,
9603+
"Type %0 is not trivially copyable and not guaranteed to be mapped correctly">,
96049604
InGroup<OpenMPMapping>;
96059605
def err_omp_requires_clause_redeclaration : Error <
96069606
"Only one %0 clause can appear on a requires directive in a single translation unit">;

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14916,7 +14916,7 @@ static bool checkTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef,
1491614916
return false;
1491714917
}
1491814918
if (FullCheck && !SemaRef.CurContext->isDependentContext() &&
14919-
!QTy.isTrivialType(SemaRef.Context))
14919+
!QTy.isTriviallyCopyableType(SemaRef.Context))
1492014920
SemaRef.Diag(SL, diag::warn_omp_non_trivial_type_mapped) << QTy << SR;
1492114921
return true;
1492214922
}

clang/test/OpenMP/distribute_firstprivate_messages.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,19 @@ int main(int argc, char **argv) {
9595
for (i = 0; i < argc; ++i) foo();
9696
#pragma omp target
9797
#pragma omp teams
98-
#pragma omp distribute firstprivate (a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} expected-warning {{Non-trivial type 'const S2' is mapped, only trivial types are guaranteed to be mapped correctly}} expected-warning {{Non-trivial type 'const S3' is mapped, only trivial types are guaranteed to be mapped correctly}} expected-error {{incomplete type 'S1' where a complete type is required}}
98+
#pragma omp distribute firstprivate (a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} expected-warning {{Type 'const S2' is not trivially copyable and not guaranteed to be mapped correctly}} expected-warning {{Type 'const S3' is not trivially copyable and not guaranteed to be mapped correctly}} expected-error {{incomplete type 'S1' where a complete type is required}}
9999
for (i = 0; i < argc; ++i) foo();
100100
#pragma omp target
101101
#pragma omp teams
102102
#pragma omp distribute firstprivate (argv[1]) // expected-error {{expected variable name}}
103103
for (i = 0; i < argc; ++i) foo();
104104
#pragma omp target
105105
#pragma omp teams
106-
#pragma omp distribute firstprivate(ba) // expected-warning {{Non-trivial type 'const S2 [5]' is mapped, only trivial types are guaranteed to be mapped correctly}}
106+
#pragma omp distribute firstprivate(ba) // expected-warning {{Type 'const S2 [5]' is not trivially copyable and not guaranteed to be mapped correctly}}
107107
for (i = 0; i < argc; ++i) foo();
108108
#pragma omp target
109109
#pragma omp teams
110-
#pragma omp distribute firstprivate(ca) // expected-error {{no matching constructor for initialization of 'S3'}} expected-warning {{Non-trivial type 'const S3 [5]' is mapped, only trivial types are guaranteed to be mapped correctly}}
110+
#pragma omp distribute firstprivate(ca) // expected-error {{no matching constructor for initialization of 'S3'}} expected-warning {{Type 'const S3 [5]' is not trivially copyable and not guaranteed to be mapped correctly}}
111111
for (i = 0; i < argc; ++i) foo();
112112
#pragma omp target
113113
#pragma omp teams

clang/test/OpenMP/distribute_parallel_for_firstprivate_messages.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ int foomain(int argc, char **argv) {
119119
++k;
120120
#pragma omp target
121121
#pragma omp teams
122-
#pragma omp distribute parallel for firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}} expected-warning {{Non-trivial type 'const S2' is mapped, only trivial types are guaranteed to be mapped correctly}}
122+
#pragma omp distribute parallel for firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}} expected-warning {{Type 'const S2' is not trivially copyable and not guaranteed to be mapped correctly}}
123123
for (int k = 0; k < argc; ++k)
124124
++k;
125125
#pragma omp target
@@ -129,7 +129,7 @@ int foomain(int argc, char **argv) {
129129
++k;
130130
#pragma omp target
131131
#pragma omp teams
132-
#pragma omp distribute parallel for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} expected-warning {{Non-trivial type 'S4' is mapped, only trivial types are guaranteed to be mapped correctly}} expected-warning {{Non-trivial type 'S5' is mapped, only trivial types are guaranteed to be mapped correctly}}
132+
#pragma omp distribute parallel for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} expected-warning {{Type 'S4' is not trivially copyable and not guaranteed to be mapped correctly}} expected-warning {{Type 'S5' is not trivially copyable and not guaranteed to be mapped correctly}}
133133
for (int k = 0; k < argc; ++k)
134134
++k;
135135
#pragma omp target
@@ -241,7 +241,7 @@ int main(int argc, char **argv) {
241241
foo();
242242
#pragma omp target
243243
#pragma omp teams
244-
#pragma omp distribute parallel for firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} expected-error {{incomplete type 'S1' where a complete type is required}} expected-warning {{Non-trivial type 'const S2' is mapped, only trivial types are guaranteed to be mapped correctly}} expected-warning {{Non-trivial type 'const S3' is mapped, only trivial types are guaranteed to be mapped correctly}}
244+
#pragma omp distribute parallel for firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} expected-error {{incomplete type 'S1' where a complete type is required}} expected-warning {{Type 'const S2' is not trivially copyable and not guaranteed to be mapped correctly}} expected-warning {{Type 'const S3' is not trivially copyable and not guaranteed to be mapped correctly}}
245245
for (i = 0; i < argc; ++i)
246246
foo();
247247
#pragma omp target
@@ -256,12 +256,12 @@ int main(int argc, char **argv) {
256256
foo();
257257
#pragma omp target
258258
#pragma omp teams
259-
#pragma omp distribute parallel for firstprivate(ba) // expected-warning {{Non-trivial type 'const S2 [5]' is mapped, only trivial types are guaranteed to be mapped correctly}}
259+
#pragma omp distribute parallel for firstprivate(ba) // expected-warning {{Type 'const S2 [5]' is not trivially copyable and not guaranteed to be mapped correctly}}
260260
for (i = 0; i < argc; ++i)
261261
foo();
262262
#pragma omp target
263263
#pragma omp teams
264-
#pragma omp distribute parallel for firstprivate(ca) // expected-warning {{Non-trivial type 'const S3 [5]' is mapped, only trivial types are guaranteed to be mapped correctly}}
264+
#pragma omp distribute parallel for firstprivate(ca) // expected-warning {{Type 'const S3 [5]' is not trivially copyable and not guaranteed to be mapped correctly}}
265265
for (i = 0; i < argc; ++i)
266266
foo();
267267
#pragma omp target
@@ -292,12 +292,12 @@ int main(int argc, char **argv) {
292292
foo();
293293
#pragma omp target
294294
#pragma omp teams
295-
#pragma omp distribute parallel for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} expected-warning {{Non-trivial type 'S4' is mapped, only trivial types are guaranteed to be mapped correctly}} expected-warning {{Non-trivial type 'S5' is mapped, only trivial types are guaranteed to be mapped correctly}}
295+
#pragma omp distribute parallel for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} expected-warning {{Type 'S4' is not trivially copyable and not guaranteed to be mapped correctly}} expected-warning {{Type 'S5' is not trivially copyable and not guaranteed to be mapped correctly}}
296296
for (i = 0; i < argc; ++i)
297297
foo();
298298
#pragma omp target
299299
#pragma omp teams
300-
#pragma omp distribute parallel for firstprivate(m) // expected-warning {{Non-trivial type 'S3' is mapped, only trivial types are guaranteed to be mapped correctly}}
300+
#pragma omp distribute parallel for firstprivate(m) // expected-warning {{Type 'S3' is not trivially copyable and not guaranteed to be mapped correctly}}
301301
for (i = 0; i < argc; ++i)
302302
foo();
303303
#pragma omp target
@@ -329,13 +329,13 @@ int main(int argc, char **argv) {
329329
// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
330330
#pragma omp target
331331
#pragma omp teams
332-
#pragma omp distribute parallel for lastprivate(g) firstprivate(g) // expected-warning {{Non-trivial type 'S5' is mapped, only trivial types are guaranteed to be mapped correctly}}
332+
#pragma omp distribute parallel for lastprivate(g) firstprivate(g) // expected-warning {{Type 'S5' is not trivially copyable and not guaranteed to be mapped correctly}}
333333
for (i = 0; i < argc; ++i)
334334
foo();
335335
// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
336336
#pragma omp target
337337
#pragma omp teams
338-
#pragma omp distribute parallel for lastprivate(n) firstprivate(n) // expected-error {{calling a private constructor of class 'S6'}} expected-warning {{Non-trivial type 'S6' is mapped, only trivial types are guaranteed to be mapped correctly}}
338+
#pragma omp distribute parallel for lastprivate(n) firstprivate(n) // expected-error {{calling a private constructor of class 'S6'}} expected-warning {{Type 'S6' is not trivially copyable and not guaranteed to be mapped correctly}}
339339
for (i = 0; i < argc; ++i)
340340
foo();
341341
#pragma omp parallel

clang/test/OpenMP/distribute_parallel_for_lastprivate_messages.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int foomain(int argc, char **argv) {
112112
++k;
113113
#pragma omp target
114114
#pragma omp teams
115-
#pragma omp distribute parallel for lastprivate(a, b) // expected-error {{lastprivate variable with incomplete type 'S1'}} expected-warning {{Non-trivial type 'const S2' is mapped, only trivial types are guaranteed to be mapped correctly}}
115+
#pragma omp distribute parallel for lastprivate(a, b) // expected-error {{lastprivate variable with incomplete type 'S1'}} expected-warning {{Type 'const S2' is not trivially copyable and not guaranteed to be mapped correctly}}
116116
for (int k = 0; k < argc; ++k)
117117
++k;
118118
#pragma omp target
@@ -122,7 +122,7 @@ int foomain(int argc, char **argv) {
122122
++k;
123123
#pragma omp target
124124
#pragma omp teams
125-
#pragma omp distribute parallel for lastprivate(e, g) // expected-error 2 {{calling a private constructor of class 'S4'}} expected-warning 2 {{Non-trivial type 'S4' is mapped, only trivial types are guaranteed to be mapped correctly}}
125+
#pragma omp distribute parallel for lastprivate(e, g) // expected-error 2 {{calling a private constructor of class 'S4'}} expected-warning 2 {{Type 'S4' is not trivially copyable and not guaranteed to be mapped correctly}}
126126
for (int k = 0; k < argc; ++k)
127127
++k;
128128
#pragma omp target
@@ -221,7 +221,7 @@ int main(int argc, char **argv) {
221221
foo();
222222
#pragma omp target
223223
#pragma omp teams
224-
#pragma omp distribute parallel for lastprivate(a, b, c, d, f) // expected-error {{lastprivate variable with incomplete type 'S1'}} expected-error 1 {{const-qualified variable without mutable fields cannot be lastprivate}} expected-error 2 {{const-qualified variable cannot be lastprivate}} expected-error {{incomplete type 'S1' where a complete type is required}} expected-warning {{Non-trivial type 'const S2' is mapped, only trivial types are guaranteed to be mapped correctly}} expected-warning {{Non-trivial type 'const S3' is mapped, only trivial types are guaranteed to be mapped correctly}}
224+
#pragma omp distribute parallel for lastprivate(a, b, c, d, f) // expected-error {{lastprivate variable with incomplete type 'S1'}} expected-error 1 {{const-qualified variable without mutable fields cannot be lastprivate}} expected-error 2 {{const-qualified variable cannot be lastprivate}} expected-error {{incomplete type 'S1' where a complete type is required}} expected-warning {{Type 'const S2' is not trivially copyable and not guaranteed to be mapped correctly}} expected-warning {{Type 'const S3' is not trivially copyable and not guaranteed to be mapped correctly}}
225225
for (i = 0; i < argc; ++i)
226226
foo();
227227
#pragma omp target
@@ -236,12 +236,12 @@ int main(int argc, char **argv) {
236236
foo();
237237
#pragma omp target
238238
#pragma omp teams
239-
#pragma omp distribute parallel for lastprivate(ba) // expected-warning {{Non-trivial type 'const S2 [5]' is mapped, only trivial types are guaranteed to be mapped correctly}}
239+
#pragma omp distribute parallel for lastprivate(ba) // expected-warning {{Type 'const S2 [5]' is not trivially copyable and not guaranteed to be mapped correctly}}
240240
for (i = 0; i < argc; ++i)
241241
foo();
242242
#pragma omp target
243243
#pragma omp teams
244-
#pragma omp distribute parallel for lastprivate(ca) // expected-error {{const-qualified variable without mutable fields cannot be lastprivate}} expected-warning {{Non-trivial type 'const S3 [5]' is mapped, only trivial types are guaranteed to be mapped correctly}}
244+
#pragma omp distribute parallel for lastprivate(ca) // expected-error {{const-qualified variable without mutable fields cannot be lastprivate}} expected-warning {{Type 'const S3 [5]' is not trivially copyable and not guaranteed to be mapped correctly}}
245245
for (i = 0; i < argc; ++i)
246246
foo();
247247
#pragma omp target
@@ -272,12 +272,12 @@ int main(int argc, char **argv) {
272272
foo();
273273
#pragma omp target
274274
#pragma omp teams
275-
#pragma omp distribute parallel for lastprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} expected-warning {{Non-trivial type 'S4' is mapped, only trivial types are guaranteed to be mapped correctly}} expected-warning {{Non-trivial type 'S5' is mapped, only trivial types are guaranteed to be mapped correctly}}
275+
#pragma omp distribute parallel for lastprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} expected-warning {{Type 'S4' is not trivially copyable and not guaranteed to be mapped correctly}} expected-warning {{Type 'S5' is not trivially copyable and not guaranteed to be mapped correctly}}
276276
for (i = 0; i < argc; ++i)
277277
foo();
278278
#pragma omp target
279279
#pragma omp teams
280-
#pragma omp distribute parallel for lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}} expected-warning {{Non-trivial type 'S3' is mapped, only trivial types are guaranteed to be mapped correctly}}
280+
#pragma omp distribute parallel for lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}} expected-warning {{Type 'S3' is not trivially copyable and not guaranteed to be mapped correctly}}
281281
for (i = 0; i < argc; ++i)
282282
foo();
283283
#pragma omp target
@@ -318,13 +318,13 @@ int main(int argc, char **argv) {
318318
// expected-error@+3 {{firstprivate variable cannot be lastprivate}} expected-note@+3 {{defined as firstprivate}}
319319
#pragma omp target
320320
#pragma omp teams
321-
#pragma omp distribute parallel for firstprivate(m) lastprivate(m) // expected-warning {{Non-trivial type 'S3' is mapped, only trivial types are guaranteed to be mapped correctly}}
321+
#pragma omp distribute parallel for firstprivate(m) lastprivate(m) // expected-warning {{Type 'S3' is not trivially copyable and not guaranteed to be mapped correctly}}
322322
for (i = 0; i < argc; ++i)
323323
foo();
324324
// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
325325
#pragma omp target
326326
#pragma omp teams
327-
#pragma omp distribute parallel for lastprivate(n) firstprivate(n) // expected-error {{calling a private constructor of class 'S6'}} expected-warning {{Non-trivial type 'S6' is mapped, only trivial types are guaranteed to be mapped correctly}}
327+
#pragma omp distribute parallel for lastprivate(n) firstprivate(n) // expected-error {{calling a private constructor of class 'S6'}} expected-warning {{Type 'S6' is not trivially copyable and not guaranteed to be mapped correctly}}
328328
for (i = 0; i < argc; ++i)
329329
foo();
330330
static int si;

clang/test/OpenMP/distribute_parallel_for_private_messages.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class S5 {
5050
#pragma omp target
5151
#pragma omp teams
5252
#pragma omp distribute parallel for private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
53-
for (int k = 0; k < s.a; ++k) // expected-warning {{Non-trivial type 'S5' is mapped, only trivial types are guaranteed to be mapped correctly}}
53+
for (int k = 0; k < s.a; ++k) // expected-warning {{Type 'S5' is not trivially copyable and not guaranteed to be mapped correctly}}
5454
++s.a;
5555
return *this;
5656
}

0 commit comments

Comments
 (0)