Skip to content

[flang] Fix crash in semantics on error case #91482

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

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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