[flang-commits] [flang] [flang][runtime] INQUIRE(UNIT=-666, EXIST=x) should be .FALSE. (PR #66239)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Sep 13 09:51:26 PDT 2023


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

The runtime implementation for INQUIRE(EXIST=x) is returning .TRUE. for all non-existent unit, which is incorrect for valid unit numbers.

>From 26d63ad2879e8f79754fb7db6e3f181d0b637876 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 5 Sep 2023 09:22:51 -0700
Subject: [PATCH] [flang][runtime] INQUIRE(UNIT=-666, EXIST=x) should be
 .FALSE.

The runtime implementation for INQUIRE(EXIST=x) is returning
.TRUE. for all non-existent unit, which is incorrect for
valid unit numbers.
---
 flang/runtime/io-stmt.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/runtime/io-stmt.cpp b/flang/runtime/io-stmt.cpp
index 6ce66911292a708..1d951a4157d3199 100644
--- a/flang/runtime/io-stmt.cpp
+++ b/flang/runtime/io-stmt.cpp
@@ -1271,7 +1271,7 @@ bool InquireNoUnitState::Inquire(
 bool InquireNoUnitState::Inquire(InquiryKeywordHash inquiry, bool &result) {
   switch (inquiry) {
   case HashInquiryKeyword("EXIST"):
-    result = true;
+    result = badUnitNumber() >= 0;
     return true;
   case HashInquiryKeyword("NAMED"):
   case HashInquiryKeyword("OPENED"):



More information about the flang-commits mailing list