[cfe-dev] case-insensitive #include warning

Eric Niebler via cfe-dev cfe-dev at lists.llvm.org
Tue Apr 5 16:03:59 PDT 2016


Hi all,

I have an initial cut at patch that issues a warning when a file is #included on a case-insensitive file system that would not be found on a case-sensitive system. Is there interest?

Since this is a hard problem to solve perfectly, I have opted for a strategy that is efficient and conservative about issuing diagnostics. That is, it shouldn't give false positives, but it will fail to diagnose some non-portable paths. On *nix systems, the low-level APIs that stat and open files get an extra call to ::realpath, and the result is cached along with the rest of the file metadata. On Windows, I use a combination of GetFullPathName and GetLongPathName to get the same effect. (I don't believe that's guaranteed to get the physical name including case, but it seems to mostly work in my testing.)

Due to how I compare path components, a relative path like "NoTtHeRiGhTcAsE/../correctly-cased.h" will not be diagnosed, but "../NoTtHeRiGhTcAsE/correctly-cased.h" will be. Catching more cases requires many more round trips to the disk, which I wanted to avoid.

Feedback welcome.

Thanks,
Eric

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160405/2a91e108/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang.patch
Type: application/octet-stream
Size: 26042 bytes
Desc: clang.patch
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160405/2a91e108/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: llvm.patch
Type: application/octet-stream
Size: 2768 bytes
Desc: llvm.patch
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160405/2a91e108/attachment-0001.obj>


More information about the cfe-dev mailing list