[flang-commits] [flang] [FLANG] Correctly handle bad AT descriptors in FORMAT statements (PR #194960)

via flang-commits flang-commits at lists.llvm.org
Thu Apr 30 04:56:59 PDT 2026


https://github.com/laoshd updated https://github.com/llvm/llvm-project/pull/194960

>From 25f067e7dc2dea042f9a8f004ff16a8b7f395ff6 Mon Sep 17 00:00:00 2001
From: Shandong Lao <shandong.lao at hpe.com>
Date: Wed, 29 Apr 2026 16:04:33 -0500
Subject: [PATCH 1/2] Fix #194237: correctly handle bad AT descriptors in
 FORMAT statements. Update tests to cover more situations.

---
 flang/include/flang/Common/format.h |  2 ++
 flang/lib/Parser/io-parsers.cpp     |  2 +-
 flang/test/Semantics/io19.f90       | 16 +++++++++++++++-
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/flang/include/flang/Common/format.h b/flang/include/flang/Common/format.h
index 4348177b5a042..48ef252c59713 100644
--- a/flang/include/flang/Common/format.h
+++ b/flang/include/flang/Common/format.h
@@ -735,6 +735,8 @@ template <typename CHAR> bool FormatValidator<CHAR>::Check() {
       }
       if (stmt_ == IoStmtKind::Read) {
         ReportError("'AT' edit descriptor must not be used for input");
+        suppressMessageCascade_ =
+            false; // reset to allow subsequent '.' check to also report
       }
       break;
     case TokenKind::B:
diff --git a/flang/lib/Parser/io-parsers.cpp b/flang/lib/Parser/io-parsers.cpp
index 60b3c4434896c..85d3f08d9ccc9 100644
--- a/flang/lib/Parser/io-parsers.cpp
+++ b/flang/lib/Parser/io-parsers.cpp
@@ -625,7 +625,7 @@ TYPE_PARSER(construct<format::IntrinsicTypeDataEditDesc>(
         mandatoryWidth, noInt, noInt) ||
     construct<format::IntrinsicTypeDataEditDesc>(
         "A " >> ("T " >> pure(format::IntrinsicTypeDataEditDesc::Kind::AT)),
-        noInt, noInt, noInt) ||
+        maybe(width), maybe("." >> digits), noInt) ||
     construct<format::IntrinsicTypeDataEditDesc>(
         "A " >> pure(format::IntrinsicTypeDataEditDesc::Kind::A), maybe(width),
         noInt, noInt) ||
diff --git a/flang/test/Semantics/io19.f90 b/flang/test/Semantics/io19.f90
index e62fcfce57924..650471245afdc 100644
--- a/flang/test/Semantics/io19.f90
+++ b/flang/test/Semantics/io19.f90
@@ -36,13 +36,27 @@
   !ERROR: Unexpected '.' in format expression
   write(*, '(AT10.2)') str
 
-  ! AT with width on input produces two independent errors.
+  ! AT with width on input produces two and three independent errors.
   !ERROR: 'AT' edit descriptor does not accept a width value
   !ERROR: 'AT' edit descriptor must not be used for input
   read(*, '(AT10)') str
+  !ERROR: 'AT' edit descriptor does not accept a width value
+  !ERROR: 'AT' edit descriptor must not be used for input
+  !ERROR: Unexpected '.' in format expression
+  read(*, '(AT10.2)') str
 
   ! FORMAT statements are standalone; the compiler cannot know if they will
   ! be used with READ or WRITE, so no compile-time error is expected here.
 2 format(AT)
   read(*,2) str
+
+  ! AT with width in FORMAT statements; report compiling error, but not
+  ! READ error.
+  !ERROR: 'AT' edit descriptor does not accept a width value
+3 format(AT10)
+  write(*,3) str
+  !ERROR: 'AT' edit descriptor does not accept a width value
+  !ERROR: Unexpected '.' in format expression
+4 format(AT10.2)
+  read(*,4) str
 end

>From 28992c23e6402f8aa48c5a32a91e2b5ef8891089 Mon Sep 17 00:00:00 2001
From: Shandong Lao <shandong.lao at hpe.com>
Date: Thu, 30 Apr 2026 06:56:36 -0500
Subject: [PATCH 2/2] Move comments to separate lines so that assignments stay
 in the same lines.

---
 flang/include/flang/Common/format.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/flang/include/flang/Common/format.h b/flang/include/flang/Common/format.h
index 48ef252c59713..8ecb0682536dd 100644
--- a/flang/include/flang/Common/format.h
+++ b/flang/include/flang/Common/format.h
@@ -730,13 +730,13 @@ template <typename CHAR> bool FormatValidator<CHAR>::Check() {
       if (token_.kind() == TokenKind::UnsignedInteger) {
         ReportError("'AT' edit descriptor does not accept a width value");
         NextToken();
-        suppressMessageCascade_ =
-            false; // reset to allow the Read check below to also report
+        // reset to allow the Read check below to also report
+        suppressMessageCascade_ = false;
       }
       if (stmt_ == IoStmtKind::Read) {
         ReportError("'AT' edit descriptor must not be used for input");
-        suppressMessageCascade_ =
-            false; // reset to allow subsequent '.' check to also report
+        // reset to allow subsequent '.' check to also report
+        suppressMessageCascade_ = false;
       }
       break;
     case TokenKind::B:



More information about the flang-commits mailing list