[flang-commits] [flang] [flang] Check definability for logical INQUIRE specifiers (PR #144797)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Jun 18 14:39:54 PDT 2025


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

check-io.cpp was missing checks for the definability of logical-valued specifiers in INQUIRE statements (e.g. EXIST=), and therefore also not noting the definitions of those variables.  This could lead to bogus warnings about undefined function result variables, and also to missed errors about immutable objects appearing in those specifiers.

Fixes https://github.com/llvm/llvm-project/issues/144453.

>From 9254496dbdcda9945ce8418cf5bcf67d0cd8650b Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Wed, 18 Jun 2025 14:36:41 -0700
Subject: [PATCH] [flang] Check definability for logical INQUIRE specifiers

check-io.cpp was missing checks for the definability of logical-valued
specifiers in INQUIRE statements (e.g. EXIST=), and therefore also
not noting the definitions of those variables.  This could lead to
bogus warnings about undefined function result variables, and also
to missed errors about immutable objects appearing in those specifiers.

Fixes https://github.com/llvm/llvm-project/issues/144453.
---
 flang/lib/Semantics/check-io.cpp   |  2 ++
 flang/test/Semantics/bug144453.f90 | 10 ++++++++++
 2 files changed, 12 insertions(+)
 create mode 100644 flang/test/Semantics/bug144453.f90

diff --git a/flang/lib/Semantics/check-io.cpp b/flang/lib/Semantics/check-io.cpp
index 10b32d9af0f88..a1ff4b922268b 100644
--- a/flang/lib/Semantics/check-io.cpp
+++ b/flang/lib/Semantics/check-io.cpp
@@ -478,6 +478,8 @@ void IoChecker::Enter(const parser::InquireSpec::LogVar &spec) {
     specKind = IoSpecKind::Pending;
     break;
   }
+  CheckForDefinableVariable(std::get<parser::ScalarLogicalVariable>(spec.t),
+      parser::ToUpperCaseLetters(common::EnumToString(specKind)));
   SetSpecifier(specKind);
 }
 
diff --git a/flang/test/Semantics/bug144453.f90 b/flang/test/Semantics/bug144453.f90
new file mode 100644
index 0000000000000..85c0892bffb5c
--- /dev/null
+++ b/flang/test/Semantics/bug144453.f90
@@ -0,0 +1,10 @@
+!RUN: %python %S/test_errors.py %s %flang_fc1
+function func(immutable)
+  logical func
+  logical, intent(in) :: immutable
+  !No warning about an undefined function result should appear
+  INQUIRE(file="/usr/local/games/adventure", EXIST=func)
+  !ERROR: EXIST variable 'immutable' is not definable
+  !BECAUSE: 'immutable' is an INTENT(IN) dummy argument
+  INQUIRE(file="/usr/local/games/adventure", EXIST=immutable)
+end



More information about the flang-commits mailing list