Skip to content

Commit 89a927c

Browse files
committed
[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
1 parent f6aac0d commit 89a927c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

flang/runtime/namelist.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "descriptor-io.h"
1111
#include "io-stmt.h"
1212
#include "flang/Runtime/io-api.h"
13+
#include <algorithm>
1314
#include <cstring>
1415
#include <limits>
1516

@@ -133,7 +134,7 @@ static bool HandleSubscripts(IoStatementState &io, Descriptor &desc,
133134
// ambiguous within the parentheses.
134135
SubscriptValue lower[maxRank], upper[maxRank], stride[maxRank];
135136
int j{0};
136-
std::size_t elemLen{source.ElementBytes()};
137+
std::size_t contiguousStride{source.ElementBytes()};
137138
bool ok{true};
138139
std::optional<char32_t> ch{io.GetNextNonBlank()};
139140
for (; ch && *ch != ')'; ++j) {
@@ -142,7 +143,9 @@ static bool HandleSubscripts(IoStatementState &io, Descriptor &desc,
142143
const Dimension &dim{source.GetDimension(j)};
143144
dimLower = dim.LowerBound();
144145
dimUpper = dim.UpperBound();
145-
dimStride = elemLen ? dim.ByteStride() / elemLen : 1;
146+
dimStride =
147+
dim.ByteStride() / std::max<SubscriptValue>(contiguousStride, 1);
148+
contiguousStride *= dim.Extent();
146149
} else if (ok) {
147150
handler.SignalError(
148151
"Too many subscripts for rank-%d NAMELIST group item '%s'",

0 commit comments

Comments
 (0)