[PATCH] Support case insensitive header searches for MSVCCompat
Richard Smith
richard at metafoo.co.uk
Thu Mar 13 18:22:14 PDT 2014
Have you considered using something ilke [ciopfs](http://www.brain-dump.org/projects/ciopfs/)? =)
This patch needs testcases.
I also suspect that some of this belongs in LLVM's Support library, rather than here, but that can wait until we've figured out exactly what we want.
================
Comment at: lib/Lex/HeaderSearch.cpp:36-42
@@ +35,9 @@
+
+ for (PI = llvm::sys::path::rbegin(LowerPath),
+ PE = llvm::sys::path::rend(LowerPath),
+ FI = llvm::sys::path::rbegin(LowerFilename),
+ FE = llvm::sys::path::rend(LowerFilename);
+ FI != FE && PI != PE; ++PI, ++FI)
+ if (FI->str() != PI->str())
+ return false;
+
----------------
Do you need to compare anything other than the last component here?
================
Comment at: lib/Frontend/InitHeaderSearch.cpp:679
@@ -673,3 +678,3 @@
const llvm::Triple &Triple) {
- InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot);
+ InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot, Lang.MSVCCompat);
----------------
We don't want to pay the cost of this if the underlying file system is already case-insensitive. On Windows, `GetVolumeInformation` can be used to determine this. I don't think there's a good way to determine it for Linux, sadly.
(We should also use this in `FileManager` rather than making an assumption that Windows is case-insensitive and nothing else is there.)
================
Comment at: include/clang/Lex/DirectoryLookup.h:66
@@ +65,3 @@
+ /// \brief Whether the lookup should be case insensitive. This is required
+ /// for compatibility with case-sensitive file systems and Mcirosoft mode
+ /// which does not include headers with the correct case.
----------------
Typo of "Microsoft"
================
Comment at: lib/Lex/HeaderSearch.cpp:257-265
@@ +256,11 @@
+ if (CaseInsensitive && !llvm::sys::fs::exists(TmpDir.str())) {
+ llvm::error_code EC;
+ std::string LowerFilename = Filename.lower();
+ for (llvm::sys::fs::directory_iterator DI(getDir()->getName(), EC), DE;
+ !EC && DI != DE; DI = DI.increment(EC)) {
+ if (IsEquivalent(DI->path(), LowerFilename)) {
+ TmpDir = DI->path();
+ break;
+ }
+ }
+ }
----------------
Please factor this out. Should you do something better with `EC` than ignoring it?
http://llvm-reviews.chandlerc.com/D2972
More information about the cfe-commits
mailing list