From: Alexey Bataev Date: Fri, 25 Dec 2015 13:38:08 +0000 (+0000) Subject: [OPENMP] Do not allow to use threadprivate or thread local variables as loop iteratio... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ee1775e00f7b7e6b6dc3e110dd6368f276031bfb;p=clang [OPENMP] Do not allow to use threadprivate or thread local variables as loop iteration variables. According to OpenMP the loop iteration variable may not appear in a threadprivate directive. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256417 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index dea301602e..c42718d576 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -3494,14 +3494,12 @@ static bool CheckOpenMPIterationSpace( ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) : OMPC_private; if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && - DVar.CKind != OMPC_threadprivate && DVar.CKind != PredeterminedCKind) || + DVar.CKind != PredeterminedCKind) || ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || - isOpenMPDistributeDirective(DKind)) && + isOpenMPDistributeDirective(DKind)) && !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && - DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate && - DVar.CKind != OMPC_threadprivate)) && - ((DVar.CKind != OMPC_private && DVar.CKind != OMPC_threadprivate) || - DVar.RefExpr != nullptr)) { + DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && + (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(PredeterminedCKind); diff --git a/test/OpenMP/for_loop_messages.cpp b/test/OpenMP/for_loop_messages.cpp index 7f0b114101..895baf57e9 100644 --- a/test/OpenMP/for_loop_messages.cpp +++ b/test/OpenMP/for_loop_messages.cpp @@ -10,6 +10,7 @@ public: }; static int sii; +// expected-note@+1 {{defined as threadprivate or thread local}} #pragma omp threadprivate(sii) static int globalii; @@ -309,6 +310,7 @@ int test_iteration_spaces() { #pragma omp parallel { +// expected-error@+2 {{loop iteration variable in the associated loop of 'omp for' directive may not be threadprivate or thread local, predetermined as private}} #pragma omp for for (sii = 0; sii < 10; sii += 1) c[sii] = a[sii]; diff --git a/test/OpenMP/for_simd_loop_messages.cpp b/test/OpenMP/for_simd_loop_messages.cpp index d336888d2b..958c7f60d0 100644 --- a/test/OpenMP/for_simd_loop_messages.cpp +++ b/test/OpenMP/for_simd_loop_messages.cpp @@ -10,6 +10,7 @@ public: }; static int sii; +// expected-note@+1 {{defined as threadprivate or thread local}} #pragma omp threadprivate(sii) static int globalii; @@ -306,6 +307,7 @@ int test_iteration_spaces() { #pragma omp parallel { +// expected-error@+2 {{loop iteration variable in the associated loop of 'omp for simd' directive may not be threadprivate or thread local, predetermined as linear}} #pragma omp for simd for (sii = 0; sii < 10; sii += 1) c[sii] = a[sii]; diff --git a/test/OpenMP/parallel_for_loop_messages.cpp b/test/OpenMP/parallel_for_loop_messages.cpp index 2a65d781a0..2bb32bdfc1 100644 --- a/test/OpenMP/parallel_for_loop_messages.cpp +++ b/test/OpenMP/parallel_for_loop_messages.cpp @@ -10,6 +10,7 @@ public: }; static int sii; +// expected-note@+1 {{defined as threadprivate or thread local}} #pragma omp threadprivate(sii) static int globalii; @@ -257,6 +258,7 @@ int test_iteration_spaces() { c[ii] = a[ii]; { +// expected-error@+2 {{loop iteration variable in the associated loop of 'omp parallel for' directive may not be threadprivate or thread local, predetermined as private}} #pragma omp parallel for for (sii = 0; sii < 10; sii += 1) c[sii] = a[sii]; diff --git a/test/OpenMP/parallel_for_simd_loop_messages.cpp b/test/OpenMP/parallel_for_simd_loop_messages.cpp index 8fe58434bc..f4929d97d4 100644 --- a/test/OpenMP/parallel_for_simd_loop_messages.cpp +++ b/test/OpenMP/parallel_for_simd_loop_messages.cpp @@ -10,6 +10,7 @@ public: }; static int sii; +// expected-note@+1 {{defined as threadprivate or thread local}} #pragma omp threadprivate(sii) static int globalii; @@ -259,6 +260,7 @@ int test_iteration_spaces() { c[ii] = a[ii]; { +// expected-error@+2 {{loop iteration variable in the associated loop of 'omp parallel for simd' directive may not be threadprivate or thread local, predetermined as linear}} #pragma omp parallel for simd for (sii = 0; sii < 10; sii += 1) c[sii] = a[sii]; diff --git a/test/OpenMP/simd_loop_messages.cpp b/test/OpenMP/simd_loop_messages.cpp index 677f2b9a2e..96b4cafc6b 100644 --- a/test/OpenMP/simd_loop_messages.cpp +++ b/test/OpenMP/simd_loop_messages.cpp @@ -1,6 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -fopenmp -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify %s static int sii; +// expected-note@+1 {{defined as threadprivate or thread local}} #pragma omp threadprivate(sii) static int globalii; @@ -252,6 +253,7 @@ int test_iteration_spaces() { #pragma omp parallel { +// expected-error@+2 {{loop iteration variable in the associated loop of 'omp simd' directive may not be threadprivate or thread local, predetermined as linear}} #pragma omp simd for (sii = 0; sii < 10; sii+=1) c[sii] = a[sii]; diff --git a/test/OpenMP/taskloop_loop_messages.cpp b/test/OpenMP/taskloop_loop_messages.cpp index 3ff8005f7f..02518e572f 100644 --- a/test/OpenMP/taskloop_loop_messages.cpp +++ b/test/OpenMP/taskloop_loop_messages.cpp @@ -10,6 +10,7 @@ public: }; static int sii; +// expected-note@+1 {{defined as threadprivate or thread local}} #pragma omp threadprivate(sii) static int globalii; @@ -310,6 +311,7 @@ int test_iteration_spaces() { #pragma omp parallel { +// expected-error@+2 {{loop iteration variable in the associated loop of 'omp taskloop' directive may not be threadprivate or thread local, predetermined as private}} #pragma omp taskloop for (sii = 0; sii < 10; sii += 1) c[sii] = a[sii]; diff --git a/test/OpenMP/taskloop_simd_loop_messages.cpp b/test/OpenMP/taskloop_simd_loop_messages.cpp index 34da10b712..4731872110 100644 --- a/test/OpenMP/taskloop_simd_loop_messages.cpp +++ b/test/OpenMP/taskloop_simd_loop_messages.cpp @@ -10,6 +10,7 @@ public: }; static int sii; +// expected-note@+1 {{defined as threadprivate or thread local}} #pragma omp threadprivate(sii) static int globalii; @@ -311,6 +312,7 @@ int test_iteration_spaces() { #pragma omp parallel { +// expected-error@+2 {{loop iteration variable in the associated loop of 'omp taskloop simd' directive may not be threadprivate or thread local, predetermined as linear}} #pragma omp taskloop simd for (sii = 0; sii < 10; sii += 1) c[sii] = a[sii];