Skip to content

Commit 9b3818e

Browse files
authored
[flang] Downgrade specific format error to warning (#110314)
When a format is missing a comma between two edit descriptors, the previous token was an integer, and the following item is a repeatable edit descriptor or a parenthesized group, we emit an error, since it can't be known where the digits of the integer should be split. But in the case of a single digit, the situation is not ambiguous, and the message should be a warning. Fixes #110261.
1 parent 1759f3b commit 9b3818e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

flang/include/flang/Common/format.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ template <typename CHAR = char> class FormatValidator {
136136

137137
const CHAR *cursor_{}; // current location in format_
138138
const CHAR *laCursor_{}; // lookahead cursor
139-
TokenKind previousTokenKind_{TokenKind::None};
139+
Token previousToken_{};
140140
Token token_{}; // current token
141141
Token knrToken_{}; // k, n, or r UnsignedInteger token
142142
Token scaleFactorToken_{}; // most recent scale factor token P
@@ -193,7 +193,7 @@ template <typename CHAR> void FormatValidator<CHAR>::NextToken() {
193193
// At entry, cursor_ points before the start of the next token.
194194
// At exit, cursor_ points to last CHAR of token_.
195195

196-
previousTokenKind_ = token_.kind();
196+
previousToken_ = token_;
197197
CHAR c{NextChar()};
198198
token_.set_kind(TokenKind::None);
199199
token_.set_offset(cursor_ - format_);
@@ -431,7 +431,7 @@ template <typename CHAR> void FormatValidator<CHAR>::NextToken() {
431431
}
432432
SetLength();
433433
if (stmt_ == IoStmtKind::Read &&
434-
previousTokenKind_ != TokenKind::DT) { // 13.3.2p6
434+
previousToken_.kind() != TokenKind::DT) { // 13.3.2p6
435435
ReportError("String edit descriptor in READ format expression");
436436
} else if (token_.kind() != TokenKind::String) {
437437
ReportError("Unterminated string");
@@ -887,8 +887,10 @@ template <typename CHAR> bool FormatValidator<CHAR>::Check() {
887887
// Possible first token of the next format item; token not yet processed.
888888
if (commaRequired) {
889889
const char *s{"Expected ',' or ')' in format expression"}; // C1302
890-
if (previousTokenKind_ == TokenKind::UnsignedInteger &&
890+
if (previousToken_.kind() == TokenKind::UnsignedInteger &&
891+
previousToken_.length() > 1 &&
891892
itemsWithLeadingInts_.test(token_.kind())) {
893+
// F10.32F10.3 is ambiguous, F10.3F10.3 is not
892894
ReportError(s);
893895
} else {
894896
ReportWarning(s);

flang/test/Semantics/io07.f90

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
! RUN: %python %S/test_errors.py %s %flang_fc1
1+
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
22
1001 format(A)
33

44
!ERROR: Format statement must be labeled
@@ -23,9 +23,13 @@
2323
endif
2424

2525
! C1302 warnings; no errors
26+
!WARNING: Expected ',' or ')' in format expression
2627
2051 format(1X3/)
28+
!WARNING: Expected ',' or ')' in format expression
2729
2052 format(1X003/)
30+
!WARNING: Expected ',' or ')' in format expression
2831
2053 format(3P7I2)
32+
!WARNING: Expected ',' or ')' in format expression
2933
2054 format(3PI2)
3034

3135
!ERROR: Expected ',' or ')' in format expression
@@ -37,13 +41,14 @@
3741
!ERROR: Expected ',' or ')' in format expression
3842
2103 format(3I8 3Z8)
3943

40-
!ERROR: Expected ',' or ')' in format expression
44+
!WARNING: Expected ',' or ')' in format expression
4145
2104 format(3I8 Z8)
4246

4347
3001 format(*(I3))
4448
3002 format(5X,*(2(A)))
4549

4650
!ERROR: Unlimited format item list must contain a data edit descriptor
51+
!WARNING: 'X' edit descriptor must have a positive position value
4752
3101 format(*(X))
4853

4954
!ERROR: Unlimited format item list must contain a data edit descriptor
@@ -52,9 +57,11 @@
5257
!ERROR: Unlimited format item list must contain a data edit descriptor
5358
3103 format(5X, 'abc', *((:)))
5459

60+
!WARNING: 'X' edit descriptor must have a positive position value
5561
4001 format(2(X))
5662

5763
!ERROR: List repeat specifier must be positive
64+
!WARNING: 'X' edit descriptor must have a positive position value
5865
!ERROR: 'DT' edit descriptor repeat specifier must be positive
5966
4101 format(0(X), 0dt)
6067

0 commit comments

Comments
 (0)