[lld] r288972 - Make convertToUnixPathSeparator return a new string instead of mutating argument.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 7 12:22:28 PST 2016


Author: ruiu
Date: Wed Dec  7 14:22:27 2016
New Revision: 288972

URL: http://llvm.org/viewvc/llvm-project?rev=288972&view=rev
Log:
Make convertToUnixPathSeparator return a new string instead of mutating argument.

Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/include/lld/Core/Reproduce.h
    lld/trunk/lib/Core/Reproduce.cpp

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=288972&r1=288971&r2=288972&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Wed Dec  7 14:22:27 2016
@@ -91,9 +91,8 @@ std::string elf::ObjectFile<ELFT>::getLi
       DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, Info);
   if (Info.Line == 0)
     return "";
-  std::string Ret = Info.FileName + ":" + std::to_string(Info.Line);
-  convertToUnixPathSeparator({(char *)Ret.data(), Ret.size()});
-  return Ret;
+  return convertToUnixPathSeparator(
+      Info.FileName + ":" + std::to_string(Info.Line));
 }
 
 // Returns "(internal)", "foo.a(bar.o)" or "baz.o".

Modified: lld/trunk/include/lld/Core/Reproduce.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Reproduce.h?rev=288972&r1=288971&r2=288972&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Reproduce.h (original)
+++ lld/trunk/include/lld/Core/Reproduce.h Wed Dec  7 14:22:27 2016
@@ -66,8 +66,8 @@ std::string rewritePath(StringRef S);
 // Returns the string form of the given argument.
 std::string stringize(llvm::opt::Arg *Arg);
 
-// Converts path to use unix path separators.
-void convertToUnixPathSeparator(llvm::MutableArrayRef<char> Path);
+// Replaces backslashes with slashes if Windows.
+std::string convertToUnixPathSeparator(StringRef S);
 
 }
 

Modified: lld/trunk/lib/Core/Reproduce.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Reproduce.cpp?rev=288972&r1=288971&r2=288972&view=diff
==============================================================================
--- lld/trunk/lib/Core/Reproduce.cpp (original)
+++ lld/trunk/lib/Core/Reproduce.cpp Wed Dec  7 14:22:27 2016
@@ -59,9 +59,8 @@ void CpioFile::append(StringRef Path, St
   // (i.e. in that case we are creating baz.cpio.)
   SmallString<128> Fullpath;
   path::append(Fullpath, Basename, Path);
-  convertToUnixPathSeparator(Fullpath);
 
-  writeMember(*OS, Fullpath, Data);
+  writeMember(*OS, convertToUnixPathSeparator(Fullpath), Data);
 
   // Print the trailer and seek back.
   // This way we have a valid archive if we crash.
@@ -92,9 +91,7 @@ std::string lld::relativeToRoot(StringRe
     Res = Root.substr(2);
 
   path::append(Res, path::relative_path(Abs));
-  convertToUnixPathSeparator(Res);
-
-  return Res.str();
+  return convertToUnixPathSeparator(Res);
 }
 
 // Quote a given string if it contains a space character.
@@ -120,8 +117,12 @@ std::string lld::stringize(opt::Arg *Arg
   return K + " " + V;
 }
 
-void lld::convertToUnixPathSeparator(MutableArrayRef<char> Path) {
+std::string lld::convertToUnixPathSeparator(StringRef S) {
 #ifdef LLVM_ON_WIN32
-  std::replace(Path.begin(), Path.end(), '\\', '/');
+  std:string Ret = S.str();
+  std::replace(Ret.begin(), Ret.end(), '\\', '/');
+  return Ret;
+#else
+  return S;
 #endif
 }




More information about the llvm-commits mailing list