[flang-commits] [PATCH] D89369: [flang][windows] Support platform-specific path separator.

Michael Kruse via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Oct 14 00:11:06 PDT 2020


Meinersbur created this revision.
Meinersbur added reviewers: isuruf, DavidTruby, sscalpone, klausler, tskeith.
Meinersbur added a project: Flang.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.
Meinersbur requested review of this revision.

Remove the assumption that the path separator is `/`. Use functions from `llvm::sys::path` instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89369

Files:
  flang/lib/Parser/source.cpp
  flang/test/Semantics/getsymbols02.f90


Index: flang/test/Semantics/getsymbols02.f90
===================================================================
--- flang/test/Semantics/getsymbols02.f90
+++ 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,
Index: flang/lib/Parser/source.cpp
===================================================================
--- flang/lib/Parser/source.cpp
+++ 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 @@
 }
 
 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89369.298054.patch
Type: text/x-patch
Size: 1858 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20201014/3be12f4e/attachment.bin>


More information about the flang-commits mailing list