From 6110e7716cd0000fdeb2a7edfbec7c9991f1a08a Mon Sep 17 00:00:00 2001 From: peter klausler Date: Tue, 26 Jan 2021 13:57:44 -0800 Subject: [flang] Search for #include "file" in right directory (take 2) Make the #include "file" preprocessing directive begin its search in the same directory as the file containing the directive, as other preprocessors and our Fortran INCLUDE statement do. Avoid current working directory for all source files except the original. Resolve tests. Differential Revision: https://reviews.llvm.org/D95481 --- flang/lib/Parser/source.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'flang/lib/Parser/source.cpp') diff --git a/flang/lib/Parser/source.cpp b/flang/lib/Parser/source.cpp index 11cd591..3fbbf78 100644 --- a/flang/lib/Parser/source.cpp +++ b/flang/lib/Parser/source.cpp @@ -56,9 +56,9 @@ std::string DirectoryName(std::string path) { return pathBuf.str().str(); } -std::string LocateSourceFile( - std::string name, const std::vector &searchPath) { - if (name.empty() || name == "-" || llvm::sys::path::is_absolute(name)) { +std::optional LocateSourceFile( + std::string name, const std::list &searchPath) { + if (name == "-" || llvm::sys::path::is_absolute(name)) { return name; } for (const std::string &dir : searchPath) { @@ -70,7 +70,7 @@ std::string LocateSourceFile( return path.str().str(); } } - return name; + return std::nullopt; } std::size_t RemoveCarriageReturns(llvm::MutableArrayRef buf) { @@ -123,7 +123,6 @@ bool SourceFile::Open(std::string path, llvm::raw_ostream &error) { bool SourceFile::ReadStandardInput(llvm::raw_ostream &error) { Close(); path_ = "standard input"; - auto buf_or = llvm::MemoryBuffer::getSTDIN(); if (!buf_or) { auto err = buf_or.getError(); @@ -146,7 +145,6 @@ void SourceFile::ReadFile() { auto tmp_buf{llvm::WritableMemoryBuffer::getNewUninitMemBuffer( content().size() + 1)}; llvm::copy(content(), tmp_buf->getBufferStart()); - Close(); buf_ = std::move(tmp_buf); } buf_end_++; -- cgit v1.1