Skip to content

[flang] Compile the output of -fdebug-unparse-with-modules #135696

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
Apr 18, 2025
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
9 changes: 8 additions & 1 deletion flang/docs/ModFiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ Entities that have been included in a module by means of USE association
are represented in the module file with `USE` statements.
Name aliases are sometimes necessary when an entity from another
module is needed for a declaration and conflicts with another
entity of the same name.
entity of the same name, or is `PRIVATE`.
These aliases have currency symbols (`$`) in them.
When a module
is parsed from a module file, no error is emitted for associating
such an alias with a `PRIVATE` name.
A module parsed from another source file that is not a module file
(notably, the output of the `-fdebug-unparse-with-modules` option)
will emit only warnings.

## Reading and writing module files

Expand Down
16 changes: 13 additions & 3 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3325,9 +3325,19 @@ ModuleVisitor::SymbolRename ModuleVisitor::AddUse(
// Privacy is not enforced in module files so that generic interfaces
// can be resolved to private specific procedures in specification
// expressions.
Say(useName, "'%s' is PRIVATE in '%s'"_err_en_US, MakeOpName(useName),
useModuleScope_->GetName().value());
return {};
// Local names that contain currency symbols ('$') are created by the
// module file writer when a private name in another module is needed to
// process a local declaration. These can show up in the output of
// -fdebug-unparse-with-modules, too, so go easy on them.
if (currScope().IsModule() &&
localName.ToString().find("$") != std::string::npos) {
Say(useName, "'%s' is PRIVATE in '%s'"_warn_en_US, MakeOpName(useName),
useModuleScope_->GetName().value());
} else {
Say(useName, "'%s' is PRIVATE in '%s'"_err_en_US, MakeOpName(useName),
useModuleScope_->GetName().value());
return {};
}
}
auto &localSymbol{MakeSymbol(localName)};
DoAddUse(useName, localName, localSymbol, *useSymbol);
Expand Down
14 changes: 14 additions & 0 deletions flang/test/Semantics/resolve11.f90
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,17 @@ subroutine s5
use m5, only: foo, fun
print *, fun() ! ok
end

module m6
!WARNING: 'foo' is PRIVATE in 'm5'
use m5, only: name$with$dollar => foo
!ERROR: 'foo' is PRIVATE in 'm5'
use m5, only: normal_name => foo
end

subroutine s6
!The special dispensation for USE association of private names to local
!aliases with '$' in them only applies to modules.
!ERROR: 'foo' is PRIVATE in 'm5'
use m5, only: name$with$dollar => foo
end
Loading