[flang-commits] [flang] [flang] Enforce F2018 C1221: ADVANCE and REC specifiers are mutually exclusive (PR #195170)
via flang-commits
flang-commits at lists.llvm.org
Thu May 14 11:09:52 PDT 2026
https://github.com/kwyatt-ext updated https://github.com/llvm/llvm-project/pull/195170
>From 8e1d357c9978ddfa2fc41cb874193fc4b7c706d0 Mon Sep 17 00:00:00 2001
From: Kevin Wyatt <kwyatt at hpe.com>
Date: Thu, 30 Apr 2026 14:35:42 -0500
Subject: [PATCH 1/2] Enforce F2018 C1221: ADVANCE and REC specifiers are
mutually exclusive
---
flang/lib/Semantics/check-io.cpp | 1 +
flang/test/Semantics/io-advance-rec.f90 | 13 +++++++++++++
2 files changed, 14 insertions(+)
create mode 100644 flang/test/Semantics/io-advance-rec.f90
diff --git a/flang/lib/Semantics/check-io.cpp b/flang/lib/Semantics/check-io.cpp
index 46abd3d298d02..ace28f170b987 100644
--- a/flang/lib/Semantics/check-io.cpp
+++ b/flang/lib/Semantics/check-io.cpp
@@ -924,6 +924,7 @@ void IoChecker::LeaveReadWrite() const {
"an explicit format"); // C1221
CheckForProhibitedSpecifier(IoSpecKind::Advance,
flags_.test(Flag::InternalUnit), "UNIT=internal-file"); // C1221
+ CheckForProhibitedSpecifier(IoSpecKind::Advance, IoSpecKind::Rec); // C1221
CheckForRequiredSpecifier(flags_.test(Flag::AsynchronousYes),
"ASYNCHRONOUS='YES'", flags_.test(Flag::NumberUnit),
"UNIT=number"); // C1224
diff --git a/flang/test/Semantics/io-advance-rec.f90 b/flang/test/Semantics/io-advance-rec.f90
new file mode 100644
index 0000000000000..ff5761ac93162
--- /dev/null
+++ b/flang/test/Semantics/io-advance-rec.f90
@@ -0,0 +1,13 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+program io_advance_rec
+ implicit none
+ integer :: arr(10)
+
+ open(10, file="dummy.dat", access='direct', recl=80)
+ !ERROR: If ADVANCE appears, REC must not appear
+ read(10, '(I1)', advance="no", rec=1, err=100) arr(1)
+
+100 continue
+
+ close(10)
+end program
\ No newline at end of file
>From 995a07fed9aa67122f4cf573fc54ad64db82e9de Mon Sep 17 00:00:00 2001
From: Kevin Wyatt <kwyatt at hpe.com>
Date: Thu, 14 May 2026 13:09:39 -0500
Subject: [PATCH 2/2] Incorporated test cases into existing tests.
---
flang/test/Semantics/io03.f90 | 3 +++
flang/test/Semantics/io04.f90 | 3 +++
2 files changed, 6 insertions(+)
diff --git a/flang/test/Semantics/io03.f90 b/flang/test/Semantics/io03.f90
index 3841735ebff95..f01331e749c5e 100644
--- a/flang/test/Semantics/io03.f90
+++ b/flang/test/Semantics/io03.f90
@@ -129,6 +129,9 @@
!ERROR: If ADVANCE appears, UNIT=internal-file must not appear
read(internal_file, '(I4)', eor=9, advance='no') jj
+ !ERROR: If ADVANCE appears, REC must not appear
+ read(10, '(I4)', advance='no', rec=13) jj
+
!ERROR: If ADVANCE appears, an explicit format must also appear
!ERROR: If EOR appears, ADVANCE with value 'NO' must also appear
read(10, eor=9, advance='yes')
diff --git a/flang/test/Semantics/io04.f90 b/flang/test/Semantics/io04.f90
index 1ad2c71a9f948..59c03f585bc11 100644
--- a/flang/test/Semantics/io04.f90
+++ b/flang/test/Semantics/io04.f90
@@ -99,6 +99,9 @@
!ERROR: If ADVANCE appears, UNIT=internal-file must not appear
write(internal_file, advance='yes', fmt=1) 'Ok'
+ !ERROR: If ADVANCE appears, REC must not appear
+ write(10, '(A)', advance='no', rec=13) 'Ok'
+
!ERROR: If ADVANCE appears, an explicit format must also appear
write(10, advance='yes') 'Ok'
More information about the flang-commits
mailing list