teach RemoveDuplicates about header maps.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45090 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index 4f6ea92..5e102b9 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -676,15 +676,30 @@
 /// search list, remove the later (dead) ones.
 static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList) {
   llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
+  llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
   for (unsigned i = 0; i != SearchList.size(); ++i) {
-    // If this isn't the first time we've seen this dir, remove it.
-    if (!SeenDirs.insert(SearchList[i].getDir())) {
+    if (SearchList[i].isNormalDir()) {
+      // If this isn't the first time we've seen this dir, remove it.
+      if (SeenDirs.insert(SearchList[i].getDir()))
+        continue;
+      
       if (Verbose)
         fprintf(stderr, "ignoring duplicate directory \"%s\"\n",
                 SearchList[i].getDir()->getName());
-      SearchList.erase(SearchList.begin()+i);
-      --i;
+    } else {
+      assert(SearchList[i].isHeaderMap() && "Not a headermap or normal dir?");
+      // If this isn't the first time we've seen this headermap, remove it.
+      if (SeenHeaderMaps.insert(SearchList[i].getHeaderMap()))
+        continue;
+      
+      if (Verbose)
+        fprintf(stderr, "ignoring duplicate directory \"%s\"\n",
+                SearchList[i].getDir()->getName());
     }
+    
+    // This is reached if the current entry is a duplicate.
+    SearchList.erase(SearchList.begin()+i);
+    --i;
   }
 }