Skip to content

[flang] Fix crash in error recovery (implicit host association) #92795

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 23, 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
2 changes: 1 addition & 1 deletion flang/include/flang/Semantics/scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class Scope {
ImportKind GetImportKind() const;
// Names appearing in IMPORT statements in this scope
std::set<SourceName> importNames() const { return importNames_; }
bool CanImport(const SourceName &) const;

// Set the kind of imports from host into this scope.
// Return an error message for incompatible kinds.
Expand Down Expand Up @@ -298,7 +299,6 @@ class Scope {
// or Symbol& points to one in there.
static Symbols<1024> allSymbols;

bool CanImport(const SourceName &) const;
const DeclTypeSpec &MakeLengthlessType(DeclTypeSpec &&);

friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Scope &);
Expand Down
45 changes: 24 additions & 21 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7846,28 +7846,31 @@ bool DeclarationVisitor::CheckForHostAssociatedImplicit(
if (name.symbol) {
ApplyImplicitRules(*name.symbol, true);
}
Symbol *hostSymbol;
Scope *host{GetHostProcedure()};
if (!host || isImplicitNoneType(*host)) {
return false;
}
if (!name.symbol) {
hostSymbol = &MakeSymbol(*host, name.source, Attrs{});
ConvertToObjectEntity(*hostSymbol);
ApplyImplicitRules(*hostSymbol);
hostSymbol->set(Symbol::Flag::ImplicitOrError);
} else if (name.symbol->test(Symbol::Flag::ImplicitOrError)) {
hostSymbol = name.symbol;
} else {
return false;
}
Symbol &symbol{MakeHostAssocSymbol(name, *hostSymbol)};
if (isImplicitNoneType()) {
symbol.get<HostAssocDetails>().implicitOrExplicitTypeError = true;
} else {
symbol.get<HostAssocDetails>().implicitOrSpecExprError = true;
if (Scope * host{GetHostProcedure()}; host && !isImplicitNoneType(*host)) {
Symbol *hostSymbol{nullptr};
if (!name.symbol) {
if (currScope().CanImport(name.source)) {
hostSymbol = &MakeSymbol(*host, name.source, Attrs{});
ConvertToObjectEntity(*hostSymbol);
ApplyImplicitRules(*hostSymbol);
hostSymbol->set(Symbol::Flag::ImplicitOrError);
}
} else if (name.symbol->test(Symbol::Flag::ImplicitOrError)) {
hostSymbol = name.symbol;
}
if (hostSymbol) {
Symbol &symbol{MakeHostAssocSymbol(name, *hostSymbol)};
if (auto *assoc{symbol.detailsIf<HostAssocDetails>()}) {
if (isImplicitNoneType()) {
assoc->implicitOrExplicitTypeError = true;
} else {
assoc->implicitOrSpecExprError = true;
}
return true;
}
}
}
return true;
return false;
}

bool DeclarationVisitor::IsUplevelReference(const Symbol &symbol) {
Expand Down
14 changes: 14 additions & 0 deletions flang/test/Semantics/procinterface05.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
interface a1
subroutine s1
interface a2
subroutine s2
!ERROR: Invalid specification expression: reference to local entity 'k'
real x(k)
end subroutine
end interface
!ERROR: Invalid specification expression: reference to local entity 'k'
real y(k)
end subroutine
end interface
end
Loading