<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Mar 11, 2014, at 7:48 AM, NAKAMURA Takumi <<a href="mailto:geek4civic@gmail.com">geek4civic@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">2014-03-11 15:21 GMT+09:00 Argyrios Kyrtzidis <<a href="mailto:akyrtzi@gmail.com">akyrtzi@gmail.com</a>>:<br><blockquote type="cite">Author: akirtzidis<br>Date: Tue Mar 11 01:21:28 2014<br>New Revision: 203542<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=203542&view=rev">http://llvm.org/viewvc/llvm-project?rev=203542&view=rev</a><br>Log:<br>[HeaderSearch] Fix issue where if a headermap entry maps the filename to a framework import (non-absolute path)<br>then we fail to find it if it is re-included later on.<br><br><a href="rdar://16285490">rdar://16285490</a><br><br>Modified:<br>   cfe/trunk/include/clang/Lex/DirectoryLookup.h<br>   cfe/trunk/include/clang/Lex/HeaderSearch.h<br>   cfe/trunk/lib/Lex/HeaderSearch.cpp<br>   cfe/trunk/test/Preprocessor/headermap-rel.c<br><br>Modified: cfe/trunk/include/clang/Lex/DirectoryLookup.h<br>URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/DirectoryLookup.h?rev=203542&r1=203541&r2=203542&view=diff<br>==============================================================================<br>--- cfe/trunk/include/clang/Lex/DirectoryLookup.h (original)<br>+++ cfe/trunk/include/clang/Lex/DirectoryLookup.h Tue Mar 11 01:21:28 2014<br>@@ -170,6 +170,7 @@ public:<br>                              SmallVectorImpl<char> *RelativePath,<br>                              ModuleMap::KnownHeader *SuggestedModule,<br>                              bool &InUserSpecifiedSystemFramework,<br>+                              bool &HasBeenMapped,<br>                              SmallVectorImpl<char> &MappedName) const;<br><br>private:<br><br>Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h<br>URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=203542&r1=203541&r2=203542&view=diff<br>==============================================================================<br>--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)<br>+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Tue Mar 11 01:21:28 2014<br>@@ -186,15 +186,19 @@ class HeaderSearch {<br>  /// included, indexed by the FileEntry's UID.<br>  std::vector<HeaderFileInfo> FileInfo;<br><br>-  /// \brief Keeps track of each lookup performed by LookupFile.<br>-  ///<br>-  /// The first part of the value is the starting index in SearchDirs<br>-  /// that the cached search was performed from.  If there is a hit and<br>-  /// this value doesn't match the current query, the cache has to be<br>-  /// ignored.  The second value is the entry in SearchDirs that satisfied<br>-  /// the query.<br>-  llvm::StringMap<std::pair<unsigned, unsigned>, llvm::BumpPtrAllocator><br>-    LookupFileCache;<br>+  /// Keeps track of each lookup performed by LookupFile.<br>+  struct LookupFileCacheInfo {<br>+    /// Starting index in SearchDirs that the cached search was performed from.<br>+    /// If there is a hit and this value doesn't match the current query, the<br>+    /// cache has to be ignored.<br>+    unsigned StartIdx = 0;<br>+    /// The entry in SearchDirs that satisfied the query.<br>+    unsigned HitIdx = 0;<br>+    /// This is non-null if the original filename was mapped to a framework<br>+    /// include via a headermap.<br>+    const char *MappedName = nullptr;<br>+  };<br></blockquote><br>Unfortunately, non-static member initializer is unavailable in msvc<br>2012. Fixed in r203554.<br></div></blockquote><div><br></div><div>Ah, thanks for taking care of it!</div><br><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br><blockquote type="cite">+  llvm::StringMap<LookupFileCacheInfo, llvm::BumpPtrAllocator> LookupFileCache;<br><br>  /// \brief Collection mapping a framework or subframework<br>  /// name like "Carbon" to the Carbon.framework directory.<br><br>Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=203542&r1=203541&r2=203542&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=203542&r1=203541&r2=203542&view=diff</a><br>==============================================================================<br>--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)<br>+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Tue Mar 11 01:21:28 2014<br>@@ -255,8 +255,10 @@ const FileEntry *DirectoryLookup::Lookup<br>    SmallVectorImpl<char> *RelativePath,<br>    ModuleMap::KnownHeader *SuggestedModule,<br>    bool &InUserSpecifiedSystemFramework,<br>+    bool &HasBeenMapped,<br>    SmallVectorImpl<char> &MappedName) const {<br>  InUserSpecifiedSystemFramework = false;<br>+  HasBeenMapped = false;<br><br>  SmallString<1024> TmpDir;<br>  if (isNormalDir()) {<br>@@ -298,6 +300,7 @@ const FileEntry *DirectoryLookup::Lookup<br>    MappedName.clear();<br>    MappedName.append(Dest.begin(), Dest.end());<br>    Filename = StringRef(MappedName.begin(), MappedName.size());<br>+    HasBeenMapped = true;<br>    Result = HM->LookupFile(Filename, HS.getFileMgr());<br><br>  } else {<br>@@ -533,6 +536,14 @@ static bool checkMSVCHeaderSearch(Diagno<br>  return false;<br>}<br><br>+static const char *copyString(StringRef Str, llvm::BumpPtrAllocator &Alloc) {<br>+  assert(!Str.empty());<br>+  char *CopyStr = Alloc.Allocate<char>(Str.size()+1);<br>+  std::copy(Str.begin(), Str.end(), CopyStr);<br>+  CopyStr[Str.size()] = '\0';<br>+  return CopyStr;<br>+}<br>+<br>/// LookupFile - Given a "foo" or \<foo> reference, look up the indicated file,<br>/// return null on failure.  isAngled indicates whether the file reference is<br>/// for system \#include's or not (i.e. using <> instead of ""). Includers, if<br>@@ -673,20 +684,22 @@ const FileEntry *HeaderSearch::LookupFil<br>  // multiply included, and the "pragma once" optimization prevents them from<br>  // being relex/pp'd, but they would still have to search through a<br>  // (potentially huge) series of SearchDirs to find it.<br>-  std::pair<unsigned, unsigned> &CacheLookup =<br>+  LookupFileCacheInfo &CacheLookup =<br>    LookupFileCache.GetOrCreateValue(Filename).getValue();<br><br>  // If the entry has been previously looked up, the first value will be<br>  // non-zero.  If the value is equal to i (the start point of our search), then<br>  // this is a matching hit.<br>-  if (!SkipCache && CacheLookup.first == i+1) {<br>+  if (!SkipCache && CacheLookup.StartIdx == i+1) {<br>    // Skip querying potentially lots of directories for this lookup.<br>-    i = CacheLookup.second;<br>+    i = CacheLookup.HitIdx;<br>+    if (CacheLookup.MappedName)<br>+      Filename = CacheLookup.MappedName;<br>  } else {<br>    // Otherwise, this is the first query, or the previous query didn't match<br>    // our search start.  We will fill in our found location below, so prime the<br>    // start point value.<br>-    CacheLookup.first = i+1;<br>+    CacheLookup.StartIdx = i+1;<br>  }<br><br>  SmallString<64> MappedName;<br>@@ -694,10 +707,15 @@ const FileEntry *HeaderSearch::LookupFil<br>  // Check each directory in sequence to see if it contains this file.<br>  for (; i != SearchDirs.size(); ++i) {<br>    bool InUserSpecifiedSystemFramework = false;<br>+    bool HasBeenMapped = false;<br>    const FileEntry *FE =<br>      SearchDirs[i].LookupFile(Filename, *this, SearchPath, RelativePath,<br>                               SuggestedModule, InUserSpecifiedSystemFramework,<br>-                               MappedName);<br>+                               HasBeenMapped, MappedName);<br>+    if (HasBeenMapped) {<br>+      CacheLookup.MappedName =<br>+          copyString(Filename, LookupFileCache.getAllocator());<br>+    }<br>    if (!FE) continue;<br><br>    CurDir = &SearchDirs[i];<br>@@ -740,7 +758,7 @@ const FileEntry *HeaderSearch::LookupFil<br>    }<br><br>    // Remember this location for the next lookup we do.<br>-    CacheLookup.second = i;<br>+    CacheLookup.HitIdx = i;<br>    return FE;<br>  }<br><br>@@ -767,10 +785,10 @@ const FileEntry *HeaderSearch::LookupFil<br>        return MSFE;<br>      }<br><br>-      std::pair<unsigned, unsigned> &CacheLookup<br>+      LookupFileCacheInfo &CacheLookup<br>        = LookupFileCache.GetOrCreateValue(Filename).getValue();<br>-      CacheLookup.second<br>-        = LookupFileCache.GetOrCreateValue(ScratchFilename).getValue().second;<br>+      CacheLookup.HitIdx<br>+        = LookupFileCache.GetOrCreateValue(ScratchFilename).getValue().HitIdx;<br>      // FIXME: SuggestedModule.<br>      return FE;<br>    }<br>@@ -783,7 +801,7 @@ const FileEntry *HeaderSearch::LookupFil<br>  }<br><br>  // Otherwise, didn't find it. Remember we didn't find this.<br>-  CacheLookup.second = SearchDirs.size();<br>+  CacheLookup.HitIdx = SearchDirs.size();<br>  return 0;<br>}<br><br><br>Modified: cfe/trunk/test/Preprocessor/headermap-rel.c<br>URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/headermap-rel.c?rev=203542&r1=203541&r2=203542&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/headermap-rel.c?rev=203542&r1=203541&r2=203542&view=diff</a><br>==============================================================================<br>--- cfe/trunk/test/Preprocessor/headermap-rel.c (original)<br>+++ cfe/trunk/test/Preprocessor/headermap-rel.c Tue Mar 11 01:21:28 2014<br>@@ -6,5 +6,7 @@<br>// RUN: FileCheck %s -input-file %t.i<br><br>// CHECK: Foo.h is parsed<br>+// CHECK: Foo.h is parsed<br><br>#include "Foo.h"<br>+#include "Foo.h"<br><br><br>_______________________________________________<br>cfe-commits mailing list<br><a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</blockquote></div></blockquote></div><br></body></html>