r336592 - [OPENMP] Do not mark local variables as declare target.

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 9 12:58:08 PDT 2018


Author: abataev
Date: Mon Jul  9 12:58:08 2018
New Revision: 336592

URL: http://llvm.org/viewvc/llvm-project?rev=336592&view=rev
Log:
[OPENMP] Do not mark local variables as declare target.

When the parsing of the functions happens inside of the declare target
region, we may erroneously mark local variables as declare target
thought they are not. This attribute can be applied only to global
variables.

Modified:
    cfe/trunk/lib/Sema/SemaOpenMP.cpp
    cfe/trunk/test/OpenMP/dump.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=336592&r1=336591&r2=336592&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Mon Jul  9 12:58:08 2018
@@ -13012,8 +13012,12 @@ void Sema::checkDeclIsAllowedInOpenMPTar
     return;
   SourceRange SR = E ? E->getSourceRange() : D->getSourceRange();
   SourceLocation SL = E ? E->getLocStart() : D->getLocation();
-  // 2.10.6: threadprivate variable cannot appear in a declare target directive.
   if (auto *VD = dyn_cast<VarDecl>(D)) {
+    // Only global variables can be marked as declare target.
+    if (VD->isLocalVarDeclOrParm())
+      return;
+    // 2.10.6: threadprivate variable cannot appear in a declare target
+    // directive.
     if (DSAStack->isThreadPrivate(VD)) {
       Diag(SL, diag::err_omp_threadprivate_in_target);
       reportOriginalDsa(*this, DSAStack, VD, DSAStack->getTopDSA(VD, false));

Modified: cfe/trunk/test/OpenMP/dump.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/dump.cpp?rev=336592&r1=336591&r2=336592&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/dump.cpp (original)
+++ cfe/trunk/test/OpenMP/dump.cpp Mon Jul  9 12:58:08 2018
@@ -63,7 +63,22 @@ struct S {
 #pragma omp declare simd inbranch
 void foo();
 
-// CHECK:      `-FunctionDecl {{.+}} <line:64:1, col:10> col:6 foo 'void ()'
+// CHECK:        |-FunctionDecl {{.+}} <line:64:1, col:10> col:6 foo 'void ()'
 // CHECK-NEXT:   |-OMPDeclareSimdDeclAttr {{.+}} <line:63:9, col:34> Implicit BS_Inbranch
 // CHECK:        `-OMPDeclareSimdDeclAttr {{.+}} <line:62:9, col:25> Implicit BS_Undefined
 
+#pragma omp declare target
+int bar() {
+  int f;
+  return f;
+}
+#pragma omp end declare target
+
+// CHECK:       `-FunctionDecl {{.+}} <line:71:1, line:74:1> line:71:5 bar 'int ()'
+// CHECK-NEXT:  |-CompoundStmt {{.+}} <col:11, line:74:1>
+// CHECK-NEXT:  | |-DeclStmt {{.+}} <line:72:3, col:8>
+// CHECK-NEXT:  | | `-VarDecl {{.+}} <col:3, col:7> col:7 used f 'int'
+// CHECK-NEXT:  | `-ReturnStmt {{.+}} <line:73:3, col:10>
+// CHECK-NEXT:  |   `-ImplicitCastExpr {{.+}} <col:10> 'int' <LValueToRValue>
+// CHECK-NEXT:  |     `-DeclRefExpr {{.+}} <col:10> 'int' lvalue Var {{.+}} 'f' 'int'
+// CHECK-NEXT:  `-OMPDeclareTargetDeclAttr {{.+}} <<invalid sloc>> Implicit MT_To




More information about the cfe-commits mailing list