Skip to content

Commit

Permalink
[flang] Fix crash in semantics on error case (llvm#91482)
Browse files Browse the repository at this point in the history
An erroneous statement function declaration exposed an unhandled
situation in a utility routine in semantics. Patch that hole and add a
test.

Fixes llvm#91429.
  • Loading branch information
klausler authored May 9, 2024
1 parent 19b41f4 commit a51d92a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 8 additions & 6 deletions flang/lib/Semantics/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions flang/test/Semantics/stmt-func01.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a51d92a

Please sign in to comment.