<div dir="ltr">It's not just windows.h, but windows sdk headers in general (#include <winsock2.h>, #include <ws2tcpip.h> #include <wspiapi.h> #include <dbghelp.h> etc). Here's what the warning does on the first few files in Chromium: <a href="https://build.chromium.org/p/chromium.fyi/builders/ClangToTWin/builds/8155/steps/compile/logs/stdio">https://build.chromium.org/p/chromium.fyi/builders/ClangToTWin/builds/8155/steps/compile/logs/stdio</a> (We add /FIIntrin.h -- but it looks like MSVC's intrin.h is called intrin.h while clang's is called Intrin.h, which is probably a bug in clang).<div><br>I think in general clang's philosophy is that warnings should be useful enough that they should be able to be on by default, so not having it on by default should be some last resort. Better to try and make it work well enough that it can be enabled :-)<br><div><br><div><br><div><br></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 3, 2016 at 5:54 PM, Eric Niebler <span dir="ltr"><<a href="mailto:eniebler@fb.com" target="_blank">eniebler@fb.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">







<div bgcolor="white" lang="EN-US" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">I can investigate the system header issue. And I could add a special exception for <windows.h> if folks feel that that’s the right thing to do. If we’re really worried about how noisy this
 warning could be, the warning could be disabled by default. Thoughts?<span class="HOEnZb"><font color="#888888"><u></u><u></u></font></span></span></p><span class="HOEnZb"><font color="#888888">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri">Eric<u></u><u></u></span></p></font></span><div><div class="h5">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:Calibri"><u></u> <u></u></span></p>
<div>
<div>
<p class="MsoNormal">On 6/3/16, 2:46 PM, "<a href="mailto:thakis@google.com" target="_blank">thakis@google.com</a> on behalf of Nico Weber" <<a href="mailto:thakis@google.com" target="_blank">thakis@google.com</a> on behalf of
<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>> wrote:<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<blockquote style="border:none;border-left:solid #b5c4df 4.5pt;padding:0in 0in 0in 4.0pt;margin-left:3.75pt;margin-right:0in">
<div>
<div>
<div>
<p class="MsoNormal">Also, once that is resolved, this warning tells people that #include <windows.h> is wrong:
<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">..\..\third_party\ffmpeg\compat/w32pthreads.h(39,10):  warning: non-portable path to file '<Windows.h>'; specified path differs in case from file name on disk [-Wnonportable-include-path]<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">#include <windows.h><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">         ^~~~~~~~~~~<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">         <Windows.h><u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I don't think that's realistically fixable; about all the code in the world includes windows.h as windows.h...any ideas what the Windows story for this warning should be?<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Fri, Jun 3, 2016 at 5:43 PM, Nico Weber <<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal">I'm getting lots of warnings like so: <u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">In file included from ..\..\tools\win\static_initializers\static_initializers.cc:5:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">C:\b\depot_tools\win_toolchain\vs_files\95ddda401ec5678f15eeed01d2bee08fcbc5ee97\DIA SDK\include\dia2.h(30,10):  error: non-portable path to file '"Windows.h"'; specified path differs in case from file name on disk [-Werror,-Wnonportable-include-path]<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">#include "windows.h"<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">         ^~~~~~~~~~~<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">         "Windows.h"<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">dia2.h is a system include, and we include it in the search path via -imsvc. Normally warnings aren't emitted for system headers. Do you know why this is happening here?<u></u><u></u></p>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Fri, Jun 3, 2016 at 2:52 PM, Taewook Oh via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">Author: twoh<br>
Date: Fri Jun  3 13:52:51 2016<br>
New Revision: 271708<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D271708-26view-3Drev&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=Gn4UbgHFrY0dCPaPeH59zNo_KJYr9z3TDI7vBbG7XRs&e=" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=271708&view=rev</a><br>
Log:<br>
Use the name of the file on disk to issue a new diagnostic about non-portable #include and #import paths.<br>
<br>
Differential Revision: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D19843&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=QUpSpSdu6fmWjTXFJjR1wpr7M_9MvIaff7xlfRVXQ14&e=" target="_blank">
http://reviews.llvm.org/D19843</a><br>
Corresponding LLVM change: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D19842&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=DQhKLK_syXeWqpQei3-4snZNgN55KGrKo7-HeOUnyd0&e=" target="_blank">
http://reviews.llvm.org/D19842</a><br>
<br>
Patch by Eric Niebler<br>
<br>
<br>
Added:<br>
    cfe/trunk/test/Lexer/Inputs/case-insensitive-include.h<br>
    cfe/trunk/test/Lexer/case-insensitive-include-ms.c<br>
    cfe/trunk/test/Lexer/case-insensitive-include.c<br>
Modified:<br>
    cfe/trunk/include/clang/Basic/DiagnosticGroups.td<br>
    cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td<br>
    cfe/trunk/include/clang/Basic/FileManager.h<br>
    cfe/trunk/include/clang/Basic/VirtualFileSystem.h<br>
    cfe/trunk/include/clang/Lex/DirectoryLookup.h<br>
    cfe/trunk/include/clang/Lex/HeaderSearch.h<br>
    cfe/trunk/lib/Basic/FileManager.cpp<br>
    cfe/trunk/lib/Basic/VirtualFileSystem.cpp<br>
    cfe/trunk/lib/Lex/HeaderSearch.cpp<br>
    cfe/trunk/lib/Lex/PPDirectives.cpp<br>
    cfe/trunk/test/PCH/case-insensitive-include.c<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_include_clang_Basic_DiagnosticGroups.td-3Frev-3D271708-26r1-3D271707-26r2-3D271708-26view-3Ddiff&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=6a-TsQHt64u-EuN1pPvtq22mZURs4e_3hnyjfo8_NT0&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=271708&r1=271707&r2=271708&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Fri Jun  3 13:52:51 2016<br>
@@ -390,6 +390,7 @@ def : DiagGroup<"sequence-point", [Unseq<br>
 def AmbiguousMacro : DiagGroup<"ambiguous-macro">;<br>
 def KeywordAsMacro : DiagGroup<"keyword-macro">;<br>
 def ReservedIdAsMacro : DiagGroup<"reserved-id-macro">;<br>
+def NonportableIncludePath : DiagGroup<"nonportable-include-path">;<br>
<br>
 // Just silence warnings about -Wstrict-aliasing for now.<br>
 def : DiagGroup<"strict-aliasing=0">;<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_include_clang_Basic_DiagnosticLexKinds.td-3Frev-3D271708-26r1-3D271707-26r2-3D271708-26view-3Ddiff&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=LqasKiMnb63oRC7lQEkw66_6fF3Y6FFaKKVR4iQxrzg&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=271708&r1=271707&r2=271708&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Fri Jun  3 13:52:51 2016<br>
@@ -274,6 +274,10 @@ def ext_missing_whitespace_after_macro_n<br>
   "whitespace required after macro name">;<br>
 def warn_missing_whitespace_after_macro_name : Warning<<br>
   "whitespace recommended after macro name">;<br>
+def pp_nonportable_path : Warning<<br>
+  "non-portable path to file '%0'; specified path differs in case from file"<br>
+  " name on disk">,<br>
+  InGroup<NonportableIncludePath>;<br>
<br>
 def pp_pragma_once_in_main_file : Warning<"#pragma once in main file">,<br>
   InGroup<DiagGroup<"pragma-once-outside-header">>;<br>
<br>
Modified: cfe/trunk/include/clang/Basic/FileManager.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_include_clang_Basic_FileManager.h-3Frev-3D271708-26r1-3D271707-26r2-3D271708-26view-3Ddiff&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=R9GHDP8ViXNbktJxnd4Tuvrs15IaYbLJIadMFaOMQig&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=271708&r1=271707&r2=271708&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/FileManager.h (original)<br>
+++ cfe/trunk/include/clang/Basic/FileManager.h Fri Jun  3 13:52:51 2016<br>
@@ -52,6 +52,7 @@ public:<br>
 /// descriptor for the file.<br>
 class FileEntry {<br>
   const char *Name;           // Name of the file.<br>
+  std::string RealPathName;   // Real path to the file; could be empty.<br>
   off_t Size;                 // File size in bytes.<br>
   time_t ModTime;             // Modification time of file.<br>
   const DirectoryEntry *Dir;  // Directory file lives in.<br>
@@ -82,6 +83,7 @@ public:<br>
   }<br>
<br>
   const char *getName() const { return Name; }<br>
+  StringRef tryGetRealPathName() const { return RealPathName; }<br>
   bool isValid() const { return IsValid; }<br>
   off_t getSize() const { return Size; }<br>
   unsigned getUID() const { return UID; }<br>
<br>
Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_include_clang_Basic_VirtualFileSystem.h-3Frev-3D271708-26r1-3D271707-26r2-3D271708-26view-3Ddiff&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=7Hd1P3b4Ro1OGdLwKWztSvAoklCLzw1aHQhHEO6fa5c&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=271708&r1=271707&r2=271708&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original)<br>
+++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Fri Jun  3 13:52:51 2016<br>
@@ -91,6 +91,13 @@ public:<br>
   virtual ~File();<br>
   /// \brief Get the status of the file.<br>
   virtual llvm::ErrorOr<Status> status() = 0;<br>
+  /// \brief Get the name of the file<br>
+  virtual llvm::ErrorOr<StringRef> getName() {<br>
+    if (auto Status = status())<br>
+      return Status->getName();<br>
+    else<br>
+      return Status.getError();<br>
+  }<br>
   /// \brief Get the contents of the file as a \p MemoryBuffer.<br>
   virtual llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>><br>
   getBuffer(const Twine &Name, int64_t FileSize = -1,<br>
<br>
Modified: cfe/trunk/include/clang/Lex/DirectoryLookup.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_include_clang_Lex_DirectoryLookup.h-3Frev-3D271708-26r1-3D271707-26r2-3D271708-26view-3Ddiff&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=OhWyW_LKPRug90vhjDFTdvTo4ikKC51n0syP7jzQnng&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/DirectoryLookup.h?rev=271708&r1=271707&r2=271708&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Lex/DirectoryLookup.h (original)<br>
+++ cfe/trunk/include/clang/Lex/DirectoryLookup.h Fri Jun  3 13:52:51 2016<br>
@@ -151,6 +151,9 @@ public:<br>
   ///<br>
   /// \param HS The header search instance to search with.<br>
   ///<br>
+  /// \param IncludeLoc the source location of the #include or #import<br>
+  /// directive.<br>
+  ///<br>
   /// \param SearchPath If not NULL, will be set to the search path relative<br>
   /// to which the file was found.<br>
   ///<br>
@@ -172,6 +175,7 @@ public:<br>
   /// a framework include ("Foo.h" -> "Foo/Foo.h"), set the new name to this<br>
   /// vector and point Filename to it.<br>
   const FileEntry *LookupFile(StringRef &Filename, HeaderSearch &HS,<br>
+                              SourceLocation IncludeLoc,<br>
                               SmallVectorImpl<char> *SearchPath,<br>
                               SmallVectorImpl<char> *RelativePath,<br>
                               Module *RequestingModule,<br>
<br>
Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_include_clang_Lex_HeaderSearch.h-3Frev-3D271708-26r1-3D271707-26r2-3D271708-26view-3Ddiff&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=X01mGHnmQJI9GpFof5nXfV-DNdzEUpEOvPo9h9k2XbA&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=271708&r1=271707&r2=271708&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)<br>
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Fri Jun  3 13:52:51 2016<br>
@@ -580,8 +580,9 @@ private:<br>
   /// \brief Look up the file with the specified name and determine its owning<br>
   /// module.<br>
   const FileEntry *<br>
-  getFileAndSuggestModule(StringRef FileName, const DirectoryEntry *Dir,<br>
-                          bool IsSystemHeaderDir, Module *RequestingModule,<br>
+  getFileAndSuggestModule(StringRef FileName, SourceLocation IncludeLoc,<br>
+                          const DirectoryEntry *Dir, bool IsSystemHeaderDir,<br>
+                          Module *RequestingModule,<br>
                           ModuleMap::KnownHeader *SuggestedModule);<br>
<br>
 public:<br>
<br>
Modified: cfe/trunk/lib/Basic/FileManager.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_lib_Basic_FileManager.cpp-3Frev-3D271708-26r1-3D271707-26r2-3D271708-26view-3Ddiff&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=iwFjomqJaFszI0DLsHSzZ9VNuXIEx0GWp1DK0mISi_w&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=271708&r1=271707&r2=271708&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Basic/FileManager.cpp (original)<br>
+++ cfe/trunk/lib/Basic/FileManager.cpp Fri Jun  3 13:52:51 2016<br>
@@ -312,6 +312,9 @@ const FileEntry *FileManager::getFile(St<br>
   UFE.InPCH = Data.InPCH;<br>
   UFE.File = std::move(F);<br>
   UFE.IsValid = true;<br>
+  if (UFE.File)<br>
+    if (auto RealPathName = UFE.File->getName())<br>
+      UFE.RealPathName = RealPathName->str();<br>
   return &UFE;<br>
 }<br>
<br>
<br>
Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_lib_Basic_VirtualFileSystem.cpp-3Frev-3D271708-26r1-3D271707-26r2-3D271708-26view-3Ddiff&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=jFhS-FsgQBiSB7NDX0Z5qqpeWYxyJwkbcldbl5gcd0s&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=271708&r1=271707&r2=271708&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)<br>
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Fri Jun  3 13:52:51 2016<br>
@@ -140,16 +140,19 @@ namespace {<br>
 class RealFile : public File {<br>
   int FD;<br>
   Status S;<br>
+  std::string RealName;<br>
   friend class RealFileSystem;<br>
-  RealFile(int FD, StringRef NewName)<br>
+  RealFile(int FD, StringRef NewName, StringRef NewRealPathName)<br>
       : FD(FD), S(NewName, {}, {}, {}, {}, {},<br>
-                  llvm::sys::fs::file_type::status_error, {}) {<br>
+                  llvm::sys::fs::file_type::status_error, {}),<br>
+        RealName(NewRealPathName.str()) {<br>
     assert(FD >= 0 && "Invalid or inactive file descriptor");<br>
   }<br>
<br>
 public:<br>
   ~RealFile() override;<br>
   ErrorOr<Status> status() override;<br>
+  ErrorOr<StringRef> getName() override;<br>
   ErrorOr<std::unique_ptr<MemoryBuffer>> getBuffer(const Twine &Name,<br>
                                                    int64_t FileSize,<br>
                                                    bool RequiresNullTerminator,<br>
@@ -170,6 +173,10 @@ ErrorOr<Status> RealFile::status() {<br>
   return S;<br>
 }<br>
<br>
+ErrorOr<StringRef> RealFile::getName() {<br>
+  return RealName.empty() ? S.getName() : StringRef(RealName);<br>
+}<br>
+<br>
 ErrorOr<std::unique_ptr<MemoryBuffer>><br>
 RealFile::getBuffer(const Twine &Name, int64_t FileSize,<br>
                     bool RequiresNullTerminator, bool IsVolatile) {<br>
@@ -207,9 +214,10 @@ ErrorOr<Status> RealFileSystem::status(c<br>
 ErrorOr<std::unique_ptr<File>><br>
 RealFileSystem::openFileForRead(const Twine &Name) {<br>
   int FD;<br>
-  if (std::error_code EC = sys::fs::openFileForRead(Name, FD))<br>
+  SmallString<256> RealName;<br>
+  if (std::error_code EC = sys::fs::openFileForRead(Name, FD, &RealName))<br>
     return EC;<br>
-  return std::unique_ptr<File>(new RealFile(FD, Name.str()));<br>
+  return std::unique_ptr<File>(new RealFile(FD, Name.str(), RealName.str()));<br>
 }<br>
<br>
 llvm::ErrorOr<std::string> RealFileSystem::getCurrentWorkingDirectory() const {<br>
<br>
Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_lib_Lex_HeaderSearch.cpp-3Frev-3D271708-26r1-3D271707-26r2-3D271708-26view-3Ddiff&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=Ebfh0dwdshHLbsMt1HqZVk5saVnTh-AS727v_ebK6XM&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=271708&r1=271707&r2=271708&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)<br>
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Fri Jun  3 13:52:51 2016<br>
@@ -250,8 +250,9 @@ const char *DirectoryLookup::getName() c<br>
 }<br>
<br>
 const FileEntry *HeaderSearch::getFileAndSuggestModule(<br>
-    StringRef FileName, const DirectoryEntry *Dir, bool IsSystemHeaderDir,<br>
-    Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule) {<br>
+    StringRef FileName, SourceLocation IncludeLoc, const DirectoryEntry *Dir,<br>
+    bool IsSystemHeaderDir, Module *RequestingModule,<br>
+    ModuleMap::KnownHeader *SuggestedModule) {<br>
   // If we have a module map that might map this header, load it and<br>
   // check whether we'll have a suggestion for a module.<br>
   const FileEntry *File = getFileMgr().getFile(FileName, /*OpenFile=*/true);<br>
@@ -272,6 +273,7 @@ const FileEntry *HeaderSearch::getFileAn<br>
 const FileEntry *DirectoryLookup::LookupFile(<br>
     StringRef &Filename,<br>
     HeaderSearch &HS,<br>
+    SourceLocation IncludeLoc,<br>
     SmallVectorImpl<char> *SearchPath,<br>
     SmallVectorImpl<char> *RelativePath,<br>
     Module *RequestingModule,<br>
@@ -297,7 +299,7 @@ const FileEntry *DirectoryLookup::Lookup<br>
       RelativePath->append(Filename.begin(), Filename.end());<br>
     }<br>
<br>
-    return HS.getFileAndSuggestModule(TmpDir, getDir(),<br>
+    return HS.getFileAndSuggestModule(TmpDir, IncludeLoc, getDir(),<br>
                                       isSystemHeaderDirectory(),<br>
                                       RequestingModule, SuggestedModule);<br>
   }<br>
@@ -585,7 +587,7 @@ const FileEntry *HeaderSearch::LookupFil<br>
       RelativePath->append(Filename.begin(), Filename.end());<br>
     }<br>
     // Otherwise, just return the file.<br>
-    return getFileAndSuggestModule(Filename, nullptr,<br>
+    return getFileAndSuggestModule(Filename, IncludeLoc, nullptr,<br>
                                    /*IsSystemHeaderDir*/false,<br>
                                    RequestingModule, SuggestedModule);<br>
   }<br>
@@ -622,7 +624,7 @@ const FileEntry *HeaderSearch::LookupFil<br>
           Includer ? getFileInfo(Includer).DirInfo != SrcMgr::C_User :<br>
           BuildSystemModule;<br>
       if (const FileEntry *FE = getFileAndSuggestModule(<br>
-              TmpDir, IncluderAndDir.second, IncluderIsSystemHeader,<br>
+              TmpDir, IncludeLoc, IncluderAndDir.second, IncluderIsSystemHeader,<br>
               RequestingModule, SuggestedModule)) {<br>
         if (!Includer) {<br>
           assert(First && "only first includer can have no file");<br>
@@ -713,7 +715,7 @@ const FileEntry *HeaderSearch::LookupFil<br>
     bool InUserSpecifiedSystemFramework = false;<br>
     bool HasBeenMapped = false;<br>
     const FileEntry *FE = SearchDirs[i].LookupFile(<br>
-        Filename, *this, SearchPath, RelativePath, RequestingModule,<br>
+        Filename, *this, IncludeLoc, SearchPath, RelativePath, RequestingModule,<br>
         SuggestedModule, InUserSpecifiedSystemFramework, HasBeenMapped,<br>
         MappedName);<br>
     if (HasBeenMapped) {<br>
<br>
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_lib_Lex_PPDirectives.cpp-3Frev-3D271708-26r1-3D271707-26r2-3D271708-26view-3Ddiff&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=QugiHYCfviRQxQQK9-OYyM-uAYKWoLlIRPACGkNGdgw&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=271708&r1=271707&r2=271708&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)<br>
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Fri Jun  3 13:52:51 2016<br>
@@ -24,6 +24,9 @@<br>
 #include "clang/Lex/ModuleLoader.h"<br>
 #include "clang/Lex/Pragma.h"<br>
 #include "llvm/ADT/APInt.h"<br>
+#include "llvm/ADT/STLExtras.h"<br>
+#include "llvm/ADT/StringExtras.h"<br>
+#include "llvm/ADT/iterator_range.h"<br>
 #include "llvm/Support/ErrorHandling.h"<br>
 #include "llvm/Support/Path.h"<br>
 #include "llvm/Support/SaveAndRestore.h"<br>
@@ -1556,6 +1559,41 @@ static void diagnoseAutoModuleImport(<br>
                                       ("@import " + PathString + ";").str());<br>
 }<br>
<br>
+namespace {<br>
+  // Given a vector of path components and a string containing the real<br>
+  // path to the file, build a properly-cased replacement in the vector,<br>
+  // and return true if the replacement should be suggested.<br>
+  bool TrySimplifyPath(SmallVectorImpl<StringRef> &Components,<br>
+                       StringRef RealPathName) {<br>
+    auto RealPathComponentIter = llvm::sys::path::rbegin(RealPathName);<br>
+    auto RealPathComponentEnd = llvm::sys::path::rend(RealPathName);<br>
+    int Cnt = 0;<br>
+    bool SuggestReplacement = false;<br>
+    // Below is a best-effort to handle ".." in paths. It is admittedly<br>
+    // not 100% correct in the presence of symlinks.<br>
+    for(auto &Component : llvm::reverse(Components)) {<br>
+      if ("." == Component) {<br>
+      } else if (".." == Component) {<br>
+        ++Cnt;<br>
+      } else if (Cnt) {<br>
+        --Cnt;<br>
+      } else if (RealPathComponentIter != RealPathComponentEnd) {<br>
+        if (Component != *RealPathComponentIter) {<br>
+          // If these path components differ by more than just case, then we<br>
+          // may be looking at symlinked paths. Bail on this diagnostic to avoid<br>
+          // noisy false positives.<br>
+          SuggestReplacement = RealPathComponentIter->equals_lower(Component);<br>
+          if (!SuggestReplacement)<br>
+            break;<br>
+          Component = *RealPathComponentIter;<br>
+        }<br>
+        ++RealPathComponentIter;<br>
+      }<br>
+    }<br>
+    return SuggestReplacement;<br>
+  }<br>
+}<br>
+<br>
 /// HandleIncludeDirective - The "\#include" tokens have just been read, read<br>
 /// the file to be included from the lexer, then include it!  This is a common<br>
 /// routine with functionality shared between \#include, \#include_next and<br>
@@ -1720,6 +1758,35 @@ void Preprocessor::HandleIncludeDirectiv<br>
     }<br>
   }<br>
<br>
+  // Issue a diagnostic if the name of the file on disk has a different case<br>
+  // than the one we're about to open.<br>
+  const bool CheckIncludePathPortability =<br>
+    File && !File->tryGetRealPathName().empty();<br>
+<br>
+  if (CheckIncludePathPortability) {<br>
+    StringRef Name = LangOpts.MSVCCompat ? NormalizedPath.c_str() : Filename;<br>
+    StringRef RealPathName = File->tryGetRealPathName();<br>
+    SmallVector<StringRef, 16> Components(llvm::sys::path::begin(Name),<br>
+                                          llvm::sys::path::end(Name));<br>
+<br>
+    if (TrySimplifyPath(Components, RealPathName)) {<br>
+      SmallString<128> Path;<br>
+      Path.reserve(Name.size()+2);<br>
+      Path.push_back(isAngled ? '<' : '"');<br>
+      for (auto Component : Components) {<br>
+        Path.append(Component);<br>
+        // Append the separator the user used, or the close quote<br>
+        Path.push_back(<br>
+          Path.size() <= Filename.size() ? Filename[Path.size()-1] :<br>
+            (isAngled ? '>' : '"'));<br>
+      }<br>
+      auto Replacement = Path.str().str();<br>
+      SourceRange Range(FilenameTok.getLocation(), CharEnd);<br>
+      Diag(FilenameTok, diag::pp_nonportable_path) << Replacement <<<br>
+        FixItHint::CreateReplacement(Range, Replacement);<br>
+    }<br>
+  }<br>
+<br>
   // Should we enter the source file? Set to false if either the source file is<br>
   // known to have no effect beyond its effect on module visibility -- that is,<br>
   // if it's got an include guard that is already defined or is a modular header<br>
<br>
Added: cfe/trunk/test/Lexer/Inputs/case-insensitive-include.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_test_Lexer_Inputs_case-2Dinsensitive-2Dinclude.h-3Frev-3D271708-26view-3Dauto&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=2DKea-gWyg2aHxljrbglHueVSS4-04lPDK8kBb8X8DA&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/Inputs/case-insensitive-include.h?rev=271708&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Lexer/Inputs/case-insensitive-include.h (added)<br>
+++ cfe/trunk/test/Lexer/Inputs/case-insensitive-include.h Fri Jun  3 13:52:51 2016<br>
@@ -0,0 +1,5 @@<br>
+#pragma once<br>
+<br>
+struct S {<br>
+  int x;<br>
+};<br>
<br>
Added: cfe/trunk/test/Lexer/case-insensitive-include-ms.c<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_test_Lexer_case-2Dinsensitive-2Dinclude-2Dms.c-3Frev-3D271708-26view-3Dauto&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=6rz4E7m8nEg_815olqcu_2xAoXuw-FzLzh8IUuRZmQs&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/case-insensitive-include-ms.c?rev=271708&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Lexer/case-insensitive-include-ms.c (added)<br>
+++ cfe/trunk/test/Lexer/case-insensitive-include-ms.c Fri Jun  3 13:52:51 2016<br>
@@ -0,0 +1,18 @@<br>
+// REQUIRES: case-insensitive-filesystem<br>
+<br>
+// RUN: mkdir -p %T/apath<br>
+// RUN: cp %S/Inputs/case-insensitive-include.h %T<br>
+// RUN: cd %T<br>
+// RUN: %clang_cc1 -fsyntax-only -fms-compatibility %s -include %s -I %T -verify<br>
+// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -fdiagnostics-parseable-fixits %s -include %s -I %T 2>&1 | FileCheck %s<br>
+<br>
+#include "..\Output\.\case-insensitive-include.h"<br>
+#include "..\Output\.\Case-Insensitive-Include.h" // expected-warning {{non-portable path}}<br>
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:50}:"\"..\\Output\\.\\case-insensitive-include.h\""<br>
+#include "..\output\.\case-insensitive-include.h" // expected-warning {{non-portable path}}<br>
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:50}:"\"..\\Output\\.\\case-insensitive-include.h\""<br>
+<br>
+#include "apath\..\.\case-insensitive-include.h"<br>
+#include "apath\..\.\Case-Insensitive-Include.h" // expected-warning {{non-portable path}}<br>
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:49}:"\"apath\\..\\.\\case-insensitive-include.h\""<br>
+#include "APath\..\.\case-insensitive-include.h" // For the sake of efficiency, this case is not diagnosed. :-(<br>
<br>
Added: cfe/trunk/test/Lexer/case-insensitive-include.c<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_test_Lexer_case-2Dinsensitive-2Dinclude.c-3Frev-3D271708-26view-3Dauto&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=1tbn86CAD1kee5FFWpAkjbAHeh-otH2u6AujIat6wZI&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/case-insensitive-include.c?rev=271708&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Lexer/case-insensitive-include.c (added)<br>
+++ cfe/trunk/test/Lexer/case-insensitive-include.c Fri Jun  3 13:52:51 2016<br>
@@ -0,0 +1,27 @@<br>
+// REQUIRES: case-insensitive-filesystem<br>
+<br>
+// RUN: mkdir -p %T/apath<br>
+// RUN: cp %S/Inputs/case-insensitive-include.h %T<br>
+// RUN: cd %T<br>
+// RUN: %clang_cc1 -fsyntax-only %s -include %s -I %T -verify<br>
+// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s -include %s -I %T 2>&1 | FileCheck %s<br>
+<br>
+#include "case-insensitive-include.h"<br>
+#include "Case-Insensitive-Include.h" // expected-warning {{non-portable path}}<br>
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:38}:"\"case-insensitive-include.h\""<br>
+<br>
+#include "../Output/./case-insensitive-include.h"<br>
+#include "../Output/./Case-Insensitive-Include.h" // expected-warning {{non-portable path}}<br>
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:50}:"\"../Output/./case-insensitive-include.h\""<br>
+#include "../output/./case-insensitive-include.h" // expected-warning {{non-portable path}}<br>
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:50}:"\"../Output/./case-insensitive-include.h\""<br>
+<br>
+#include "apath/.././case-insensitive-include.h"<br>
+#include "apath/.././Case-Insensitive-Include.h" // expected-warning {{non-portable path}}<br>
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:49}:"\"apath/.././case-insensitive-include.h\""<br>
+#include "APath/.././case-insensitive-include.h" // For the sake of efficiency, this case is not diagnosed. :-(<br>
+<br>
+#include "../Output/./apath/.././case-insensitive-include.h"<br>
+#include "../Output/./APath/.././case-insensitive-include.h" // For the sake of efficiency, this case is not diagnosed. :-(<br>
+#include "../output/./apath/.././case-insensitive-include.h" // expected-warning {{non-portable path}}<br>
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:61}:"\"../Output/./apath/.././case-insensitive-include.h\""<br>
<br>
Modified: cfe/trunk/test/PCH/case-insensitive-include.c<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_test_PCH_case-2Dinsensitive-2Dinclude.c-3Frev-3D271708-26r1-3D271707-26r2-3D271708-26view-3Ddiff&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=zVaRhVtq7ZHNV3H0vfd_1vOF7-vjRQeHnRyU419K7IE&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/case-insensitive-include.c?rev=271708&r1=271707&r2=271708&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/PCH/case-insensitive-include.c (original)<br>
+++ cfe/trunk/test/PCH/case-insensitive-include.c Fri Jun  3 13:52:51 2016<br>
@@ -2,7 +2,7 @@<br>
<br>
 // Test this without pch.<br>
 // RUN: cp %S/Inputs/case-insensitive-include.h %T<br>
-// RUN: %clang_cc1 -fsyntax-only %s -include %s -I %T -verify<br>
+// RUN: %clang_cc1 -Wno-nonportable-include-path -fsyntax-only %s -include %s -I %T -verify<br>
<br>
 // Test with pch.<br>
 // RUN: %clang_cc1 -emit-pch -o %t.pch %s -I %T<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_cfe-2Dcommits&d=CwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=t4UJXwtMcIwGvgOaMqGzrQ&m=V9o7pyPA6lC6C5vc83jcUDQl3QUmGLtRDdBUFqIUYc8&s=vEbwZjtEM_C4qGMaZuAZ2bGrAqRPN-kA24CpR350-_s&e=" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div></div></div>
</div>

</blockquote></div><br></div>