From b7c31ff4a22e05da367503f5f7e845d1a98169a5 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Fri, 28 Jun 2019 15:16:37 +0000 Subject: [PATCH] [OPENMP]Fix DSA for loop iteration variables in simd loops. According to the OpenMP 5.0 standard, the loop iteration variable in the associated for-loop of a simd construct with just one associated for-loop may be listed in a private, lastprivate, or linear clause with a linear-step that is the increment of the associated for-loop. Also, the loop teration variables in the associated for-loops of a simd construct with multiple associated for-loops may be listed in a private or lastprivate clause. llvm-svn: 364650 --- clang/lib/Sema/SemaOpenMP.cpp | 4 +++- clang/test/OpenMP/simd_loop_messages.cpp | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 732b22c..d2e3c39 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -5697,7 +5697,9 @@ static bool checkOpenMPIterationSpace( ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) : OMPC_private; if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && - DVar.CKind != PredeterminedCKind && DVar.RefExpr) || + DVar.CKind != PredeterminedCKind && DVar.RefExpr && + (SemaRef.getLangOpts().OpenMP <= 45 || + (DVar.CKind != OMPC_lastprivate && DVar.CKind != OMPC_private))) || ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || isOpenMPDistributeDirective(DKind)) && !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && diff --git a/clang/test/OpenMP/simd_loop_messages.cpp b/clang/test/OpenMP/simd_loop_messages.cpp index 4c4ce5f..8134020 100644 --- a/clang/test/OpenMP/simd_loop_messages.cpp +++ b/clang/test/OpenMP/simd_loop_messages.cpp @@ -1,5 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -fopenmp -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify %s // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify %s +// RUN: %clang_cc1 -fsyntax-only -fopenmp -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify %s -fopenmp-version=50 -DOMP50 +// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify %s -fopenmp-version=50 -DOMP50 static int sii; // expected-note@+1 {{defined as threadprivate or thread local}} @@ -239,12 +241,22 @@ int test_iteration_spaces() { for (ii = 0; (ii < 10); (ii-=0)) c[ii] = a[ii]; - // expected-note@+2 {{defined as private}} - // expected-error@+2 {{loop iteration variable in the associated loop of 'omp simd' directive may not be private, predetermined as linear}} +#ifndef OMP50 + // expected-note@+3 {{defined as private}} + // expected-error@+3 {{loop iteration variable in the associated loop of 'omp simd' directive may not be private, predetermined as linear}} +#endif // OMP50 #pragma omp simd private(ii) for (ii = 0; ii < 10; ii++) c[ii] = a[ii]; +#ifndef OMP50 + // expected-note@+3 {{defined as lastprivate}} + // expected-error@+3 {{loop iteration variable in the associated loop of 'omp simd' directive may not be lastprivate, predetermined as linear}} +#endif // OMP50 + #pragma omp simd lastprivate(ii) + for (ii = 0; ii < 10; ii++) + c[ii] = a[ii]; + // expected-error@+1 {{unexpected OpenMP clause 'shared' in directive '#pragma omp simd'}} #pragma omp simd shared(ii) for (ii = 0; ii < 10; ii++) -- 2.7.4