From 9c761a36b9a93bff188109502231cc60b96894e1 Mon Sep 17 00:00:00 2001 From: Serge Pavlov Date: Wed, 1 Mar 2017 09:38:15 +0000 Subject: Process tilde in llvm::sys::path::native Windows does not treat `~` as a reference to home directory, so the call to `llvm::sys::path::native` on, say, `~/somedir` produces `~\somedir`, which has different meaning than the original path. With this change tilde is expanded on Windows to user profile directory. Such behavior keeps original meaning of the path and is consistent with the algorithm of `llvm::sys::path::home_directory`. Differential Revision: https://reviews.llvm.org/D27527 llvm-svn: 296590 --- llvm/lib/Support/Path.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'llvm/lib/Support') diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index 4bb035eeccc..0709ec272f5 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -556,8 +556,16 @@ void native(const Twine &path, SmallVectorImpl &result) { } void native(SmallVectorImpl &Path) { + if (Path.empty()) + return; #ifdef LLVM_ON_WIN32 std::replace(Path.begin(), Path.end(), '/', '\\'); + if (Path[0] == '~' && (Path.size() == 1 || is_separator(Path[1]))) { + SmallString<128> PathHome; + home_directory(PathHome); + PathHome.append(Path.begin() + 1, Path.end()); + Path = PathHome; + } #else for (auto PI = Path.begin(), PE = Path.end(); PI < PE; ++PI) { if (*PI == '\\') { -- cgit v1.2.3