[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:30:39 PDT 2023


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

Adding AST mutation listener to the other modified declaration to signal that it was changed.


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
@@ -22986,6 +22986,9 @@
       Context, MT, DTCI.DT, IndirectE, IsIndirect, Level,
       SourceRange(Loc, Loc));
   ND->addAttr(A);
+  if (auto *CD = dyn_cast<NamedDecl>(ND->getCanonicalDecl()))
+    if (!CD->hasAttr<OMPDeclareTargetDeclAttr>())
+      CD->addAttr(A);
   if (ASTMutationListener *ML = Context.getASTMutationListener())
     ML->DeclarationMarkedOpenMPDeclareTarget(ND, A);
   checkDeclIsAllowedInOpenMPTarget(nullptr, ND, Loc);
@@ -23090,8 +23093,15 @@
             DTCI.DT, IndirectE, IsIndirect, Level,
             SourceRange(DTCI.Loc, DTCI.Loc));
         D->addAttr(A);
-        if (ASTMutationListener *ML = Context.getASTMutationListener())
+        if (auto *CD = dyn_cast<NamedDecl>(D->getCanonicalDecl()))
+          if (!CD->hasAttr<OMPDeclareTargetDeclAttr>())
+            CD->addAttr(A);
+        if (ASTMutationListener *ML = Context.getASTMutationListener()) {
           ML->DeclarationMarkedOpenMPDeclareTarget(D, A);
+          if (auto *CD = dyn_cast<NamedDecl>(D->getCanonicalDecl()))
+            if (!CD->hasAttr<OMPDeclareTargetDeclAttr>())
+              ML->DeclarationMarkedOpenMPDeclareTarget(CD, A);
+        }
       }
       return;
     }


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


More information about the cfe-commits mailing list