jyu2 created this revision.
jyu2 added reviewers: ABataev, mikerice, jdoerfert.
jyu2 added projects: clang, OpenMP.
Herald added subscribers: guansong, yaxunl.
jyu2 requested review of this revision.
Herald added a subscriber: sstefan1.

Loop iteration var with threadprivate is predetermined as threadprivate.

Current clang emit error when loop var that appear in threadprivate
directives.

According to OpenMP 5.1 [2.21.1.1]

  For first predetermined rule is:
  Variables that appear in threadprivate directives or variables with the
  _Thread_local (in C) or thread_local (in C++) storage-class specifier
  are threadprivate

The error should not be emitted.

To fix this, set PredeterminedCKind with OMPC_threadprivate when loopvar
with threadprivate.

Setting PredeterminedCKind with DVar.CKind according the rule.  And use
PredeterminedCKind to emit error.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112292

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_loop_messages.cpp
  clang/test/OpenMP/distribute_simd_loop_messages.cpp
  clang/test/OpenMP/for_loop_messages.cpp
  clang/test/OpenMP/for_simd_loop_messages.cpp
  clang/test/OpenMP/master_taskloop_loop_messages.cpp
  clang/test/OpenMP/master_taskloop_simd_loop_messages.cpp
  clang/test/OpenMP/parallel_for_loop_messages.cpp
  clang/test/OpenMP/parallel_for_simd_loop_messages.cpp
  clang/test/OpenMP/parallel_master_taskloop_loop_messages.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_loop_messages.cpp
  clang/test/OpenMP/simd_loop_messages.cpp
  clang/test/OpenMP/target_parallel_for_loop_messages.cpp
  clang/test/OpenMP/target_parallel_for_simd_loop_messages.cpp
  clang/test/OpenMP/target_simd_loop_messages.cpp
  clang/test/OpenMP/target_teams_distribute_loop_messages.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_loop_messages.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_loop_messages.cpp
  clang/test/OpenMP/target_teams_distribute_simd_loop_messages.cpp
  clang/test/OpenMP/taskloop_loop_messages.cpp
  clang/test/OpenMP/taskloop_simd_loop_messages.cpp
  clang/test/OpenMP/teams_distribute_loop_messages.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_loop_messages.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_loop_messages.cpp
  clang/test/OpenMP/teams_distribute_simd_loop_messages.cpp

Index: clang/test/OpenMP/teams_distribute_simd_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/teams_distribute_simd_loop_messages.cpp
+++ clang/test/OpenMP/teams_distribute_simd_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -303,7 +303,7 @@
 
 #pragma omp target
 #pragma omp teams distribute simd
-// expected-error@+1 {{loop iteration variable in the associated loop of 'omp teams distribute simd' directive may not be threadprivate or thread local, predetermined as linear}}
+// no error expected @+1 {{loop iteration variable in the associated loop of 'omp teams distribute simd' directive may not be threadprivate or thread local, predetermined as linear}}
   for (sii = 0; sii < 10; sii++)
     c[sii] = a[sii];
 
Index: clang/test/OpenMP/teams_distribute_parallel_for_simd_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/teams_distribute_parallel_for_simd_loop_messages.cpp
+++ clang/test/OpenMP/teams_distribute_parallel_for_simd_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -303,7 +303,7 @@
 
 #pragma omp target
 #pragma omp teams distribute parallel for simd
-// expected-error@+1 {{loop iteration variable in the associated loop of 'omp teams distribute parallel for simd' directive may not be threadprivate or thread local, predetermined as linear}}
+// no error expected @+1 {{loop iteration variable in the associated loop of 'omp teams distribute parallel for simd' directive may not be threadprivate or thread local, predetermined as linear}}
   for (sii = 0; sii < 10; sii++)
     c[sii] = a[sii];
 
Index: clang/test/OpenMP/teams_distribute_parallel_for_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/teams_distribute_parallel_for_loop_messages.cpp
+++ clang/test/OpenMP/teams_distribute_parallel_for_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -301,7 +301,8 @@
 
 #pragma omp target
 #pragma omp teams distribute parallel for
-// expected-error@+1 {{loop iteration variable in the associated loop of 'omp teams distribute parallel for' directive may not be threadprivate or thread local, predetermined as private}}
+// loop var with threadprivate or thread local is predetermined as threadprivate
+// no error expected @+1 {{loop iteration variable in the associated loop of 'omp teams distribute parallel for' directive may not be threadprivate or thread local, predetermined as private}}
   for (sii = 0; sii < 10; sii++)
     c[sii] = a[sii];
 
Index: clang/test/OpenMP/teams_distribute_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/teams_distribute_loop_messages.cpp
+++ clang/test/OpenMP/teams_distribute_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -303,7 +303,8 @@
 
 #pragma omp target
 #pragma omp teams distribute
-// expected-error@+1 {{loop iteration variable in the associated loop of 'omp teams distribute' directive may not be threadprivate or thread local, predetermined as private}}
+// loop var with threadprivate or thread local is predetermined as threadprivate
+// no error expected @+1 {{loop iteration variable in the associated loop of 'omp teams distribute' directive may not be threadprivate or thread local, predetermined as private}}
   for (sii = 0; sii < 10; sii++)
     c[sii] = a[sii];
 
Index: clang/test/OpenMP/taskloop_simd_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/taskloop_simd_loop_messages.cpp
+++ clang/test/OpenMP/taskloop_simd_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -316,7 +316,7 @@
 
 #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}}
+// no error expected @+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];
Index: clang/test/OpenMP/taskloop_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/taskloop_loop_messages.cpp
+++ clang/test/OpenMP/taskloop_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected@+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -314,7 +314,8 @@
 
 #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}}
+// loop var with threadprivate or thread local is predetermined as threadprivate
+// no error expected @+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];
Index: clang/test/OpenMP/target_teams_distribute_simd_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/target_teams_distribute_simd_loop_messages.cpp
+++ clang/test/OpenMP/target_teams_distribute_simd_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -251,7 +251,7 @@
     c[ii] = a[ii];
 
 #pragma omp target teams distribute simd
-// expected-error@+1 {{loop iteration variable in the associated loop of 'omp target teams distribute simd' directive may not be threadprivate or thread local, predetermined as linear}}
+// no error expected @+1 {{loop iteration variable in the associated loop of 'omp target teams distribute simd' directive may not be threadprivate or thread local, predetermined as linear}}
   for (sii = 0; sii < 10; sii++)
     c[sii] = a[sii];
 
Index: clang/test/OpenMP/target_teams_distribute_parallel_for_simd_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/target_teams_distribute_parallel_for_simd_loop_messages.cpp
+++ clang/test/OpenMP/target_teams_distribute_parallel_for_simd_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -257,7 +257,7 @@
   for (ii = 0; ii < 10; ii++)
     c[ii] = a[ii];
 
-// expected-error@+2 {{loop iteration variable in the associated loop of 'omp target teams distribute parallel for simd' directive may not be threadprivate or thread local, predetermined as linear}}
+// no error expected @+2 {{loop iteration variable in the associated loop of 'omp target teams distribute parallel for simd' directive may not be threadprivate or thread local, predetermined as linear}}
 #pragma omp target teams distribute parallel for simd
   for (sii = 0; sii < 10; sii++)
     c[sii] = a[sii];
Index: clang/test/OpenMP/target_teams_distribute_parallel_for_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/target_teams_distribute_parallel_for_loop_messages.cpp
+++ clang/test/OpenMP/target_teams_distribute_parallel_for_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -255,7 +255,8 @@
     c[ii] = a[ii];
 
 #pragma omp target teams distribute parallel for
-// expected-error@+1 {{loop iteration variable in the associated loop of 'omp target teams distribute parallel for' directive may not be threadprivate or thread local, predetermined as private}}
+// loop var with threadprivate or thread local is predetermined as threadprivate
+// no error expected @+1 {{loop iteration variable in the associated loop of 'omp target teams distribute parallel for' directive may not be threadprivate or thread local, predetermined as private}}
   for (sii = 0; sii < 10; sii++)
     c[sii] = a[sii];
 
Index: clang/test/OpenMP/target_teams_distribute_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/target_teams_distribute_loop_messages.cpp
+++ clang/test/OpenMP/target_teams_distribute_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -257,7 +257,8 @@
     c[ii] = a[ii];
 
 #pragma omp target teams distribute
-// expected-error@+1 {{loop iteration variable in the associated loop of 'omp target teams distribute' directive may not be threadprivate or thread local, predetermined as private}}
+// loop var with threadprivate or thread local is predetermined as threadprivate
+// no error expected @+1 {{loop iteration variable in the associated loop of 'omp target teams distribute' directive may not be threadprivate or thread local, predetermined as private}}
   for (sii = 0; sii < 10; sii++)
     c[sii] = a[sii];
 
Index: clang/test/OpenMP/target_simd_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/target_simd_loop_messages.cpp
+++ clang/test/OpenMP/target_simd_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -264,7 +264,7 @@
     c[ii] = a[ii];
 
   {
-// expected-error@+2 {{loop iteration variable in the associated loop of 'omp target simd' directive may not be threadprivate or thread local, predetermined as linear}}
+// no error expected @+2 {{loop iteration variable in the associated loop of 'omp target simd' directive may not be threadprivate or thread local, predetermined as linear}}
 #pragma omp target simd
     for (sii = 0; sii < 10; sii += 1)
       c[sii] = a[sii];
Index: clang/test/OpenMP/target_parallel_for_simd_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/target_parallel_for_simd_loop_messages.cpp
+++ clang/test/OpenMP/target_parallel_for_simd_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -264,7 +264,7 @@
     c[ii] = a[ii];
 
   {
-// expected-error@+2 {{loop iteration variable in the associated loop of 'omp target parallel for simd' directive may not be threadprivate or thread local, predetermined as linear}}
+// no error expected @+2 {{loop iteration variable in the associated loop of 'omp target parallel for simd' directive may not be threadprivate or thread local, predetermined as linear}}
 #pragma omp target parallel for simd
     for (sii = 0; sii < 10; sii += 1)
       c[sii] = a[sii];
Index: clang/test/OpenMP/target_parallel_for_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/target_parallel_for_loop_messages.cpp
+++ clang/test/OpenMP/target_parallel_for_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -262,7 +262,8 @@
     c[ii] = a[ii];
 
   {
-// expected-error@+2 {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be threadprivate or thread local, predetermined as private}}
+// loop var with threadprivate or thread local is predetermined as threadprivate
+// no error expected @+2 {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be threadprivate or thread local, predetermined as private}}
 #pragma omp target parallel for
     for (sii = 0; sii < 10; sii += 1)
       c[sii] = a[sii];
Index: clang/test/OpenMP/simd_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/simd_loop_messages.cpp
+++ clang/test/OpenMP/simd_loop_messages.cpp
@@ -6,7 +6,7 @@
 // RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4 %s -Wuninitialized -Wno-openmp
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -281,7 +281,7 @@
 
   #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}}
+// no error expected @+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];
Index: clang/test/OpenMP/parallel_master_taskloop_simd_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/parallel_master_taskloop_simd_loop_messages.cpp
+++ clang/test/OpenMP/parallel_master_taskloop_simd_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -309,7 +309,7 @@
 
 #pragma omp parallel
   {
-// expected-error@+2 {{loop iteration variable in the associated loop of 'omp parallel master taskloop simd' directive may not be threadprivate or thread local, predetermined as linear}}
+// no error expected @+2 {{loop iteration variable in the associated loop of 'omp parallel master taskloop simd' directive may not be threadprivate or thread local, predetermined as linear}}
 #pragma omp parallel master taskloop simd
     for (sii = 0; sii < 10; sii += 1)
       c[sii] = a[sii];
Index: clang/test/OpenMP/parallel_master_taskloop_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/parallel_master_taskloop_loop_messages.cpp
+++ clang/test/OpenMP/parallel_master_taskloop_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -314,7 +314,8 @@
 
 #pragma omp parallel
   {
-// expected-error@+2 {{loop iteration variable in the associated loop of 'omp parallel master taskloop' directive may not be threadprivate or thread local, predetermined as private}}
+// loop var with threadprivate or thread local is predetermined as threadprivate
+// no error expected @+2 {{loop iteration variable in the associated loop of 'omp parallel master taskloop' directive may not be threadprivate or thread local, predetermined as private}}
 #pragma omp parallel master taskloop
     for (sii = 0; sii < 10; sii += 1)
       c[sii] = a[sii];
Index: clang/test/OpenMP/parallel_for_simd_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/parallel_for_simd_loop_messages.cpp
+++ clang/test/OpenMP/parallel_for_simd_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -264,7 +264,7 @@
     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}}
+// no error expected @+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];
Index: clang/test/OpenMP/parallel_for_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/parallel_for_loop_messages.cpp
+++ clang/test/OpenMP/parallel_for_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -262,7 +262,8 @@
     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}}
+// loop var with threadprivate or thread local is predetermined as threadprivate
+// no error expected @+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];
Index: clang/test/OpenMP/master_taskloop_simd_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/master_taskloop_simd_loop_messages.cpp
+++ clang/test/OpenMP/master_taskloop_simd_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -316,7 +316,7 @@
 
 #pragma omp parallel
   {
-// expected-error@+2 {{loop iteration variable in the associated loop of 'omp master taskloop simd' directive may not be threadprivate or thread local, predetermined as linear}}
+// no error expected @+2 {{loop iteration variable in the associated loop of 'omp master taskloop simd' directive may not be threadprivate or thread local, predetermined as linear}}
 #pragma omp master taskloop simd
     for (sii = 0; sii < 10; sii += 1)
       c[sii] = a[sii];
Index: clang/test/OpenMP/master_taskloop_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/master_taskloop_loop_messages.cpp
+++ clang/test/OpenMP/master_taskloop_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected@+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -314,7 +314,8 @@
 
 #pragma omp parallel
   {
-// expected-error@+2 {{loop iteration variable in the associated loop of 'omp master taskloop' directive may not be threadprivate or thread local, predetermined as private}}
+// loop var with threadprivate or thread local is predetermined as threadprivate
+// not error expected@+2 {{loop iteration variable in the associated loop of 'omp master taskloop' directive may not be threadprivate or thread local, predetermined as private}}
 #pragma omp master taskloop
     for (sii = 0; sii < 10; sii += 1)
       c[sii] = a[sii];
Index: clang/test/OpenMP/for_simd_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/for_simd_loop_messages.cpp
+++ clang/test/OpenMP/for_simd_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -311,7 +311,7 @@
 
 #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}}
+// no error expected @+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];
Index: clang/test/OpenMP/for_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/for_loop_messages.cpp
+++ clang/test/OpenMP/for_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected@+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -334,7 +334,8 @@
 
 #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}}
+// loop var with threadprivate or thread local is predetermined as threadprivate
+// not error expected@+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];
Index: clang/test/OpenMP/distribute_simd_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/distribute_simd_loop_messages.cpp
+++ clang/test/OpenMP/distribute_simd_loop_messages.cpp
@@ -21,7 +21,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -365,7 +365,7 @@
   {
     #pragma omp target
     #pragma omp teams
-// expected-error@+2 {{loop iteration variable in the associated loop of 'omp distribute simd' directive may not be threadprivate or thread local, predetermined as linear}}
+// no error expected @+2 {{loop iteration variable in the associated loop of 'omp distribute simd' directive may not be threadprivate or thread local, predetermined as linear}}
     #pragma omp distribute simd
     for (sii = 0; sii < 10; sii+=1)
       c[sii] = a[sii];
Index: clang/test/OpenMP/distribute_parallel_for_simd_loop_messages.cpp
===================================================================
--- clang/test/OpenMP/distribute_parallel_for_simd_loop_messages.cpp
+++ clang/test/OpenMP/distribute_parallel_for_simd_loop_messages.cpp
@@ -14,7 +14,7 @@
 };
 
 static int sii;
-// expected-note@+1 {{defined as threadprivate or thread local}}
+// no note expected @+1 {{defined as threadprivate or thread local}}
 #pragma omp threadprivate(sii)
 static int globalii;
 
@@ -356,7 +356,7 @@
     c[ii] = a[ii];
 
   {
-// expected-error@+2 {{loop iteration variable in the associated loop of 'omp distribute parallel for simd' directive may not be threadprivate or thread local, predetermined as linear}}
+// no error expected @+2 {{loop iteration variable in the associated loop of 'omp distribute parallel for simd' directive may not be threadprivate or thread local, predetermined as linear}}
 #pragma omp distribute parallel for simd
     for (sii = 0; sii < 10; sii += 1)
       c[sii] = a[sii];
Index: clang/lib/Sema/SemaOpenMP.cpp
===================================================================
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -8629,13 +8629,19 @@
                                  ForLoc, /*RefersToCapture=*/true));
         }
         OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective();
-        // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables
-        // Referenced in a Construct, C/C++]. The loop iteration variable in the
-        // associated for-loop of a simd construct with just one associated
-        // for-loop may be listed in a linear clause with a constant-linear-step
-        // that is the increment of the associated for-loop. The loop iteration
-        // variable(s) in the associated for-loop(s) of a for or parallel for
-        // construct may be listed in a private or lastprivate clause.
+        // OpenMP 5.1:[2.21.1.1, Data-Sharing Attribute Rules for Variables:
+        // Variables that appear in threadprivate directives or variables
+        // with the _Thread_local (in C) or thread_local (in C++)
+        // storage-class specifier are threadprivate.
+        // The loop iteration variable in any associated loop of a for,
+        // parallel for, taskloop, or distribute construct is private.
+        // The loop iteration variable in the associated loop of a simd
+        // construct with just one associated loop is linear with a
+        // linear-step that is the increment of the associated loop.
+        // The loop iteration variables in the associated loops of a simd
+        // construct with multiple associated loops are lastprivate.
+        // The loop iteration variable in any associated loop of a loop
+        // construct is lastprivate.
         DSAStackTy::DSAVarData DVar =
             DSAStack->getTopDSA(D, /*FromParent=*/false);
         // If LoopVarRefExpr is nullptr it means the corresponding loop variable
@@ -8644,24 +8650,35 @@
         OpenMPClauseKind PredeterminedCKind =
             isOpenMPSimdDirective(DKind)
                 ? (DSAStack->hasMutipleLoops() ? OMPC_lastprivate : OMPC_linear)
-                : OMPC_private;
-        if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown &&
-              DVar.CKind != PredeterminedCKind && DVar.RefExpr &&
-              (LangOpts.OpenMP <= 45 || (DVar.CKind != OMPC_lastprivate &&
-                                         DVar.CKind != OMPC_private))) ||
-             ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop ||
-               DKind == OMPD_master_taskloop ||
-               DKind == OMPD_parallel_master_taskloop ||
-               isOpenMPDistributeDirective(DKind)) &&
-              !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown &&
-              DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) &&
-            (DVar.CKind != OMPC_private || DVar.RefExpr)) {
+            : DVar.CKind == OMPC_lastprivate ? OMPC_lastprivate
+                                             : OMPC_private;
+        // OpenMP 5.0 and up: If a simd construct has just one associated
+        // loop then its loop iteration variable may be listed in a private,
+        // lastprivate, or linear clause with a linear-step that is the
+        // increment of the associated loop
+        // If a simd construct has more than one associated loop then their
+        // loop iteration variables may be listed in a private or
+        // lastprivate clause
+        if (LangOpts.OpenMP > 45 && isOpenMPSimdDirective(DKind)) {
+          if (DVar.CKind == OMPC_lastprivate)
+            PredeterminedCKind = OMPC_lastprivate;
+          else if (DVar.CKind == OMPC_private)
+            PredeterminedCKind = OMPC_private;
+        }
+        // LoopVar with threadprivate is predetermined as threadprivate
+        if (DVar.CKind == OMPC_threadprivate)
+          PredeterminedCKind = OMPC_threadprivate;
+        if ((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown &&
+             DVar.CKind != PredeterminedCKind && DVar.RefExpr) ||
+            ((isOpenMPWorksharingDirective(DKind) ||
+              isOpenMPTaskLoopDirective(DKind) ||
+              isOpenMPDistributeDirective(DKind)) &&
+             !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown &&
+             DVar.CKind != PredeterminedCKind && DVar.RefExpr)) {
           Diag(Init->getBeginLoc(), diag::err_omp_loop_var_dsa)
               << getOpenMPClauseName(DVar.CKind)
               << getOpenMPDirectiveName(DKind)
               << getOpenMPClauseName(PredeterminedCKind);
-          if (DVar.RefExpr == nullptr)
-            DVar.CKind = PredeterminedCKind;
           reportOriginalDsa(*this, DSAStack, D, DVar,
                             /*IsLoopIterVar=*/true);
         } else if (LoopDeclRefExpr) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to