[PATCH] D112876: [Flang][OpenMP] Copy the attributes when creating a host-associated symbol

Kiran Chandramohan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 30 13:32:15 PDT 2021


kiranchandramohan created this revision.
kiranchandramohan added reviewers: klausler, peixin.
Herald added subscribers: guansong, yaxunl.
Herald added a reviewer: sscalpone.
Herald added a project: Flang.
kiranchandramohan requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, sstefan1, jdoerfert.
Herald added a project: LLVM.

Host associated symbols are created for privatized variables in OpenMP regions.
Currently the attributes of the host symbol are not copied to the privatized
symbol. This causes some issues in Semantic checks because the privatized variable's
symbol does not carry the pointer or allocatable attributes.

This patch fixes the issue reported by Peixin in https://github.com/flang-compiler/f18-llvm-project/issues/1171#issuecomment-955180002.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112876

Files:
  flang/lib/Semantics/resolve-directives.cpp
  flang/test/Semantics/omp-symbol09.f90


Index: flang/test/Semantics/omp-symbol09.f90
===================================================================
--- /dev/null
+++ flang/test/Semantics/omp-symbol09.f90
@@ -0,0 +1,16 @@
+! RUN: %python %S/test_symbols.py %s %flang_fc1 -fopenmp
+
+!DEF:/test_attrs (Subroutine) Subprogram
+subroutine test_attrs
+  implicit none
+  !DEF: /test_attrs/p POINTER ObjectEntity INTEGER(4)
+  integer, pointer :: p
+  !DEF: /test_attrs/a ALLOCATABLE ObjectEntity INTEGER(4)
+  integer, allocatable :: a
+
+  !$omp parallel private(p, a)
+  !DEF: /test_attrs/Block1/p POINTER (OmpPrivate) HostAssoc INTEGER(4)
+  !DEF: /test_attrs/Block1/a ALLOCATABLE (OmpPrivate) HostAssoc INTEGER(4)
+    print *, p, a
+  !$omp end parallel
+end subroutine
Index: flang/lib/Semantics/resolve-directives.cpp
===================================================================
--- flang/lib/Semantics/resolve-directives.cpp
+++ flang/lib/Semantics/resolve-directives.cpp
@@ -79,7 +79,7 @@
     GetContext().associatedLoopLevel = level;
   }
   Symbol &MakeAssocSymbol(const SourceName &name, Symbol &prev, Scope &scope) {
-    const auto pair{scope.try_emplace(name, Attrs{}, HostAssocDetails{prev})};
+    const auto pair{scope.try_emplace(name, prev.attrs(), HostAssocDetails{prev})};
     return *pair.first->second;
   }
   Symbol &MakeAssocSymbol(const SourceName &name, Symbol &prev) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112876.383618.patch
Type: text/x-patch
Size: 1368 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211030/e820c633/attachment.bin>


More information about the llvm-commits mailing list