[flang-commits] [flang] 6e7df70 - [flang][runtime] Handle array components in NAMELIST input

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu Oct 6 14:49:36 PDT 2022


Author: Peter Klausler
Date: 2022-10-06T14:49:24-07:00
New Revision: 6e7df70e5acb482b118b8d9a8957c0980a172e16

URL: https://github.com/llvm/llvm-project/commit/6e7df70e5acb482b118b8d9a8957c0980a172e16
DIFF: https://github.com/llvm/llvm-project/commit/6e7df70e5acb482b118b8d9a8957c0980a172e16.diff

LOG: [flang][runtime] Handle array components in NAMELIST input

A namelist input item that is a derived type component reference
needs additional processing when the base item or the component
is an array.  When both have rank > 0, the component reference
must of course be subscripted.

Differential Revision: https://reviews.llvm.org/D135218

Added: 
    

Modified: 
    flang/runtime/namelist.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/namelist.cpp b/flang/runtime/namelist.cpp
index 125b8509c631f..48761a90e4dc4 100644
--- a/flang/runtime/namelist.cpp
+++ b/flang/runtime/namelist.cpp
@@ -310,7 +310,42 @@ static bool HandleComponent(IoStatementState &io, Descriptor &desc,
         type{addendum ? addendum->derivedType() : nullptr}) {
       if (const typeInfo::Component *
           comp{type->FindDataComponent(compName, std::strlen(compName))}) {
-        comp->CreatePointerDescriptor(desc, source, handler);
+        bool createdDesc{false};
+        if (comp->rank() > 0 && source.rank() > 0) {
+          // If base and component are both arrays, the component name
+          // must be followed by subscripts; process them now.
+          std::size_t byteCount{0};
+          if (std::optional<char32_t> next{io.GetNextNonBlank(byteCount)};
+              next && *next == '(') {
+            io.HandleRelativePosition(byteCount); // skip over '('
+            StaticDescriptor<maxRank, true, 16> staticDesc;
+            Descriptor &tmpDesc{staticDesc.descriptor()};
+            comp->CreatePointerDescriptor(tmpDesc, source, handler);
+            if (!HandleSubscripts(io, desc, tmpDesc, compName)) {
+              return false;
+            }
+            createdDesc = true;
+          }
+        }
+        if (!createdDesc) {
+          comp->CreatePointerDescriptor(desc, source, handler);
+        }
+        if (source.rank() > 0) {
+          if (desc.rank() > 0) {
+            handler.SignalError(
+                "NAMELIST component reference '%%%s' of input group "
+                "item %s cannot be an array when its base is not scalar",
+                compName, name);
+            return false;
+          }
+          desc.raw().rank = source.rank();
+          for (int j{0}; j < source.rank(); ++j) {
+            const auto &srcDim{source.GetDimension(j)};
+            desc.GetDimension(j)
+                .SetBounds(1, srcDim.UpperBound())
+                .SetByteStride(srcDim.ByteStride());
+          }
+        }
         return true;
       } else {
         handler.SignalError(


        


More information about the flang-commits mailing list