From 63d064e9d15d48648da916749f44b4c8f013755e Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 7 Dec 2016 20:22:27 +0000 Subject: [PATCH] Make convertToUnixPathSeparator return a new string instead of mutating argument. llvm-svn: 288972 --- lld/ELF/InputFiles.cpp | 5 ++--- lld/include/lld/Core/Reproduce.h | 4 ++-- lld/lib/Core/Reproduce.cpp | 15 ++++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 92b1439..ac717f4 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -91,9 +91,8 @@ std::string elf::ObjectFile::getLineInfo(InputSectionBase *S, 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". diff --git a/lld/include/lld/Core/Reproduce.h b/lld/include/lld/Core/Reproduce.h index 3c5e5e1..660c2da 100644 --- a/lld/include/lld/Core/Reproduce.h +++ b/lld/include/lld/Core/Reproduce.h @@ -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 Path); +// Replaces backslashes with slashes if Windows. +std::string convertToUnixPathSeparator(StringRef S); } diff --git a/lld/lib/Core/Reproduce.cpp b/lld/lib/Core/Reproduce.cpp index a6d1f8d..50cc716 100644 --- a/lld/lib/Core/Reproduce.cpp +++ b/lld/lib/Core/Reproduce.cpp @@ -59,9 +59,8 @@ void CpioFile::append(StringRef Path, StringRef Data) { // (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(StringRef Path) { 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 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 } -- 2.7.4