diff --git a/llvm/test/tools/llvm-rc/absolute.test b/llvm/test/tools/llvm-rc/absolute.test --- a/llvm/test/tools/llvm-rc/absolute.test +++ b/llvm/test/tools/llvm-rc/absolute.test @@ -1,3 +1,7 @@ ; RUN: touch %t.manifest ; RUN: echo "1 24 \"%t.manifest\"" > %t.rc ; RUN: llvm-rc -- %t.rc +;; On Windows, try stripping out the drive name from the absolute path, +;; and make sure the path still is found. +; RUN: cat %t.rc | sed 's/"[a-zA-Z]:/"/' > %t2.rc +; RUN: llvm-rc -- %t2.rc diff --git a/llvm/tools/llvm-rc/ResourceFileWriter.cpp b/llvm/tools/llvm-rc/ResourceFileWriter.cpp --- a/llvm/tools/llvm-rc/ResourceFileWriter.cpp +++ b/llvm/tools/llvm-rc/ResourceFileWriter.cpp @@ -1514,8 +1514,16 @@ SmallString<128> Cwd; std::unique_ptr Result; - // 0. The file path is absolute and the file exists. - if (sys::path::is_absolute(File)) + // 0. The file path is absolute or has a root directory, so we shouldn't + // try to append it on top of other base directories. (An absolute path + // must have a root directory, but e.g. the path "\dir\file" on windows + // isn't considered absolute, but it does have a root directory. As long as + // sys::path::append doesn't handle appending an absolute path or a path + // starting with a root directory on top of a base, we must handle this + // case separately at the top. C++17's path::append handles that case + // properly though, so if using that to append paths below, this early + // exception case could be removed.) + if (sys::path::has_root_directory(File)) return errorOrToExpected(MemoryBuffer::getFile(File, -1, false)); // 1. The current working directory.