[PATCH] D22075: [OpenMP] Fix incorrect diagnostics in map clause

David S via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 6 16:52:42 PDT 2016


davidsh created this revision.
davidsh added reviewers: carlo.bertolli, arpith-jacob, sfantao, ABataev, kkwli0.
davidsh added a subscriber: cfe-commits.

Having the following code pattern will result in incorrect diagnostic
int main() {
int arr[10];
#pragma omp target data map(arr[:])
#pragma omp target map(arr)
{}
}
t.cpp:4:24: error: original storage of expression in data environment is shared but data environment do not fully contain mapped expression storage
#pragma omp target map(arr)
                       ^~~
t.cpp:3:29: note: used here
#pragma omp target data map(arr[:])
                            ^~~~~~
1 error generated.        

http://reviews.llvm.org/D22075

Files:
  lib/Sema/SemaOpenMP.cpp
  test/OpenMP/target_map_messages.cpp

Index: test/OpenMP/target_map_messages.cpp
===================================================================
--- test/OpenMP/target_map_messages.cpp
+++ test/OpenMP/target_map_messages.cpp
@@ -284,6 +284,11 @@
     {}
   }
   }
+  #pragma omp target data map(marr[:][:][:])
+  {
+    #pragma omp target data map(marr)
+    {}
+  }
 
   #pragma omp target data map(to: t)
   {
@@ -488,10 +493,10 @@
 #pragma omp target data map(j)
 #pragma omp target map(l) map(l[:5]) // expected-error {{variable already marked as mapped in current construct}} expected-note {{used here}}
   foo();
-#pragma omp target data map(k[:4], j, l[:5]) // expected-note 2 {{used here}}
+#pragma omp target data map(k[:4], j, l[:5]) // expected-note {{used here}}
 #pragma omp target data map(k) // expected-error {{pointer cannot be mapped along with a section derived from itself}}
 #pragma omp target data map(j)
-#pragma omp target map(l) // expected-error {{original storage of expression in data environment is shared but data environment do not fully contain mapped expression storage}}
+#pragma omp target map(l)
   foo();
 
 #pragma omp target data map(always, tofrom: x)
Index: lib/Sema/SemaOpenMP.cpp
===================================================================
--- lib/Sema/SemaOpenMP.cpp
+++ lib/Sema/SemaOpenMP.cpp
@@ -10637,6 +10637,24 @@
           if (CI->getAssociatedDeclaration() != SI->getAssociatedDeclaration())
             break;
         }
+        while(SI != SE) {
+          QualType Type;
+          if (auto *ASE = 
+              dyn_cast<ArraySubscriptExpr>(SI->getAssociatedExpression())) {
+            Type = ASE->getBase()->IgnoreParenImpCasts()->getType();
+          } else if (auto *OASE = 
+               dyn_cast<OMPArraySectionExpr>(SI->getAssociatedExpression())) {
+            auto *E = OASE->getBase()->IgnoreParenImpCasts();
+            Type =
+                OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType();
+          }
+          if (!Type.isNull() && !Type->isAnyPointerType() &&
+              !CheckArrayExpressionDoesNotReferToWholeSize(SemaRef,
+               SI->getAssociatedExpression(),Type))
+            ++SI;
+          else
+            break;
+        }
 
         // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4]
         //  List items of map clauses in the same construct must not share


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22075.62992.patch
Type: text/x-patch
Size: 2365 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160706/7420119a/attachment.bin>


More information about the cfe-commits mailing list