This is an archive of the discontinued LLVM Phabricator instance.

[flang] Handle undeclared names in EQUIVALENCE statements
ClosedPublic

Authored by PeteSteinfeld on Dec 15 2020, 2:53 PM.

Details

Summary

Names in EQUIVALENCE statements are only allowed to indicate local
objects as per 19.5.1.4, paragraph 2, item (10). Thus, a name appearing
in an EQUIVALENCE statement with no corresponding declaration in the
same scope is an implicit declaration of the name. If that scope
contains an IMPLICIT NONE, it's an error.

I implemented this by adding a state variable to the SemanticsContext to
indicate if we're resolving the names in an EQUIVALENCE statement and
then checked this state when resolving names. I also added a test to
the existing tests for EQUIVALENCE statements.

Diff Detail

Event Timeline

PeteSteinfeld requested review of this revision.Dec 15 2020, 2:53 PM
PeteSteinfeld created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 15 2020, 2:53 PM
PeteSteinfeld added a project: Restricted Project.Dec 15 2020, 2:53 PM
klausler requested changes to this revision.Dec 15 2020, 3:58 PM
klausler added inline comments.
flang/include/flang/Semantics/scope.h
133

This is really just a convenience wrapper for find(), yes? If so, then either it's redundant with find(), or you should find and replace other uses of find() with your new API and avoid the confusion that can arise with multiple interfaces that do much the same thing. (Preference is for the former, since usage of find() in scopes is pretty idiomatic by this point.)

flang/include/flang/Semantics/semantics.h
88

The SemanticsContext object is probably not the best place for this new state. One of the visitor classes in name resolution would make more sense.

This revision now requires changes to proceed.Dec 15 2020, 3:58 PM
tskeith added inline comments.Dec 15 2020, 4:22 PM
flang/lib/Semantics/resolve-names.cpp
2024

FindInScope(scope, name.source) does the same thing, so you don't need the new function. (Or replace FindInScope with FindLocalSymbol everywhere.)

4358

I think it makes more sense for inEquivalenceStmt_ to be recorded in ScopeHandler (like inExecutionPart_, for example). It doesn't really belong in SemanticsContext because it only applies to name resolution, not to the rest of semantic analysis.

Sorry, I didn't see Peter's comments until after I submitted mine.

PeteSteinfeld added inline comments.Dec 16 2020, 10:42 AM
flang/include/flang/Semantics/scope.h
133

Thanks, Peter. I plan to follow Tim's suggestion below and use the existing

FindInScope()
flang/include/flang/Semantics/semantics.h
88

Thanks. I'll make that change.

flang/lib/Semantics/resolve-names.cpp
2024

I didn't notice

FindInScope()
```.  I'll just use that.
4358

Thanks, Tim. Will do.

Responses to review comments. I moved the state variable indicating if we're
resolving names in an EQUIVALENCE statement to the class ScopeHandler and used
the existing FindInScope() function to limit name loopups to the current scope
rather than inventing a new interface.

klausler accepted this revision.Dec 16 2020, 10:48 AM
This revision is now accepted and ready to land.Dec 16 2020, 10:48 AM
tskeith accepted this revision.Dec 16 2020, 11:01 AM
This revision was landed with ongoing or failed builds.Dec 16 2020, 11:04 AM
This revision was automatically updated to reflect the committed changes.