Skip to content

[flang] Check definability for logical INQUIRE specifiers #144797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

klausler
Copy link
Contributor

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 #144453.

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 llvm#144453.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Jun 18, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 18, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

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 #144453.


Full diff: https://github.com/llvm/llvm-project/pull/144797.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/check-io.cpp (+2)
  • (added) flang/test/Semantics/bug144453.f90 (+10)
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flang] pseudopositive warning to function result that is set, pseudonegative warning to subroutine INTENT(OUT) parameter that is not set
4 participants