diff options
author | Sylvain Audi <sylvain.audi@ubisoft.com> | 2021-05-12 09:56:52 -0400 |
---|---|---|
committer | Sylvain Audi <sylvain.audi@ubisoft.com> | 2021-05-17 10:32:52 -0400 |
commit | 6052a8a53559d667321637f7159353ab724a1141 (patch) | |
tree | 47b54358e53d6377c33fed897e2c4117754caa56 /clang/lib/Frontend/DependencyFile.cpp | |
parent | 472f856714fb1687b0727b3013f5d071d8fa86ae (diff) | |
download | llvm-6052a8a53559d667321637f7159353ab724a1141.zip llvm-6052a8a53559d667321637f7159353ab724a1141.tar.gz llvm-6052a8a53559d667321637f7159353ab724a1141.tar.bz2 |
[clang] In DependencyCollector on Windows, ignore case and separators when discarding duplicate dependency file paths.
This patch removes duplicates also encountered in the output of clang-scan-deps when one same header file is encountered with different casing and/or different separators ('/' vs '\').
The case of separators can appear when the same file is included externally by
`#include <folder/file.h>`
whereas a file from the same folder does
`#include "file.h"`
Under Windows, clang computes the paths using '/' from the include directive, the `\` from the -I options, and the concatenations use the native `\`, leading to internal paths containing a mix of both separators.
Differential Revision: https://reviews.llvm.org/D102339
Diffstat (limited to 'clang/lib/Frontend/DependencyFile.cpp')
-rw-r--r-- | clang/lib/Frontend/DependencyFile.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/clang/lib/Frontend/DependencyFile.cpp b/clang/lib/Frontend/DependencyFile.cpp index ccc7ed9..2888273 100644 --- a/clang/lib/Frontend/DependencyFile.cpp +++ b/clang/lib/Frontend/DependencyFile.cpp @@ -141,7 +141,18 @@ void DependencyCollector::maybeAddDependency(StringRef Filename, } bool DependencyCollector::addDependency(StringRef Filename) { - if (Seen.insert(Filename).second) { + StringRef SearchPath; +#ifdef _WIN32 + // Make the search insensitive to case and separators. + llvm::SmallString<256> TmpPath = Filename; + llvm::sys::path::native(TmpPath); + std::transform(TmpPath.begin(), TmpPath.end(), TmpPath.begin(), ::tolower); + SearchPath = TmpPath.str(); +#else + SearchPath = Filename; +#endif + + if (Seen.insert(SearchPath).second) { Dependencies.push_back(std::string(Filename)); return true; } |