Skip to content

Commit 8305a92

Browse files
committed
[flang] Treat tabs like spaces in formatted input.
Reviewed By: sscalpone Differential Revision: https://reviews.llvm.org/D84078
1 parent 8e2b4e5 commit 8305a92

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

flang/runtime/edit-input.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static bool EditBOZInput(IoStatementState &io, const DataEdit &edit, void *n,
3434
common::UnsignedInt128 value{0};
3535
for (; next; next = io.NextInField(remaining)) {
3636
char32_t ch{*next};
37-
if (ch == ' ') {
37+
if (ch == ' ' || ch == '\t') {
3838
continue;
3939
}
4040
int digit{0};
@@ -101,7 +101,7 @@ bool EditIntegerInput(
101101
common::UnsignedInt128 value;
102102
for (; next; next = io.NextInField(remaining)) {
103103
char32_t ch{*next};
104-
if (ch == ' ') {
104+
if (ch == ' ' || ch == '\t') {
105105
if (edit.modes.editingFlags & blankZero) {
106106
ch = '0'; // BZ mode - treat blank as if it were zero
107107
} else {
@@ -170,7 +170,7 @@ static int ScanRealInput(char *buffer, int bufferSize, IoStatementState &io,
170170
} else if (*next == decimal || (*next >= '0' && *next <= '9')) {
171171
for (; next; next = io.NextInField(remaining)) {
172172
char32_t ch{*next};
173-
if (ch == ' ') {
173+
if (ch == ' ' || ch == '\t') {
174174
if (edit.modes.editingFlags & blankZero) {
175175
ch = '0'; // BZ mode - treat blank as if it were zero
176176
} else {
@@ -229,7 +229,7 @@ static int ScanRealInput(char *buffer, int bufferSize, IoStatementState &io,
229229
return 0;
230230
}
231231
if (remaining) {
232-
while (next && *next == ' ') {
232+
while (next && (*next == ' ' || *next == '\t')) {
233233
next = io.NextInField(remaining);
234234
}
235235
if (next) {
@@ -386,6 +386,7 @@ static bool EditListDirectedDefaultCharacterInput(
386386
next = io.NextInField(remaining)) {
387387
switch (*next) {
388388
case ' ':
389+
case '\t':
389390
case ',':
390391
case ';':
391392
case '/':

flang/runtime/io-stmt.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ std::optional<char32_t> IoStatementState::SkipSpaces(
353353
std::optional<int> &remaining) {
354354
while (!remaining || *remaining > 0) {
355355
if (auto ch{GetCurrentChar()}) {
356-
if (*ch != ' ') {
356+
if (*ch != ' ' && *ch != '\t') {
357357
return ch;
358358
}
359359
HandleRelativePosition(1);
@@ -373,6 +373,7 @@ std::optional<char32_t> IoStatementState::NextInField(
373373
if (auto next{GetCurrentChar()}) {
374374
switch (*next) {
375375
case ' ':
376+
case '\t':
376377
case ',':
377378
case ';':
378379
case '/':
@@ -415,7 +416,7 @@ std::optional<char32_t> IoStatementState::NextInField(
415416

416417
std::optional<char32_t> IoStatementState::GetNextNonBlank() {
417418
auto ch{GetCurrentChar()};
418-
while (ch.value_or(' ') == ' ') {
419+
while (!ch || *ch == ' ' || *ch == '\t') {
419420
if (ch) {
420421
HandleRelativePosition(1);
421422
} else if (!AdvanceRecord()) {
@@ -485,7 +486,8 @@ ListDirectedStatementState<Direction::Input>::GetNextDataEdit(
485486
if (!imaginaryPart_) {
486487
edit.repeat = std::min<int>(remaining_, maxRepeat);
487488
auto ch{io.GetNextNonBlank()};
488-
if (!ch || *ch == ' ' || *ch == comma) { // "r*" repeated null
489+
if (!ch || *ch == ' ' || *ch == '\t' || *ch == comma) {
490+
// "r*" repeated null
489491
edit.descriptor = DataEdit::ListDirectedNullValue;
490492
}
491493
}
@@ -554,7 +556,7 @@ ListDirectedStatementState<Direction::Input>::GetNextDataEdit(
554556
edit.descriptor = DataEdit::ListDirectedNullValue;
555557
return edit;
556558
}
557-
if (!ch || *ch == ' ' || *ch == comma) { // "r*" null
559+
if (!ch || *ch == ' ' || *ch == '\t' || *ch == comma) { // "r*" null
558560
edit.descriptor = DataEdit::ListDirectedNullValue;
559561
}
560562
edit.repeat = std::min<int>(r, maxRepeat);

0 commit comments

Comments
 (0)