Index: clang/include/clang/Lex/HeaderSearch.h =================================================================== --- clang/include/clang/Lex/HeaderSearch.h +++ clang/include/clang/Lex/HeaderSearch.h @@ -361,6 +361,8 @@ /// \param CurDir If non-null, the file was found in the specified directory /// search location. This is used to implement \#include_next. /// + /// \param IsMapped If true, the search involved header maps. + /// /// \param Includers Indicates where the \#including file(s) are, in case /// relative searches are needed. In reverse order of inclusion. /// @@ -378,11 +380,25 @@ const FileEntry *LookupFile( StringRef Filename, SourceLocation IncludeLoc, bool isAngled, const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir, + bool &IsMapped, ArrayRef> Includers, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool SkipCache = false, bool BuildSystemModule = false); + const FileEntry *LookupFile( + StringRef Filename, SourceLocation IncludeLoc, bool isAngled, + const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir, + ArrayRef> Includers, + SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, + Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, + bool SkipCache = false, bool BuildSystemModule = false) { + bool IsMapped = false; + return LookupFile(Filename, IncludeLoc, isAngled, FromDir, CurDir, IsMapped, + Includers, SearchPath, RelativePath, RequestingModule, + SuggestedModule, SkipCache, BuildSystemModule); + } + /// \brief Look up a subframework for the specified \#include file. /// /// For example, if \#include'ing from Index: clang/include/clang/Lex/Preprocessor.h =================================================================== --- clang/include/clang/Lex/Preprocessor.h +++ clang/include/clang/Lex/Preprocessor.h @@ -1682,12 +1682,26 @@ const FileEntry *LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled, const DirectoryLookup *FromDir, const FileEntry *FromFile, - const DirectoryLookup *&CurDir, + const DirectoryLookup *&CurDir, bool &IsMapped, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, ModuleMap::KnownHeader *SuggestedModule, bool SkipCache = false); + const FileEntry *LookupFile(SourceLocation FilenameLoc, StringRef Filename, + bool isAngled, const DirectoryLookup *FromDir, + const FileEntry *FromFile, + const DirectoryLookup *&CurDir, + SmallVectorImpl *SearchPath, + SmallVectorImpl *RelativePath, + ModuleMap::KnownHeader *SuggestedModule, + bool SkipCache = false) { + bool IsMapped = false; + return LookupFile(FilenameLoc, Filename, isAngled, FromDir, FromFile, + CurDir, IsMapped, SearchPath, RelativePath, + SuggestedModule, SkipCache); + } + /// \brief Get the DirectoryLookup structure used to find the current /// FileEntry, if CurLexer is non-null and if applicable. /// Index: clang/lib/Lex/HeaderSearch.cpp =================================================================== --- clang/lib/Lex/HeaderSearch.cpp +++ clang/lib/Lex/HeaderSearch.cpp @@ -621,10 +621,12 @@ const FileEntry *HeaderSearch::LookupFile( StringRef Filename, SourceLocation IncludeLoc, bool isAngled, const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir, + bool &IsMapped, ArrayRef> Includers, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool SkipCache, bool BuildSystemModule) { + IsMapped = false; if (SuggestedModule) *SuggestedModule = ModuleMap::KnownHeader(); @@ -754,8 +756,10 @@ if (!SkipCache && CacheLookup.StartIdx == i+1) { // Skip querying potentially lots of directories for this lookup. i = CacheLookup.HitIdx; - if (CacheLookup.MappedName) + if (CacheLookup.MappedName) { Filename = CacheLookup.MappedName; + IsMapped = true; + } } else { // Otherwise, this is the first query, or the previous query didn't match // our search start. We will fill in our found location below, so prime the @@ -774,6 +778,7 @@ SuggestedModule, InUserSpecifiedSystemFramework, HasBeenMapped, MappedName); if (HasBeenMapped) { + IsMapped = true; CacheLookup.MappedName = copyString(Filename, LookupFileCache.getAllocator()); } @@ -838,8 +843,8 @@ const FileEntry *FE = LookupFile(ScratchFilename, IncludeLoc, /*isAngled=*/true, FromDir, - CurDir, Includers.front(), SearchPath, RelativePath, - RequestingModule, SuggestedModule); + CurDir, IsMapped, Includers.front(), SearchPath, + RelativePath, RequestingModule, SuggestedModule); if (checkMSVCHeaderSearch(Diags, MSFE, FE, IncludeLoc)) { if (SuggestedModule) Index: clang/lib/Lex/PPDirectives.cpp =================================================================== --- clang/lib/Lex/PPDirectives.cpp +++ clang/lib/Lex/PPDirectives.cpp @@ -758,6 +758,7 @@ const DirectoryLookup *FromDir, const FileEntry *FromFile, const DirectoryLookup *&CurDir, + bool &IsMapped, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, ModuleMap::KnownHeader *SuggestedModule, @@ -834,8 +835,8 @@ // Do a standard file entry lookup. const FileEntry *FE = HeaderInfo.LookupFile( - Filename, FilenameLoc, isAngled, FromDir, CurDir, Includers, SearchPath, - RelativePath, RequestingModule, SuggestedModule, SkipCache, + Filename, FilenameLoc, isAngled, FromDir, CurDir, IsMapped, Includers, + SearchPath, RelativePath, RequestingModule, SuggestedModule, SkipCache, BuildSystemModule); if (FE) { if (SuggestedModule && !LangOpts.AsmPreprocessor) @@ -1783,6 +1784,7 @@ } // Search include directories. + bool IsMapped = false; const DirectoryLookup *CurDir; SmallString<1024> SearchPath; SmallString<1024> RelativePath; @@ -1799,7 +1801,7 @@ } const FileEntry *File = LookupFile( FilenameLoc, LangOpts.MSVCCompat ? NormalizedPath.c_str() : Filename, - isAngled, LookupFrom, LookupFromFile, CurDir, + isAngled, LookupFrom, LookupFromFile, CurDir, IsMapped, Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr, &SuggestedModule); @@ -1817,7 +1819,7 @@ File = LookupFile( FilenameLoc, LangOpts.MSVCCompat ? NormalizedPath.c_str() : Filename, isAngled, - LookupFrom, LookupFromFile, CurDir, nullptr, nullptr, + LookupFrom, LookupFromFile, CurDir, IsMapped, nullptr, nullptr, &SuggestedModule, /*SkipCache*/ true); } } @@ -1831,7 +1833,7 @@ File = LookupFile( FilenameLoc, LangOpts.MSVCCompat ? NormalizedPath.c_str() : Filename, false, - LookupFrom, LookupFromFile, CurDir, + LookupFrom, LookupFromFile, CurDir, IsMapped, Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr, &SuggestedModule); @@ -1964,7 +1966,7 @@ // Issue a diagnostic if the name of the file on disk has a different case // than the one we're about to open. const bool CheckIncludePathPortability = - File && !File->tryGetRealPathName().empty(); + !IsMapped && File && !File->tryGetRealPathName().empty(); if (CheckIncludePathPortability) { StringRef Name = LangOpts.MSVCCompat ? NormalizedPath.str() : Filename; Index: clang/test/Preprocessor/nonportable-include-with-hmap.c =================================================================== --- /dev/null +++ clang/test/Preprocessor/nonportable-include-with-hmap.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -Eonly \ +// RUN: -I%S/Inputs/nonportable-hmaps/foo.hmap \ +// RUN: -I%S/Inputs/nonportable-hmaps \ +// RUN: %s -verify +// +// foo.hmap contains: Foo/Foo.h -> headers/foo/Foo.h +// +// Header search of "Foo/Foo.h" follows this path: +// 1. Look for "Foo/Foo.h". +// 2. Find "Foo/Foo.h" in "nonportable-hmaps/foo.hmap". +// 3. Look for "headers/foo/Foo.h". +// 4. Find "headers/foo/Foo.h" in "nonportable-hmaps". +// 5. Return. +// +// There is nothing nonportable; -Wnonportable-include-path should not fire. +#include "Foo/Foo.h" // expected-no-diagnostics