[flang-commits] [flang] b579378 - [flang][windows] Support platform-specific path separator.
Michael Kruse via flang-commits
flang-commits at lists.llvm.org
Fri Oct 23 20:22:45 PDT 2020
Author: Michael Kruse
Date: 2020-10-23T22:22:37-05:00
New Revision: b57937861f68305068d8a35154811b4303ce52e5
URL: https://github.com/llvm/llvm-project/commit/b57937861f68305068d8a35154811b4303ce52e5
DIFF: https://github.com/llvm/llvm-project/commit/b57937861f68305068d8a35154811b4303ce52e5.diff
LOG: [flang][windows] Support platform-specific path separator.
Remove the assumption that the path separator is `/`. Use functions from `llvm::sys::path` instead.
Reviewed By: isuruf, klausler
Differential Revision: https://reviews.llvm.org/D89369
Added:
Modified:
flang/lib/Parser/source.cpp
flang/test/Semantics/getsymbols02.f90
Removed:
################################################################################
diff --git a/flang/lib/Parser/source.cpp b/flang/lib/Parser/source.cpp
index 693138c2711c..11cd5916dedf 100644
--- 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 <algorithm>
#include <memory>
@@ -50,21 +51,23 @@ void SourceFile::IdentifyPayload() {
}
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<std::string> &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
index 80b7651f029b..0119ab16daa8 100644
--- a/flang/test/Semantics/getsymbols02.f90
+++ b/flang/test/Semantics/getsymbols02.f90
@@ -10,5 +10,5 @@ PROGRAM helloworld
! 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,
More information about the flang-commits
mailing list