[flang-commits] [PATCH] D127019: [flang] Distinguish intrinsic module USE in module files; correct search paths

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Jun 3 15:50:19 PDT 2022


klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

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.


https://reviews.llvm.org/D127019

Files:
  flang/lib/Parser/parsing.cpp
  flang/lib/Semantics/mod-file.cpp
  flang/test/Semantics/modfile36.f90


Index: flang/test/Semantics/modfile36.f90
===================================================================
--- flang/test/Semantics/modfile36.f90
+++ flang/test/Semantics/modfile36.f90
@@ -14,7 +14,7 @@
 !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 @@
 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
Index: flang/lib/Semantics/mod-file.cpp
===================================================================
--- flang/lib/Semantics/mod-file.cpp
+++ flang/lib/Semantics/mod-file.cpp
@@ -518,8 +518,14 @@
 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 different 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 @@
       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()) {
Index: flang/lib/Parser/parsing.cpp
===================================================================
--- flang/lib/Parser/parsing.cpp
+++ flang/lib/Parser/parsing.cpp
@@ -35,9 +35,12 @@
   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)};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127019.434177.patch
Type: text/x-patch
Size: 2565 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220603/dd41e733/attachment.bin>


More information about the flang-commits mailing list