Skip to content

Commit 3738447

Browse files
committed
[flang] Address name resolution problems
Don't emit a bogus error message about a bad forward reference when it's an IMPORT of a USE-associated symbol; don't ignore intrinsic functions when USE-associating the contents of a module when the intrinsic has been explicitly USE'd; allow PUBLIC or PRIVATE accessibility attribute to be specified for an enumerator before the declaration of the enumerator. Differential Revision: https://reviews.llvm.org/D95175
1 parent 6e36046 commit 3738447

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,6 +2238,12 @@ std::optional<SourceName> ScopeHandler::HadForwardRef(
22382238
bool ScopeHandler::CheckPossibleBadForwardRef(const Symbol &symbol) {
22392239
if (!context().HasError(symbol)) {
22402240
if (auto fwdRef{HadForwardRef(symbol)}) {
2241+
const Symbol *outer{symbol.owner().FindSymbol(symbol.name())};
2242+
if (outer && symbol.has<UseDetails>() &&
2243+
&symbol.GetUltimate() == &outer->GetUltimate()) {
2244+
// e.g. IMPORT of host's USE association
2245+
return false;
2246+
}
22412247
Say(*fwdRef,
22422248
"Forward reference to '%s' is not allowed in the same specification part"_err_en_US,
22432249
*fwdRef)
@@ -2332,7 +2338,8 @@ void ModuleVisitor::Post(const parser::UseStmt &x) {
23322338
}
23332339
for (const auto &[name, symbol] : *useModuleScope_) {
23342340
if (symbol->attrs().test(Attr::PUBLIC) &&
2335-
!symbol->attrs().test(Attr::INTRINSIC) &&
2341+
(!symbol->attrs().test(Attr::INTRINSIC) ||
2342+
symbol->has<UseDetails>()) &&
23362343
!symbol->has<MiscDetails>() && useNames.count(name) == 0) {
23372344
SourceName location{x.moduleName.source};
23382345
if (auto *localSymbol{FindInScope(name)}) {
@@ -3310,10 +3317,11 @@ bool DeclarationVisitor::Pre(const parser::NamedConstant &x) {
33103317
bool DeclarationVisitor::Pre(const parser::Enumerator &enumerator) {
33113318
const parser::Name &name{std::get<parser::NamedConstant>(enumerator.t).v};
33123319
Symbol *symbol{FindSymbol(name)};
3313-
if (symbol) {
3320+
if (symbol && !symbol->has<UnknownDetails>()) {
33143321
// Contrary to named constants appearing in a PARAMETER statement,
33153322
// enumerator names should not have their type, dimension or any other
3316-
// attributes defined before they are declared in the enumerator statement.
3323+
// attributes defined before they are declared in the enumerator statement,
3324+
// with the exception of accessibility.
33173325
// This is not explicitly forbidden by the standard, but they are scalars
33183326
// which type is left for the compiler to chose, so do not let users try to
33193327
// tamper with that.

0 commit comments

Comments
 (0)