[flang-commits] [flang] 35db91c - [flang] Catch empty nested parenthsized format item list (#183097)

via flang-commits flang-commits at lists.llvm.org
Thu Feb 26 07:04:00 PST 2026


Author: Peter Klausler
Date: 2026-02-26T07:03:48-08:00
New Revision: 35db91c0d8295b8cef3d27502a4354ff8f508075

URL: https://github.com/llvm/llvm-project/commit/35db91c0d8295b8cef3d27502a4354ff8f508075
DIFF: https://github.com/llvm/llvm-project/commit/35db91c0d8295b8cef3d27502a4354ff8f508075.diff

LOG: [flang] Catch empty nested parenthsized format item list (#183097)

While a completely empty format item list is meaningful -- it does
nothing when there are no data items -- an empty nested parenthesized
format item list is neither conforming nor useful, and will cause a
runtime error if it is interpreted as unlimited repetition. We
essentially catch these cases as parsing errors when they appear in a
FORMAT statement, but the format string checker used for character
constants is missing them.

Added: 
    

Modified: 
    flang/include/flang/Common/format.h
    flang/test/Semantics/io08.f90

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Common/format.h b/flang/include/flang/Common/format.h
index 1e64acb823616..1ddca2c706ede 100644
--- a/flang/include/flang/Common/format.h
+++ b/flang/include/flang/Common/format.h
@@ -909,6 +909,9 @@ template <typename CHAR> bool FormatValidator<CHAR>::Check() {
       if (++nestLevel > maxNesting_) {
         maxNesting_ = nestLevel;
       }
+      if (LookAheadChar() == ')') {
+        ReportError("Nested parenthesized format item list is empty");
+      }
       break;
     case TokenKind::RParen:
       if (knrValue_ >= 0) {

diff  --git a/flang/test/Semantics/io08.f90 b/flang/test/Semantics/io08.f90
index 517984fe3433d..4e99ee1279fe3 100644
--- a/flang/test/Semantics/io08.f90
+++ b/flang/test/Semantics/io08.f90
@@ -40,6 +40,7 @@
   write(*,'($)')
   write(*,'(\)')
   write(*,'(RZ,RU,RP,RN,RD,RC,SS,SP,S,3G15.3e2)')
+  write(*, "()")
   write(*, '(' // achar( 9) // ')') ! horizontal tab
   write(*, '(' // achar(11) // ')') ! vertical tab
   write(*, '(' // achar(32) // ')') ! space
@@ -320,4 +321,8 @@
 
   !ERROR: Negative scale factor k (from kP) and width d in a 'E' edit descriptor must satisfy '-d < k'
   write(*, '(-4P,E20.5,E15.2)')
+
+  !ERROR: Nested parenthesized format item list is empty
+  write(*, "(I6.3, ( ))")
+
 end


        


More information about the flang-commits mailing list