From e847b30369adffd5e90401918eb9efbd82b28607 Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Mon, 10 Jan 2022 12:04:30 -0800 Subject: [PATCH] [flang] runtime error on inappropriate OPEN(UNIT=extant,RECL=n) Don't let a program set a fixed RECL= on a connected unit unless it already had one with the same value. Differential Revision: https://reviews.llvm.org/D117595 --- flang/runtime/io-api.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp index 213fd5d..88a5c3b 100644 --- a/flang/runtime/io-api.cpp +++ b/flang/runtime/io-api.cpp @@ -826,13 +826,15 @@ bool IONAME(SetRecl)(Cookie cookie, std::size_t n) { } if (n <= 0) { io.GetIoErrorHandler().SignalError("RECL= must be greater than zero"); - } - if (open->wasExtant() && - open->unit().openRecl.value_or(n) != static_cast(n)) { + return false; + } else if (open->wasExtant() && + open->unit().openRecl.value_or(0) != static_cast(n)) { open->SignalError("RECL= may not be changed for an open unit"); + return false; + } else { + open->unit().openRecl = n; + return true; } - open->unit().openRecl = n; - return true; } bool IONAME(SetStatus)(Cookie cookie, const char *keyword, std::size_t length) { -- 2.7.4