[flang-commits] [flang] 89a927c - [flang] Fix NAMELIST input bug with multiple subscript triplets

peter klausler via flang-commits flang-commits at lists.llvm.org
Fri Oct 22 16:02:10 PDT 2021


Author: peter klausler
Date: 2021-10-22T15:59:28-07:00
New Revision: 89a927c6781200701b01ae4f48bac16e6f082549

URL: https://github.com/llvm/llvm-project/commit/89a927c6781200701b01ae4f48bac16e6f082549
DIFF: https://github.com/llvm/llvm-project/commit/89a927c6781200701b01ae4f48bac16e6f082549.diff

LOG: [flang] Fix NAMELIST input bug with multiple subscript triplets

NAMELIST input can contain array subscripts with triplet notation.
The calculation of the default effective stride for the constructed
array descriptor was simply incorrect after the first dimension.

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

Added: 
    

Modified: 
    flang/runtime/namelist.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/namelist.cpp b/flang/runtime/namelist.cpp
index c2c3d6537984..03fddd61f24d 100644
--- a/flang/runtime/namelist.cpp
+++ b/flang/runtime/namelist.cpp
@@ -10,6 +10,7 @@
 #include "descriptor-io.h"
 #include "io-stmt.h"
 #include "flang/Runtime/io-api.h"
+#include <algorithm>
 #include <cstring>
 #include <limits>
 
@@ -133,7 +134,7 @@ static bool HandleSubscripts(IoStatementState &io, Descriptor &desc,
   // ambiguous within the parentheses.
   SubscriptValue lower[maxRank], upper[maxRank], stride[maxRank];
   int j{0};
-  std::size_t elemLen{source.ElementBytes()};
+  std::size_t contiguousStride{source.ElementBytes()};
   bool ok{true};
   std::optional<char32_t> ch{io.GetNextNonBlank()};
   for (; ch && *ch != ')'; ++j) {
@@ -142,7 +143,9 @@ static bool HandleSubscripts(IoStatementState &io, Descriptor &desc,
       const Dimension &dim{source.GetDimension(j)};
       dimLower = dim.LowerBound();
       dimUpper = dim.UpperBound();
-      dimStride = elemLen ? dim.ByteStride() / elemLen : 1;
+      dimStride =
+          dim.ByteStride() / std::max<SubscriptValue>(contiguousStride, 1);
+      contiguousStride *= dim.Extent();
     } else if (ok) {
       handler.SignalError(
           "Too many subscripts for rank-%d NAMELIST group item '%s'",


        


More information about the flang-commits mailing list