Skip to content

Commit d02b318

Browse files
committed
[flang] Remove typo that affected complex namelist input
A recent patch to real/complex formatted input included what must have been an editing hiccup: "++ ++p" instead of "++p". This compiles, and it broke the consumption of the trailing ')' of a complex value in namelist input by skipping over the character. Extend existing test to cover this case. Differential Revision: https://reviews.llvm.org/D114297
1 parent 2f5d6a0 commit d02b318

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

flang/runtime/edit-input.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,15 @@ static bool TryFastPathRealInput(
303303
for (; p < limit && (*p == ' ' || *p == '\t'); ++p) {
304304
}
305305
if (edit.descriptor == DataEdit::ListDirectedImaginaryPart) {
306-
// Need a trailing ')'
306+
// Need to consume a trailing ')' and any white space after
307307
if (p >= limit || *p != ')') {
308308
return false;
309309
}
310-
for (++ ++p; p < limit && (*p == ' ' || *p == '\t'); ++p) {
310+
for (++p; p < limit && (*p == ' ' || *p == '\t'); ++p) {
311311
}
312312
}
313-
if (p < limit) {
314-
return false; // unconverted characters remain in field
313+
if (edit.width && p < str + *edit.width) {
314+
return false; // unconverted characters remain in fixed width field
315315
}
316316
// Success on the fast path!
317317
// TODO: raise converted.flags as exceptions?

flang/unittests/Runtime/NumericalFormatTest.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ TEST(IOApiTests, MultilineOutputTest) {
144144
}
145145

146146
TEST(IOApiTests, ListInputTest) {
147-
static const char input[]{",1*,(5.,6..)"};
147+
static const char input[]{",1*,(5.,6.),(7.0,8.0)"};
148148
auto cookie{IONAME(BeginInternalListInput)(input, sizeof input - 1)};
149149

150150
// Create real values for IO tests
151-
static constexpr int numRealValues{6};
151+
static constexpr int numRealValues{8};
152152
float z[numRealValues];
153153
for (int j{0}; j < numRealValues; ++j) {
154154
z[j] = -(j + 1);
@@ -166,7 +166,7 @@ TEST(IOApiTests, ListInputTest) {
166166
<< static_cast<int>(status);
167167

168168
// Ensure writing complex values from floats does not result in an error
169-
static constexpr int bufferSize{33};
169+
static constexpr int bufferSize{39};
170170
char output[bufferSize];
171171
output[bufferSize - 1] = '\0';
172172
cookie = IONAME(BeginInternalListOutput)(output, bufferSize - 1);
@@ -182,7 +182,8 @@ TEST(IOApiTests, ListInputTest) {
182182
<< static_cast<int>(status);
183183

184184
// Verify output buffer against expected value
185-
static const char expect[bufferSize]{" (-1.,-2.) (-3.,-4.) (5.,6.) "};
185+
static const char expect[bufferSize]{
186+
" (-1.,-2.) (-3.,-4.) (5.,6.) (7.,8.) "};
186187
ASSERT_EQ(std::strncmp(output, expect, bufferSize), 0)
187188
<< "Failed complex list-directed output, expected '" << expect
188189
<< "', but got '" << output << "'";

0 commit comments

Comments
 (0)