Skip to content

Commit

Permalink
[flang] Fix a crash with IMPORT in BLOCK (issue 604)
Browse files Browse the repository at this point in the history
Only call scope.name() if the scope has a symbol (Block, Global,
Forall and ImpliedDo kind of scopes do not have a symbol).

Original-commit: flang-compiler/f18@81c6b67
Reviewed-on: flang-compiler/f18#634
Tree-same-pre-rewrite: false
  • Loading branch information
jeanPerier committed Aug 21, 2019
1 parent 5330ebb commit f2453c9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flang/lib/semantics/resolve-names.cc
Expand Up @@ -5297,7 +5297,7 @@ void ResolveNamesVisitor::CheckImports() {
// C8102: all entities in host must not be hidden
for (const auto &pair : scope.parent()) {
auto &name{pair.first};
if (name != scope.name()) {
if (!scope.GetSymbol() || name != scope.name()) {
CheckImport(*prevImportStmt_, name);
}
}
Expand Down
2 changes: 2 additions & 0 deletions flang/lib/semantics/scope.h
Expand Up @@ -89,6 +89,8 @@ class Scope {
const Symbol *GetSymbol() const;
const Scope *GetDerivedTypeParent() const;

// It is only safe to call name() for kind of scopes for which GetSymbol
// will return a symbol (e.g, it will die if the scope is a Block).
const SourceName &name() const { return DEREF(GetSymbol()).name(); }

/// Make a scope nested in this one
Expand Down
6 changes: 6 additions & 0 deletions flang/test/semantics/resolve28.f90
Expand Up @@ -58,6 +58,12 @@ function f
import, all
end

subroutine sub2()
block
import, all !OK
end block
end

!ERROR: IMPORT is not allowed in a main program scoping unit
import
end

0 comments on commit f2453c9

Please sign in to comment.