[flang-commits] [flang] 15faac9 - [flang] Distinguish intrinsic module USE in module files; correct search paths
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Fri Jun 3 22:07:57 PDT 2022
Author: Peter Klausler
Date: 2022-06-03T22:07:44-07:00
New Revision: 15faac900d3b4fc17a04b3b9de421fab1bbe33db
URL: https://github.com/llvm/llvm-project/commit/15faac900d3b4fc17a04b3b9de421fab1bbe33db
DIFF: https://github.com/llvm/llvm-project/commit/15faac900d3b4fc17a04b3b9de421fab1bbe33db.diff
LOG: [flang] Distinguish intrinsic module USE in module files; correct search paths
In the USE statements that f18 emits to module files, ensure that symbols
from intrinsic modules are marked as such on their USE statements. And
ensure that the current working directory (".") cannot override the intrinsic
module search path when trying to locate an intrinsic module.
Differential Revision: https://reviews.llvm.org/D127019
Added:
Modified:
flang/lib/Parser/parsing.cpp
flang/lib/Semantics/mod-file.cpp
flang/test/Semantics/modfile36.f90
Removed:
################################################################################
diff --git a/flang/lib/Parser/parsing.cpp b/flang/lib/Parser/parsing.cpp
index 6b0119008dbf4..3ea14e934b178 100644
--- a/flang/lib/Parser/parsing.cpp
+++ b/flang/lib/Parser/parsing.cpp
@@ -35,9 +35,12 @@ const SourceFile *Parsing::Prescan(const std::string &path, Options options) {
const SourceFile *sourceFile;
if (path == "-") {
sourceFile = allSources.ReadStandardInput(fileError);
+ } else if (options.isModuleFile) {
+ // Don't mess with intrinsic module search path
+ sourceFile = allSources.Open(path, fileError);
} else {
- std::optional<std::string> currentDirectory{"."};
- sourceFile = allSources.Open(path, fileError, std::move(currentDirectory));
+ sourceFile =
+ allSources.Open(path, fileError, "."s /*prepend to search path*/);
}
if (!fileError.str().empty()) {
ProvenanceRange range{allSources.AddCompilerInsertion(path)};
diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp
index 2ba8918f88473..d97b81786e7fe 100644
--- a/flang/lib/Semantics/mod-file.cpp
+++ b/flang/lib/Semantics/mod-file.cpp
@@ -518,8 +518,14 @@ void ModFileWriter::PutGeneric(const Symbol &symbol) {
void ModFileWriter::PutUse(const Symbol &symbol) {
auto &details{symbol.get<UseDetails>()};
auto &use{details.symbol()};
- uses_ << "use " << GetUsedModule(details).name();
- PutGenericName(uses_ << ",only:", symbol);
+ const Symbol &module{GetUsedModule(details)};
+ if (use.owner().parent().IsIntrinsicModules()) {
+ uses_ << "use,intrinsic::";
+ } else {
+ uses_ << "use ";
+ }
+ uses_ << module.name() << ",only:";
+ PutGenericName(uses_, symbol);
// Can have intrinsic op with
diff erent local-name and use-name
// (e.g. `operator(<)` and `operator(.lt.)`) but rename is not allowed
if (!IsIntrinsicOp(symbol) && use.name() != symbol.name()) {
@@ -953,6 +959,7 @@ Scope *ModFileReader::Read(const SourceName &name,
std::remove(options.searchDirectories.begin(),
options.searchDirectories.end(), dir);
}
+ options.searchDirectories.insert(options.searchDirectories.begin(), "."s);
}
if (isIntrinsic.value_or(true)) {
for (const auto &dir : context_.intrinsicModuleDirectories()) {
diff --git a/flang/test/Semantics/modfile36.f90 b/flang/test/Semantics/modfile36.f90
index b8dff4ce59978..bcdd559ad318c 100644
--- a/flang/test/Semantics/modfile36.f90
+++ b/flang/test/Semantics/modfile36.f90
@@ -14,7 +14,7 @@ subroutine s(x)
!module m1
! interface
! subroutine s(x)
-! use iso_c_binding, only: c_ptr
+! use,intrinsic::iso_c_binding, only: c_ptr
! type(c_ptr) :: x
! end
! end interface
@@ -31,7 +31,7 @@ subroutine s(x)
end module
!Expect: m2.mod
!module m2
-! use iso_c_binding,only:c_ptr
+! use,intrinsic::iso_c_binding,only:c_ptr
! interface
! subroutine s(x)
! import::c_ptr
More information about the flang-commits
mailing list