[PATCH] D157229: Fix edge case in declare target initializer expression

Ritanya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 6 06:40:50 PDT 2023


RitanyaB created this revision.
RitanyaB added reviewers: soumitra, sandeepkosuri, koops, ABataev.
Herald added a project: All.
RitanyaB requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, jplehr, sstefan1.
Herald added a project: clang.

This patch adds support for the following edge cases in declare target - 
#pragma omp declare target(variable)
#pragma omp declare target to(variable)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157229

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/declare_target_variables_ast_print.cpp


Index: clang/test/OpenMP/declare_target_variables_ast_print.cpp
===================================================================
--- clang/test/OpenMP/declare_target_variables_ast_print.cpp
+++ clang/test/OpenMP/declare_target_variables_ast_print.cpp
@@ -27,6 +27,10 @@
 };
 static target S;
 
+static int var3 = 100;
+static int *ptr_3 = &var3;
+static char c = 'a';
+
 #pragma omp declare target
 int target_var = variable;
 float target_var1 = variable2;
@@ -36,6 +40,9 @@
 declare **obj3 = &obj2;
 target *S1 = &S;
 #pragma omp end declare target
+#pragma omp declare target(ptr_3)
+#pragma omp declare target to(c)
+
 // CHECK: #pragma omp declare target
 // CHECK-NEXT: static int variable = 100;
 // CHECK-NEXT: #pragma omp end declare target
@@ -87,7 +94,15 @@
 // CHECK-NEXT: #pragma omp declare target
 // CHECK-NEXT: static target S;
 // CHECK-NEXT: #pragma omp end declare target
-
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static int var3 = 100;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static int *ptr_3 = &var3;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static char c = 'a';
+// CHECK-NEXT: #pragma omp end declare target
 // CHECK-NEXT: #pragma omp declare target
 // CHECK-NEXT: int target_var = variable;
 // CHECK-NEXT: #pragma omp end declare target
Index: clang/lib/Sema/SemaOpenMP.cpp
===================================================================
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -23102,6 +23102,10 @@
   if (ASTMutationListener *ML = Context.getASTMutationListener())
     ML->DeclarationMarkedOpenMPDeclareTarget(ND, A);
   checkDeclIsAllowedInOpenMPTarget(nullptr, ND, Loc);
+  if (auto *VD = dyn_cast<VarDecl>(ND);
+      LangOpts.OpenMP && VD && VD->hasAttr<OMPDeclareTargetDeclAttr>() &&
+      VD->hasGlobalStorage())
+    ActOnOpenMPDeclareTargetInitializer(ND);
 }
 
 static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157229.547571.patch
Type: text/x-patch
Size: 2064 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230806/8a8e3ceb/attachment-0001.bin>


More information about the cfe-commits mailing list