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

Conversation

klausler
Copy link
Contributor

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.

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 llvm#110261.
@klausler klausler requested a review from vdonaldson September 27, 2024 19:05
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Sep 27, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 27, 2024

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/110314.diff

2 Files Affected:

  • (modified) flang/include/flang/Common/format.h (+6-4)
  • (modified) flang/test/Semantics/io07.f90 (+9-2)
diff --git a/flang/include/flang/Common/format.h b/flang/include/flang/Common/format.h
index 2374ff6983cf41..67d37bee32ab35 100644
--- a/flang/include/flang/Common/format.h
+++ b/flang/include/flang/Common/format.h
@@ -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
@@ -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_);
@@ -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");
@@ -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);
diff --git a/flang/test/Semantics/io07.f90 b/flang/test/Semantics/io07.f90
index 1c13c7df20a31c..64a32c9959287c 100644
--- a/flang/test/Semantics/io07.f90
+++ b/flang/test/Semantics/io07.f90
@@ -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
@@ -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
@@ -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
@@ -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)
 

@klausler klausler merged commit 9b3818e into llvm:main Sep 30, 2024
11 checks passed
@klausler klausler deleted the bug110261 branch September 30, 2024 19:38
Sterling-Augustine pushed a commit to Sterling-Augustine/llvm-project that referenced this pull request Oct 3, 2024
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 llvm#110261.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flang] Semantic error while compiling a fixed form file
3 participants