diff options
author | Paul Pluzhnikov <ppluzhnikov@google.com> | 2022-06-02 10:30:24 -0700 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2022-06-02 11:07:44 -0700 |
commit | 35ab2a11bb55c39ef9fe389aeacc14bb55c5a12d (patch) | |
tree | ca1c351b0e8af4fea1547b6531824c19da711da9 /llvm/lib/Support/Path.cpp | |
parent | e4870c835791faa7b71f66820fdb6bcdcec636d7 (diff) | |
download | llvm-35ab2a11bb55c39ef9fe389aeacc14bb55c5a12d.zip llvm-35ab2a11bb55c39ef9fe389aeacc14bb55c5a12d.tar.gz llvm-35ab2a11bb55c39ef9fe389aeacc14bb55c5a12d.tar.bz2 |
Fix a buglet in remove_dots().
The function promises to canonicalize the path, but neglected to do so
for the root component.
For example, calling remove_dots("/tmp/foo.c", Style::windows_backslash)
resulted in "/tmp\foo.c". Now it produces "\tmp\foo.c".
Also fix FIXME in the corresponding test.
Reviewed By: rnk
Differential Revision: https://reviews.llvm.org/D126412
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r-- | llvm/lib/Support/Path.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index 973b903..9575e34 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -760,11 +760,15 @@ bool remove_dots(SmallVectorImpl<char> &the_path, bool remove_dot_dot, } } + SmallString<256> buffer = root; + // "root" could be "/", which may need to be translated into "\". + make_preferred(buffer, style); + needs_change |= root != buffer; + // Avoid rewriting the path unless we have to. if (!needs_change) return false; - SmallString<256> buffer = root; if (!components.empty()) { buffer += components[0]; for (StringRef C : makeArrayRef(components).drop_front()) { |