aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Semantics/mod-file.cpp
diff options
context:
space:
mode:
authorPeter Klausler <35819229+klausler@users.noreply.github.com>2023-10-16 14:15:40 -0700
committerGitHub <noreply@github.com>2023-10-16 14:15:40 -0700
commite200b0e4a7b5447052698397939c80ee3b0ebda9 (patch)
tree3121b33ba5257e9c391b19a4b4343fc25a791743 /flang/lib/Semantics/mod-file.cpp
parentea7e50cdf2f531d323a564590a22c7bb6e11aa3a (diff)
downloadllvm-e200b0e4a7b5447052698397939c80ee3b0ebda9.zip
llvm-e200b0e4a7b5447052698397939c80ee3b0ebda9.tar.gz
llvm-e200b0e4a7b5447052698397939c80ee3b0ebda9.tar.bz2
[flang] Submodule names can clash only with submodule names (#67361)
Name resolution creates symbols for submodules in their parents' scopes. This can lead to bogus errors about name clashes between submodule names and other entities in the parents' scopes. Create symbols for submodules but do not add them to a scope's dictionary.
Diffstat (limited to 'flang/lib/Semantics/mod-file.cpp')
-rw-r--r--flang/lib/Semantics/mod-file.cpp43
1 files changed, 31 insertions, 12 deletions
diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp
index cee267a..8684eb1fb 100644
--- a/flang/lib/Semantics/mod-file.cpp
+++ b/flang/lib/Semantics/mod-file.cpp
@@ -1183,30 +1183,49 @@ Scope *ModFileReader::Read(const SourceName &name,
}
Scope &topScope{isIntrinsic.value_or(false) ? context_.intrinsicModulesScope()
: context_.globalScope()};
- if (!ancestor) {
+ Symbol *moduleSymbol{nullptr};
+ if (!ancestor) { // module, not submodule
parentScope = &topScope;
+ auto pair{parentScope->try_emplace(name, UnknownDetails{})};
+ if (!pair.second) {
+ return nullptr;
+ }
+ moduleSymbol = &*pair.first->second;
+ moduleSymbol->set(Symbol::Flag::ModFile);
} else if (std::optional<SourceName> parent{GetSubmoduleParent(parseTree)}) {
+ // submodule with submodule parent
parentScope = Read(*parent, false /*not intrinsic*/, ancestor, silent);
} else {
+ // submodule with module parent
parentScope = ancestor;
}
- auto pair{parentScope->try_emplace(name, UnknownDetails{})};
- if (!pair.second) {
- return nullptr;
- }
// Process declarations from the module file
- Symbol &modSymbol{*pair.first->second};
- modSymbol.set(Symbol::Flag::ModFile);
bool wasInModuleFile{context_.foldingContext().inModuleFile()};
context_.foldingContext().set_inModuleFile(true);
ResolveNames(context_, parseTree, topScope);
context_.foldingContext().set_inModuleFile(wasInModuleFile);
- CHECK(modSymbol.has<ModuleDetails>());
- CHECK(modSymbol.test(Symbol::Flag::ModFile));
- if (isIntrinsic.value_or(false)) {
- modSymbol.attrs().set(Attr::INTRINSIC);
+ if (!moduleSymbol) {
+ // Submodule symbols' storage are owned by their parents' scopes,
+ // but their names are not in their parents' dictionaries -- we
+ // don't want to report bogus errors about clashes between submodule
+ // names and other objects in the parent scopes.
+ if (Scope * submoduleScope{ancestor->FindSubmodule(name)}) {
+ moduleSymbol = submoduleScope->symbol();
+ if (moduleSymbol) {
+ moduleSymbol->set(Symbol::Flag::ModFile);
+ }
+ }
+ }
+ if (moduleSymbol) {
+ CHECK(moduleSymbol->has<ModuleDetails>());
+ CHECK(moduleSymbol->test(Symbol::Flag::ModFile));
+ if (isIntrinsic.value_or(false)) {
+ moduleSymbol->attrs().set(Attr::INTRINSIC);
+ }
+ return moduleSymbol->scope();
+ } else {
+ return nullptr;
}
- return modSymbol.scope();
}
parser::Message &ModFileReader::Say(const SourceName &name,