Author: Alexey Bataev Date: 2020-09-16T09:30:32-04:00 New Revision: 4341c6618decb4014a167bc83aeeed49ab49b34f
URL: https://github.com/llvm/llvm-project/commit/4341c6618decb4014a167bc83aeeed49ab49b34f DIFF: https://github.com/llvm/llvm-project/commit/4341c6618decb4014a167bc83aeeed49ab49b34f.diff LOG: [OPENMP]Do not allow threadprivates as base for array-like reduction. The base must be shared between the threads, threadprivates are not allowed to be bases for array-like reductions. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D85762 Added: Modified: clang/lib/Sema/SemaOpenMP.cpp clang/test/OpenMP/parallel_reduction_messages.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 336f26422914..1a0470a9606d 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -15120,6 +15120,17 @@ static bool actOnOMPReductionKindClause( continue; } } + } else { + // Threadprivates cannot be shared between threads, so dignose if the base + // is a threadprivate variable. + DSAStackTy::DSAVarData DVar = Stack->getTopDSA(D, /*FromParent=*/false); + if (DVar.CKind == OMPC_threadprivate) { + S.Diag(ELoc, diag::err_omp_wrong_dsa) + << getOpenMPClauseName(DVar.CKind) + << getOpenMPClauseName(OMPC_reduction); + reportOriginalDsa(S, Stack, D, DVar); + continue; + } } // Try to find 'declare reduction' corresponding construct before using diff --git a/clang/test/OpenMP/parallel_reduction_messages.cpp b/clang/test/OpenMP/parallel_reduction_messages.cpp index b464bf5b9643..12b34a4de07b 100644 --- a/clang/test/OpenMP/parallel_reduction_messages.cpp +++ b/clang/test/OpenMP/parallel_reduction_messages.cpp @@ -92,6 +92,8 @@ class S6 { // expected-note 3 {{candidate function (the implicit copy assignment S3 h, k; #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} +int *gptr; +#pragma omp threadprivate(gptr) // expected-note {{defined as threadprivate or thread local}} template <class T> // expected-note {{declared here}} T tmain(T argc) { @@ -277,6 +279,8 @@ int main(int argc, char **argv) { m++; #pragma omp parallel reduction(task, + : m) // omp45-error 2 {{expected expression}} omp45-warning {{missing ':' after reduction identifier - ignoring}} m++; +#pragma omp parallel reduction(+:gptr[:argc]) // expected-error {{threadprivate or thread local variable cannot be reduction}} + ; return tmain(argc) + tmain(fl); // expected-note {{in instantiation of function template specialization 'tmain<int>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<float>' requested here}} } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits