Browse Source

[OPENMP]Fix top DSA for static members.

Fixed handling of the data-sharing attributes for static members when
requesting top most attribute. Previously, it might return the incorrect
attributes for static members if they were overriden in the outer
constructs.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@364655 91177308-0d34-0410-b5e6-96231b3b80d8
Alexey Bataev 6 years ago
parent
commit
40aa8e605d
2 changed files with 20 additions and 3 deletions
  1. 15 3
      lib/Sema/SemaOpenMP.cpp
  2. 5 0
      test/OpenMP/simd_loop_messages.cpp

+ 15 - 3
lib/Sema/SemaOpenMP.cpp

@@ -1354,16 +1354,28 @@ const DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D,
   // in a Construct, C/C++, predetermined, p.7]
   // in a Construct, C/C++, predetermined, p.7]
   //  Variables with static storage duration that are declared in a scope
   //  Variables with static storage duration that are declared in a scope
   //  inside the construct are shared.
   //  inside the construct are shared.
-  auto &&MatchesAlways = [](OpenMPDirectiveKind) { return true; };
   if (VD && VD->isStaticDataMember()) {
   if (VD && VD->isStaticDataMember()) {
-    DSAVarData DVarTemp = hasDSA(D, isOpenMPPrivate, MatchesAlways, FromParent);
-    if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr)
+    // Check for explicitly specified attributes.
+    const_iterator I = begin();
+    const_iterator EndI = end();
+    if (FromParent && I != EndI)
+      ++I;
+    auto It = I->SharingMap.find(D);
+    if (It != I->SharingMap.end()) {
+      const DSAInfo &Data = It->getSecond();
+      DVar.RefExpr = Data.RefExpr.getPointer();
+      DVar.PrivateCopy = Data.PrivateCopy;
+      DVar.CKind = Data.Attributes;
+      DVar.ImplicitDSALoc = I->DefaultAttrLoc;
+      DVar.DKind = I->Directive;
       return DVar;
       return DVar;
+    }
 
 
     DVar.CKind = OMPC_shared;
     DVar.CKind = OMPC_shared;
     return DVar;
     return DVar;
   }
   }
 
 
+  auto &&MatchesAlways = [](OpenMPDirectiveKind) { return true; };
   // The predetermined shared attribute for const-qualified types having no
   // The predetermined shared attribute for const-qualified types having no
   // mutable members was removed after OpenMP 3.1.
   // mutable members was removed after OpenMP 3.1.
   if (SemaRef.LangOpts.OpenMP <= 31) {
   if (SemaRef.LangOpts.OpenMP <= 31) {

+ 5 - 0
test/OpenMP/simd_loop_messages.cpp

@@ -9,6 +9,7 @@ static int sii;
 static int globalii;
 static int globalii;
 
 
 struct S {
 struct S {
+  // expected-note@+1 {{static data member is predetermined as shared}}
   static int ssi;
   static int ssi;
 };
 };
 
 
@@ -21,6 +22,10 @@ int test_iteration_spaces() {
 #pragma omp simd linear(S::ssi)
 #pragma omp simd linear(S::ssi)
   for (S::ssi = 0; S::ssi < 10; ++S::ssi)
   for (S::ssi = 0; S::ssi < 10; ++S::ssi)
     ;
     ;
+// expected-error@+1 {{shared variable cannot be private}}
+#pragma omp simd private(S::ssi)
+  for (S::ssi = 0; S::ssi < 10; ++S::ssi)
+    ;
 #pragma omp simd // no messages expected
 #pragma omp simd // no messages expected
   for (S::ssi = 0; S::ssi < 10; ++S::ssi)
   for (S::ssi = 0; S::ssi < 10; ++S::ssi)
     ;
     ;