Skip to content

[flang] Downgrade specific format error to warning #110314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions flang/include/flang/Common/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ template <typename CHAR = char> class FormatValidator {

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

previousTokenKind_ = token_.kind();
previousToken_ = token_;
CHAR c{NextChar()};
token_.set_kind(TokenKind::None);
token_.set_offset(cursor_ - format_);
Expand Down Expand Up @@ -431,7 +431,7 @@ template <typename CHAR> void FormatValidator<CHAR>::NextToken() {
}
SetLength();
if (stmt_ == IoStmtKind::Read &&
previousTokenKind_ != TokenKind::DT) { // 13.3.2p6
previousToken_.kind() != TokenKind::DT) { // 13.3.2p6
ReportError("String edit descriptor in READ format expression");
} else if (token_.kind() != TokenKind::String) {
ReportError("Unterminated string");
Expand Down Expand Up @@ -887,8 +887,10 @@ template <typename CHAR> bool FormatValidator<CHAR>::Check() {
// Possible first token of the next format item; token not yet processed.
if (commaRequired) {
const char *s{"Expected ',' or ')' in format expression"}; // C1302
if (previousTokenKind_ == TokenKind::UnsignedInteger &&
if (previousToken_.kind() == TokenKind::UnsignedInteger &&
previousToken_.length() > 1 &&
itemsWithLeadingInts_.test(token_.kind())) {
// F10.32F10.3 is ambiguous, F10.3F10.3 is not
ReportError(s);
} else {
ReportWarning(s);
Expand Down
11 changes: 9 additions & 2 deletions flang/test/Semantics/io07.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
1001 format(A)

!ERROR: Format statement must be labeled
Expand All @@ -23,9 +23,13 @@
endif

! C1302 warnings; no errors
!WARNING: Expected ',' or ')' in format expression
2051 format(1X3/)
!WARNING: Expected ',' or ')' in format expression
2052 format(1X003/)
!WARNING: Expected ',' or ')' in format expression
2053 format(3P7I2)
!WARNING: Expected ',' or ')' in format expression
2054 format(3PI2)

!ERROR: Expected ',' or ')' in format expression
Expand All @@ -37,13 +41,14 @@
!ERROR: Expected ',' or ')' in format expression
2103 format(3I8 3Z8)

!ERROR: Expected ',' or ')' in format expression
!WARNING: Expected ',' or ')' in format expression
2104 format(3I8 Z8)

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

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

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

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

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

Expand Down
Loading