[flang-commits] [flang] [flang][runtime] Allow OPEN(, RECL=) on open unit with no RECL= (PR #107718)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Sat Sep 7 13:30:32 PDT 2024


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

Most Fortran implementations allow an OPEN(,RECL=n) statement to impose a record length on an already-opened unit that was opened with no RECL=, typically OPEN(6,RECL=<big number>) to avoid automatic line-wrapping of output.  We emit an unconditional error if the unit was already open, as must be the case for preconnected unit 6. Make the error conditional on RECL= simply not having been already set.

>From ac787470a4c9eb8e1fff918a6d4444cb4308382c Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Sat, 7 Sep 2024 13:27:02 -0700
Subject: [PATCH] [flang][runtime] Allow OPEN(,RECL=) on open unit with no
 RECL=

Most Fortran implementations allow an OPEN(,RECL=n) statement to
impose a record length on an already-opened unit that was opened
with no RECL=, typically OPEN(6,RECL=<big number>) to avoid automatic
line-wrapping of output.  We emit an unconditional error if the
unit was already open, as must be the case for preconnected unit 6.
Make the error conditional on RECL= simply not having been already
set.
---
 flang/runtime/io-api.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp
index e3c6b9e5ca8959..5b353d24816915 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang/runtime/io-api.cpp
@@ -952,7 +952,7 @@ bool IODEF(SetRecl)(Cookie cookie, std::size_t n) {
     io.GetIoErrorHandler().SignalError("RECL= must be greater than zero");
     return false;
   } else if (open->wasExtant() &&
-      open->unit().openRecl.value_or(0) != static_cast<std::int64_t>(n)) {
+      open->unit().openRecl.value_or(n) != static_cast<std::int64_t>(n)) {
     open->SignalError("RECL= may not be changed for an open unit");
     return false;
   } else {



More information about the flang-commits mailing list