<div dir="ltr">Is it possible to write a test for this?</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 17, 2016 at 10:34 AM, Cameron Desrochers via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: cameron314<br>
Date: Tue May 17 09:34:53 2016<br>
New Revision: 269769<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=269769&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=269769&view=rev</a><br>
Log:<br>
[PCH] Fixed bug with preamble invalidation when overridden files change<br>
<br>
When remapped files were changed, they would not always cause the preamble's PCH to be invalidated, because the remapped path didn't necessarily match the include path (e.g. slash direction -- this happens a lot on Windows). I fixed this by moving to a llvm::sys::fs::UniqueID-based map instead of comparing paths stringwise.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D20137" rel="noreferrer" target="_blank">http://reviews.llvm.org/D20137</a><br>
<br>
Modified:<br>
    cfe/trunk/lib/Frontend/ASTUnit.cpp<br>
<br>
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=269769&r1=269768&r2=269769&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=269769&r1=269768&r2=269769&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)<br>
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Tue May 17 09:34:53 2016<br>
@@ -1378,7 +1378,7 @@ ASTUnit::getMainBufferWithPrecompiledPre<br>
<br>
       // First, make a record of those files that have been overridden via<br>
       // remapping or unsaved_files.<br>
-      llvm::StringMap<PreambleFileHash> OverriddenFiles;<br>
+      std::map<llvm::sys::fs::UniqueID, PreambleFileHash> OverriddenFiles;<br>
       for (const auto &R : PreprocessorOpts.RemappedFiles) {<br>
         if (AnyFileChanged)<br>
           break;<br>
@@ -1391,24 +1391,38 @@ ASTUnit::getMainBufferWithPrecompiledPre<br>
           break;<br>
         }<br>
<br>
-        OverriddenFiles[R.first] = PreambleFileHash::createForFile(<br>
+        OverriddenFiles[Status.getUniqueID()] = PreambleFileHash::createForFile(<br>
             Status.getSize(), Status.getLastModificationTime().toEpochTime());<br>
       }<br>
<br>
       for (const auto &RB : PreprocessorOpts.RemappedFileBuffers) {<br>
         if (AnyFileChanged)<br>
           break;<br>
-        OverriddenFiles[RB.first] =<br>
+<br>
+        vfs::Status Status;<br>
+        if (FileMgr->getNoncachedStatValue(RB.first, Status)) {<br>
+          AnyFileChanged = true;<br>
+          break;<br>
+        }<br>
+<br>
+        OverriddenFiles[Status.getUniqueID()] =<br>
             PreambleFileHash::createForMemoryBuffer(RB.second);<br>
       }<br>
<br>
       // Check whether anything has changed.<br>
-      for (llvm::StringMap<PreambleFileHash>::iterator<br>
+      for (llvm::StringMap<PreambleFileHash>::iterator<br>
              F = FilesInPreamble.begin(), FEnd = FilesInPreamble.end();<br>
            !AnyFileChanged && F != FEnd;<br>
            ++F) {<br>
-        llvm::StringMap<PreambleFileHash>::iterator Overridden<br>
-          = OverriddenFiles.find(F->first());<br>
+        vfs::Status Status;<br>
+        if (FileMgr->getNoncachedStatValue(F->first(), Status)) {<br>
+          // If we can't stat the file, assume that something horrible happened.<br>
+          AnyFileChanged = true;<br>
+          break;<br>
+        }<br>
+<br>
+        std::map<llvm::sys::fs::UniqueID, PreambleFileHash>::iterator Overridden<br>
+          = OverriddenFiles.find(Status.getUniqueID());<br>
         if (Overridden != OverriddenFiles.end()) {<br>
           // This file was remapped; check whether the newly-mapped file<br>
           // matches up with the previous mapping.<br>
@@ -1418,13 +1432,9 @@ ASTUnit::getMainBufferWithPrecompiledPre<br>
         }<br>
<br>
         // The file was not remapped; check whether it has changed on disk.<br>
-        vfs::Status Status;<br>
-        if (FileMgr->getNoncachedStatValue(F->first(), Status)) {<br>
-          // If we can't stat the file, assume that something horrible happened.<br>
-          AnyFileChanged = true;<br>
-        } else if (Status.getSize() != uint64_t(F->second.Size) ||<br>
-                   Status.getLastModificationTime().toEpochTime() !=<br>
-                       uint64_t(F->second.ModTime))<br>
+        if (Status.getSize() != uint64_t(F->second.Size) ||<br>
+            Status.getLastModificationTime().toEpochTime() !=<br>
+                uint64_t(F->second.ModTime))<br>
           AnyFileChanged = true;<br>
       }<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>