r303077 - [OPENMP] Check DSA for variables captured by value.

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Mon May 15 09:26:16 PDT 2017


Author: abataev
Date: Mon May 15 11:26:15 2017
New Revision: 303077

URL: http://llvm.org/viewvc/llvm-project?rev=303077&view=rev
Log:
[OPENMP] Check DSA for variables captured by value.

Currently clang checks for default data sharing attributes only for
variables captured in OpenMP regions by reference. Patch adds checks for
variables captured by value.

Added:
    cfe/trunk/test/OpenMP/report_default_DSA.cpp
Modified:
    cfe/trunk/lib/AST/Stmt.cpp

Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=303077&r1=303076&r2=303077&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Mon May 15 11:26:15 2017
@@ -1112,7 +1112,7 @@ void CapturedStmt::setCapturedRegionKind
 
 bool CapturedStmt::capturesVariable(const VarDecl *Var) const {
   for (const auto &I : captures()) {
-    if (!I.capturesVariable())
+    if (!I.capturesVariable() && !I.capturesVariableByCopy())
       continue;
 
     // This does not handle variable redeclarations. This should be

Added: cfe/trunk/test/OpenMP/report_default_DSA.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/report_default_DSA.cpp?rev=303077&view=auto
==============================================================================
--- cfe/trunk/test/OpenMP/report_default_DSA.cpp (added)
+++ cfe/trunk/test/OpenMP/report_default_DSA.cpp Mon May 15 11:26:15 2017
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 %s
+
+void foo(int x, int n) {
+  double vec[n];
+  for (int iter = 0; iter < x; iter++) {
+#pragma omp target teams distribute parallel for map( \
+    from                                              \
+    : vec [0:n]) default(none)
+    // expected-error at +1 {{variable 'n' must have explicitly specified data sharing attributes}}
+    for (int ii = 0; ii < n; ii++) {
+      // expected-error at +3 {{variable 'iter' must have explicitly specified data sharing attributes}}
+      // expected-error at +2 {{variable 'vec' must have explicitly specified data sharing attributes}}
+      // expected-error at +1 {{variable 'x' must have explicitly specified data sharing attributes}}
+      vec[ii] = iter + ii + x;
+    }
+  }
+}
+




More information about the cfe-commits mailing list