[flang-commits] [PATCH] D120835: [flang] Handle optional TARGET associate in ASSOCIATED runtime

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Mar 2 10:47:33 PST 2022


jeanPerier created this revision.
jeanPerier added a reviewer: klausler.
jeanPerier added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
jeanPerier requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The TARGET argument of ASSOCIATED may be dynamically optional, in which
case ASSOCIATED(POINTER, TARGET) is equal to ASSOCIATED(TARGET).

Make the runtime argument a pointer so that it can detect and handle
arguments that are dynamically optional.

Also fix the runtime to check if TARGET base address is not null and if
its element size is not null to match the requirement of ASSOCIATED
regarding TARGET:

- if TARGET is an object: true iff [..] TARGET is not a zerosized storage sequence
- if TARGET is a POINTER: true iff [..] POINTER and TARGET are associated

Not that ASSOCIATED will also returns false if TARGET is an unallocated allocatable.
This is not described in the standard, but is a unanimous behaviour of
existing compilers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120835

Files:
  flang/include/flang/Runtime/pointer.h
  flang/runtime/pointer.cpp


Index: flang/runtime/pointer.cpp
===================================================================
--- flang/runtime/pointer.cpp
+++ flang/runtime/pointer.cpp
@@ -147,16 +147,22 @@
 }
 
 bool RTNAME(PointerIsAssociatedWith)(
-    const Descriptor &pointer, const Descriptor &target) {
+    const Descriptor &pointer, const Descriptor *target) {
+  if (!target) {
+    return pointer.raw().base_addr != nullptr;
+  }
+  if (!target->raw().base_addr || target->ElementBytes() == 0) {
+    return false;
+  }
   int rank{pointer.rank()};
-  if (pointer.raw().base_addr != target.raw().base_addr ||
-      pointer.ElementBytes() != target.ElementBytes() ||
-      rank != target.rank()) {
+  if (pointer.raw().base_addr != target->raw().base_addr ||
+      pointer.ElementBytes() != target->ElementBytes() ||
+      rank != target->rank()) {
     return false;
   }
   for (int j{0}; j < rank; ++j) {
     const Dimension &pDim{pointer.GetDimension(j)};
-    const Dimension &tDim{target.GetDimension(j)};
+    const Dimension &tDim{target->GetDimension(j)};
     if (pDim.Extent() != tDim.Extent() ||
         pDim.ByteStride() != tDim.ByteStride()) {
       return false;
Index: flang/include/flang/Runtime/pointer.h
===================================================================
--- flang/include/flang/Runtime/pointer.h
+++ flang/include/flang/Runtime/pointer.h
@@ -105,7 +105,7 @@
 
 // True when the pointer is associated with a specific target.
 bool RTNAME(PointerIsAssociatedWith)(
-    const Descriptor &, const Descriptor &target);
+    const Descriptor &, const Descriptor *target);
 
 } // extern "C"
 } // namespace Fortran::runtime


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120835.412486.patch
Type: text/x-patch
Size: 1650 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220302/29be298e/attachment.bin>


More information about the flang-commits mailing list