[flang-commits] [flang] [flang] Catch READ(... SIZE=) with NML= or FMT=* (PR #71235)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Nov 3 14:35:09 PDT 2023


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/71235

The SIZE= specifier may not appear on a list-directed or namelist READ statement.

>From a6a9327f9dc19ff0551a858557bf762e674acaf9 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Fri, 3 Nov 2023 14:32:54 -0700
Subject: [PATCH] [flang] Catch READ(... SIZE=) with NML= or FMT=*

The SIZE= specifier may not appear on a list-directed
or namelist READ statement.
---
 flang/lib/Semantics/check-io.cpp | 4 ++++
 flang/test/Semantics/io03.f90    | 5 +++++
 2 files changed, 9 insertions(+)

diff --git a/flang/lib/Semantics/check-io.cpp b/flang/lib/Semantics/check-io.cpp
index 314dee5a232226c..7a17023558ad213 100644
--- a/flang/lib/Semantics/check-io.cpp
+++ b/flang/lib/Semantics/check-io.cpp
@@ -793,6 +793,10 @@ void IoChecker::Leave(const parser::ReadStmt &readStmt) {
   CheckForProhibitedSpecifier(IoSpecKind::Delim); // C1212
   CheckForProhibitedSpecifier(IoSpecKind::Sign); // C1212
   CheckForProhibitedSpecifier(IoSpecKind::Rec, IoSpecKind::End); // C1220
+  CheckForProhibitedSpecifier(
+      IoSpecKind::Nml, IoSpecKind::Size); // F'2023 C1214
+  CheckForProhibitedSpecifier(
+      IoSpecKind::Size, flags_.test(Flag::StarFmt), "FMT=*"); // F'2023 C1214
   CheckForRequiredSpecifier(IoSpecKind::Eor,
       specifierSet_.test(IoSpecKind::Advance) && !flags_.test(Flag::AdvanceYes),
       "ADVANCE with value 'NO'"); // C1222 + 12.6.2.1p2
diff --git a/flang/test/Semantics/io03.f90 b/flang/test/Semantics/io03.f90
index a5adafd5f2f96c6..61f87f3594e8028 100644
--- a/flang/test/Semantics/io03.f90
+++ b/flang/test/Semantics/io03.f90
@@ -155,6 +155,11 @@
   !ERROR: If PAD appears, FMT or NML must also appear
   read(10, pad='no', round='nearest') jj
 
+  !ERROR: If NML appears, SIZE must not appear
+  read(10, nml=nnn, size=kk)
+  !ERROR: If SIZE appears, FMT=* must not appear
+  read(10, *, size=kk) jj
+
   !ERROR: ID kind (2) is smaller than default INTEGER kind (4)
   read(10, id=id2, asynchronous='yes') jj
 



More information about the flang-commits mailing list