[flang-commits] [flang] a51d92a - [flang] Fix crash in semantics on error case (#91482)
via flang-commits
flang-commits at lists.llvm.org
Thu May 9 11:42:29 PDT 2024
Author: Peter Klausler
Date: 2024-05-09T11:42:25-07:00
New Revision: a51d92a44740fd1b17930de183c9ad6d993029b1
URL: https://github.com/llvm/llvm-project/commit/a51d92a44740fd1b17930de183c9ad6d993029b1
DIFF: https://github.com/llvm/llvm-project/commit/a51d92a44740fd1b17930de183c9ad6d993029b1.diff
LOG: [flang] Fix crash in semantics on error case (#91482)
An erroneous statement function declaration exposed an unhandled
situation in a utility routine in semantics. Patch that hole and add a
test.
Fixes https://github.com/llvm/llvm-project/issues/91429.
Added:
Modified:
flang/lib/Semantics/tools.cpp
flang/test/Semantics/stmt-func01.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/tools.cpp b/flang/lib/Semantics/tools.cpp
index 2d0caff82eb2b..99381918fc638 100644
--- a/flang/lib/Semantics/tools.cpp
+++ b/flang/lib/Semantics/tools.cpp
@@ -256,15 +256,17 @@ static const Symbol &FollowHostAssoc(const Symbol &symbol) {
}
bool IsHostAssociated(const Symbol &symbol, const Scope &scope) {
- return DoesScopeContain(
- &GetProgramUnitOrBlockConstructContaining(FollowHostAssoc(symbol)),
- GetProgramUnitOrBlockConstructContaining(scope));
+ const Symbol &base{FollowHostAssoc(symbol)};
+ return base.owner().IsTopLevel() ||
+ DoesScopeContain(&GetProgramUnitOrBlockConstructContaining(base),
+ GetProgramUnitOrBlockConstructContaining(scope));
}
bool IsHostAssociatedIntoSubprogram(const Symbol &symbol, const Scope &scope) {
- return DoesScopeContain(
- &GetProgramUnitOrBlockConstructContaining(FollowHostAssoc(symbol)),
- GetProgramUnitContaining(scope));
+ const Symbol &base{FollowHostAssoc(symbol)};
+ return base.owner().IsTopLevel() ||
+ DoesScopeContain(&GetProgramUnitOrBlockConstructContaining(base),
+ GetProgramUnitContaining(scope));
}
bool IsInStmtFunction(const Symbol &symbol) {
diff --git a/flang/test/Semantics/stmt-func01.f90 b/flang/test/Semantics/stmt-func01.f90
index 733a7a56dfdb2..3c9ffa565900a 100644
--- a/flang/test/Semantics/stmt-func01.f90
+++ b/flang/test/Semantics/stmt-func01.f90
@@ -83,3 +83,11 @@ subroutine s4
!ERROR: VOLATILE attribute may apply only to a variable
sf(x) = 1.
end
+
+subroutine s5
+ !ERROR: Invalid specification expression: reference to impure function 'k'
+ real x(k())
+ !WARNING: Name 'k' from host scope should have a type declaration before its local statement function definition
+ !ERROR: 'k' is already declared in this scoping unit
+ k() = 0.0
+end
More information about the flang-commits
mailing list