aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Parser/source.cpp
diff options
context:
space:
mode:
authorpeter klausler <pklausler@nvidia.com>2021-01-25 12:29:10 -0800
committerpeter klausler <pklausler@nvidia.com>2021-01-25 13:39:37 -0800
commitd987b61b1dce9948801ac37704477e7c257100b1 (patch)
tree6a8a54ab211362a19b5eb575034a05a2fb5789a7 /flang/lib/Parser/source.cpp
parentf50b8ee71faeb5056df7a950e7427f3047ff9987 (diff)
downloadllvm-d987b61b1dce9948801ac37704477e7c257100b1.zip
llvm-d987b61b1dce9948801ac37704477e7c257100b1.tar.gz
llvm-d987b61b1dce9948801ac37704477e7c257100b1.tar.bz2
[flang] Search for #include "file" in right directory
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 after the original. Differential Revision: https://reviews.llvm.org/D95388
Diffstat (limited to 'flang/lib/Parser/source.cpp')
-rw-r--r--flang/lib/Parser/source.cpp10
1 files changed, 4 insertions, 6 deletions
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<std::string> &searchPath) {
- if (name.empty() || name == "-" || llvm::sys::path::is_absolute(name)) {
+std::optional<std::string> LocateSourceFile(
+ std::string name, const std::list<std::string> &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<char> 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_++;