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 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)}; 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()}; 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/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