[PATCH] D153369: [OpenMP] Always apply target declarations to canonical definitions

Joseph Huber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 20 11:33:48 PDT 2023


jhuber6 updated this revision to Diff 533002.
jhuber6 added a comment.

Fix logic


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153369/new/

https://reviews.llvm.org/D153369

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/AST/dump.cpp


Index: clang/test/AST/dump.cpp
===================================================================
--- clang/test/AST/dump.cpp
+++ clang/test/AST/dump.cpp
@@ -79,11 +79,32 @@
 }
 #pragma omp end declare target
 
-// CHECK:       `-FunctionDecl {{.+}} <line:[[@LINE-6]]:1, line:[[@LINE-3]]:1> line:[[@LINE-6]]:5 bar 'int ()'
-// CHECK-NEXT:  |-CompoundStmt {{.+}} <col:11, line:[[@LINE-4]]:1>
-// CHECK-NEXT:  | |-DeclStmt {{.+}} <line:[[@LINE-7]]:3, col:8>
-// CHECK-NEXT:  | | `-VarDecl {{.+}} <col:3, col:7> col:7 used f 'int'
-// CHECK-NEXT:  | `-ReturnStmt {{.+}} <line:[[@LINE-8]]:3, col:10>
-// CHECK-NEXT:  |   `-ImplicitCastExpr {{.+}} <col:10> 'int' <LValueToRValue>
-// CHECK-NEXT:  |     `-DeclRefExpr {{.+}} <col:10> 'int' lvalue Var {{.+}} 'f' 'int'
-// CHECK-NEXT:  `-OMPDeclareTargetDeclAttr {{.+}} <line:75:21> Implicit MT_To DT_Any 1
+// CHECK:      |-FunctionDecl {{.+}} <line:[[@LINE-6]]:1, line:[[@LINE-3]]:1> line:[[@LINE-6]]:5 bar 'int ()'
+// CHECK-NEXT: | |-CompoundStmt {{.+}} <col:11, line:[[@LINE-4]]:1>
+// CHECK-NEXT: | | |-DeclStmt {{.+}} <line:[[@LINE-7]]:3, col:8>
+// CHECK-NEXT: | | | `-VarDecl {{.+}} <col:3, col:7> col:7 used f 'int'
+// CHECK-NEXT: | | `-ReturnStmt {{.+}} <line:[[@LINE-8]]:3, col:10>
+// CHECK-NEXT: | |   `-ImplicitCastExpr {{.+}} <col:10> 'int' <LValueToRValue>
+// CHECK-NEXT: | |     `-DeclRefExpr {{.+}} <col:10> 'int' lvalue Var {{.+}} 'f' 'int'
+// CHECK-NEXT: | `-OMPDeclareTargetDeclAttr {{.+}} <line:[[@LINE-14]]:21> Implicit MT_To DT_Any 1
+
+int dx;
+
+extern int dx;
+#pragma omp declare target to(dx)
+
+// CHECK:      |-VarDecl {{.+}} <line:[[@LINE-5]]:1, col:5> col:5 dx 'int'
+// CHECK-NEXT: | `-OMPDeclareTargetDeclAttr {{.+}} <line:[[@LINE-3]]:31> Implicit MT_To DT_Any 4294967295
+// CHECK:      |-VarDecl {{.+}} prev {{.+}} <line:[[@LINE-5]]:1, col:12> col:12 dx 'int' extern
+// CHECK-NEXT: | `-OMPDeclareTargetDeclAttr {{.+}} <line:[[@LINE-5]]:31> Implicit MT_To DT_Any 4294967295
+
+int dy;
+
+#pragma omp begin declare target
+extern int dy;
+#pragma omp end declare target
+
+// CHECK:      |-VarDecl {{.+}} <line:[[@LINE-6]]:1, col:5> col:5 dy 'int'
+// CHECK-NEXT: | `-OMPDeclareTargetDeclAttr {{.+}} <line:[[@LINE-5]]:27> Implicit MT_To DT_Any 1
+// CHECK:      `-VarDecl {{.+}} prev {{.+}} <line:[[@LINE-5]]:1, col:12> col:12 dy 'int' extern
+// CHECK-NEXT:   `-OMPDeclareTargetDeclAttr {{.+}} <line:[[@LINE-7]]:27> Implicit MT_To DT_Any 1
Index: clang/lib/Sema/SemaOpenMP.cpp
===================================================================
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -22988,6 +22988,15 @@
   ND->addAttr(A);
   if (ASTMutationListener *ML = Context.getASTMutationListener())
     ML->DeclarationMarkedOpenMPDeclareTarget(ND, A);
+
+  // If this was not a canonical definition we need to update it as well.
+  if (auto *CD = dyn_cast<NamedDecl>(ND->getCanonicalDecl())) {
+    if (!CD->hasAttr<OMPDeclareTargetDeclAttr>()) {
+      CD->addAttr(A);
+      if (ASTMutationListener *ML = Context.getASTMutationListener())
+        ML->DeclarationMarkedOpenMPDeclareTarget(CD, A);
+    }
+  }
   checkDeclIsAllowedInOpenMPTarget(nullptr, ND, Loc);
 }
 
@@ -23092,6 +23101,15 @@
         D->addAttr(A);
         if (ASTMutationListener *ML = Context.getASTMutationListener())
           ML->DeclarationMarkedOpenMPDeclareTarget(D, A);
+
+        // If this was not a canonical definition we need to update it as well.
+        if (auto *CD = dyn_cast<NamedDecl>(D->getCanonicalDecl())) {
+          if (!CD->hasAttr<OMPDeclareTargetDeclAttr>()) {
+            CD->addAttr(A);
+            if (ASTMutationListener *ML = Context.getASTMutationListener())
+              ML->DeclarationMarkedOpenMPDeclareTarget(CD, A);
+          }
+        }
       }
       return;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153369.533002.patch
Type: text/x-patch
Size: 3800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230620/b45d25ea/attachment-0001.bin>


More information about the cfe-commits mailing list