summaryrefslogtreecommitdiff
path: root/flang/lib/Semantics/resolve-names.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'flang/lib/Semantics/resolve-names.cpp')
-rw-r--r--flang/lib/Semantics/resolve-names.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 57870a7ccce0..321f819e6b73 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -749,8 +749,6 @@ public:
}
private:
- // The default access spec for this module.
- Attr defaultAccess_{Attr::PUBLIC};
// The location of the last AccessStmt without access-ids, if any.
std::optional<SourceName> prevAccessStmt_;
// The scope of the module during a UseStmt
@@ -3119,7 +3117,6 @@ void ModuleVisitor::BeginModule(const parser::Name &name, bool isSubmodule) {
auto &details{symbol.get<ModuleDetails>()};
PushScope(Scope::Kind::Module, &symbol);
details.set_scope(&currScope());
- defaultAccess_ = Attr::PUBLIC;
prevAccessStmt_ = std::nullopt;
}
@@ -3142,10 +3139,15 @@ Scope *ModuleVisitor::FindModule(const parser::Name &name,
}
void ModuleVisitor::ApplyDefaultAccess() {
+ const auto *moduleDetails{
+ DEREF(currScope().symbol()).detailsIf<ModuleDetails>()};
+ CHECK(moduleDetails);
for (auto &pair : currScope()) {
- Symbol &symbol = *pair.second;
+ Symbol &symbol{*pair.second};
if (!symbol.attrs().HasAny({Attr::PUBLIC, Attr::PRIVATE})) {
- SetImplicitAttr(symbol, defaultAccess_);
+ SetImplicitAttr(symbol,
+ DEREF(moduleDetails).isDefaultPrivate() ? Attr::PRIVATE
+ : Attr::PUBLIC);
}
}
}
@@ -7319,7 +7321,8 @@ bool ModuleVisitor::Pre(const parser::AccessStmt &x) {
.Attach(*prevAccessStmt_, "Previous declaration"_en_US);
}
prevAccessStmt_ = currStmtSource();
- defaultAccess_ = accessAttr;
+ auto *moduleDetails{DEREF(currScope().symbol()).detailsIf<ModuleDetails>()};
+ DEREF(moduleDetails).set_isDefaultPrivate(accessAttr == Attr::PRIVATE);
} else {
for (const auto &accessId : accessIds) {
GenericSpecInfo info{accessId.v.value()};
@@ -8232,6 +8235,12 @@ void ResolveNamesVisitor::ResolveExecutionParts(const ProgramTree &node) {
Walk(*exec);
}
FinishNamelists();
+ if (node.IsModule()) {
+ // A second final pass to catch new symbols added from implicitly
+ // typed names in NAMELIST groups or the specification parts of
+ // module subprograms.
+ ApplyDefaultAccess();
+ }
PopScope(); // converts unclassified entities into objects
for (const auto &child : node.children()) {
ResolveExecutionParts(child);