aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Path.cpp
diff options
context:
space:
mode:
authorSylvain Audi <sylvain.audi@ubisoft.com>2020-04-29 12:50:37 -0400
committerSylvain Audi <sylvain.audi@ubisoft.com>2020-05-13 13:49:14 -0400
commit7a8edcb2124b60941ef6ea4bb4b38a9eb0d70137 (patch)
tree6e6e17e69e14eed67c2f745cd6153e9571571284 /llvm/lib/Support/Path.cpp
parent33d96bf7b9b2add1c45bf1c60195dc7ca961393e (diff)
downloadllvm-7a8edcb2124b60941ef6ea4bb4b38a9eb0d70137.zip
llvm-7a8edcb2124b60941ef6ea4bb4b38a9eb0d70137.tar.gz
llvm-7a8edcb2124b60941ef6ea4bb4b38a9eb0d70137.tar.bz2
[Clang] Restore replace_path_prefix instead of startswith
In D49466, sys::path::replace_path_prefix was used instead startswith for -f[macro/debug/file]-prefix-map options. However those were reverted later (commit rG3bb24bf25767ef5bbcef958b484e7a06d8689204) due to broken Windows tests. This patch restores those replace_path_prefix calls. It also modifies the prefix matching to be case-insensitive under Windows. Differential Revision : https://reviews.llvm.org/D76869
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r--llvm/lib/Support/Path.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index 7756290..37b3086 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -496,13 +496,32 @@ void replace_extension(SmallVectorImpl<char> &path, const Twine &extension,
path.append(ext.begin(), ext.end());
}
+static bool starts_with(StringRef Path, StringRef Prefix,
+ Style style = Style::native) {
+ // Windows prefix matching : case and separator insensitive
+ if (real_style(style) == Style::windows) {
+ if (Path.size() < Prefix.size())
+ return false;
+ for (size_t I = 0, E = Prefix.size(); I != E; ++I) {
+ bool SepPath = is_separator(Path[I], style);
+ bool SepPrefix = is_separator(Prefix[I], style);
+ if (SepPath != SepPrefix)
+ return false;
+ if (!SepPath && toLower(Path[I]) != toLower(Prefix[I]))
+ return false;
+ }
+ return true;
+ }
+ return Path.startswith(Prefix);
+}
+
bool replace_path_prefix(SmallVectorImpl<char> &Path, StringRef OldPrefix,
- StringRef NewPrefix) {
+ StringRef NewPrefix, Style style) {
if (OldPrefix.empty() && NewPrefix.empty())
return false;
StringRef OrigPath(Path.begin(), Path.size());
- if (!OrigPath.startswith(OldPrefix))
+ if (!starts_with(OrigPath, OldPrefix, style))
return false;
// If prefixes have the same size we can simply copy the new one over.