[flang] Check definability for logical INQUIRE specifiers (#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.
This commit is contained in:
Peter Klausler
2025-06-30 10:21:06 -07:00
committed by GitHub
parent dccc0266f4
commit 348002e111
2 changed files with 12 additions and 0 deletions

View File

@@ -478,6 +478,8 @@ void IoChecker::Enter(const parser::InquireSpec::LogVar &spec) {
specKind = IoSpecKind::Pending; specKind = IoSpecKind::Pending;
break; break;
} }
CheckForDefinableVariable(std::get<parser::ScalarLogicalVariable>(spec.t),
parser::ToUpperCaseLetters(common::EnumToString(specKind)));
SetSpecifier(specKind); SetSpecifier(specKind);
} }

View File

@@ -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