diff --git a/flang/lib/Parser/source.cpp b/flang/lib/Parser/source.cpp --- a/flang/lib/Parser/source.cpp +++ b/flang/lib/Parser/source.cpp @@ -11,6 +11,7 @@ #include "flang/Parser/char-buffer.h" #include "llvm/Support/Errno.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -50,21 +51,23 @@ } std::string DirectoryName(std::string path) { - auto lastSlash{path.rfind("/")}; - return lastSlash == std::string::npos ? path : path.substr(0, lastSlash); + llvm::SmallString<128> pathBuf{path}; + llvm::sys::path::remove_filename(pathBuf); + return pathBuf.str().str(); } std::string LocateSourceFile( std::string name, const std::vector &searchPath) { - if (name.empty() || name == "-" || name[0] == '/') { + if (name.empty() || name == "-" || llvm::sys::path::is_absolute(name)) { return name; } for (const std::string &dir : searchPath) { - std::string path{dir + '/' + name}; + llvm::SmallString<128> path{dir}; + llvm::sys::path::append(path, name); bool isDir{false}; auto er = llvm::sys::fs::is_directory(path, isDir); if (!er && !isDir) { - return path; + return path.str().str(); } } return name; diff --git a/flang/test/Semantics/getsymbols02.f90 b/flang/test/Semantics/getsymbols02.f90 --- a/flang/test/Semantics/getsymbols02.f90 +++ b/flang/test/Semantics/getsymbols02.f90 @@ -10,5 +10,5 @@ ! RUN: %f18 -fparse-only %S/Inputs/getsymbols02-a.f90 ! RUN: %f18 -fparse-only %S/Inputs/getsymbols02-b.f90 ! RUN: %f18 -fget-symbols-sources -fparse-only %s 2>&1 | FileCheck %s -! CHECK: callget5: ./mm2b.mod, -! CHECK: get5: ./mm2a.mod, +! CHECK: callget5: .{{[/\\]}}mm2b.mod, +! CHECK: get5: .{{[/\\]}}mm2a.mod,