Index: include/clang/Lex/HeaderSearch.h
===================================================================
--- include/clang/Lex/HeaderSearch.h	(revision 144239)
+++ include/clang/Lex/HeaderSearch.h	(working copy)
@@ -199,6 +199,15 @@
     //LookupFileCache.clear();
   }
 
+  /// AddSearchPath - Add an additional search path.
+  void AddSearchPath(const DirectoryLookup &dir, bool isAngled) {
+    std::vector<DirectoryLookup>::iterator it = SearchDirs.begin();
+    SearchDirs.insert(isAngled ? it + SystemDirIdx : it + AngledDirIdx, dir);
+    if (!isAngled)
+      AngledDirIdx++;
+    SystemDirIdx++;
+  }
+
   /// \brief Set the path to the module cache and the name of the module
   /// we're building
   void configureModules(StringRef CachePath, StringRef BuildingModule) {
@@ -255,7 +264,8 @@
                               const FileEntry *CurFileEnt,
                               SmallVectorImpl<char> *SearchPath,
                               SmallVectorImpl<char> *RelativePath,
-                              StringRef *SuggestedModule);
+                              StringRef *SuggestedModule,
+                              bool SkipCache = false);
 
   /// LookupSubframeworkHeader - Look up a subframework for the specified
   /// #include file.  For example, if #include'ing <HIToolbox/HIToolbox.h> from
Index: include/clang/Lex/PPCallbacks.h
===================================================================
--- include/clang/Lex/PPCallbacks.h	(revision 144239)
+++ include/clang/Lex/PPCallbacks.h	(working copy)
@@ -91,6 +91,9 @@
   ///
   /// \param RelativePath The path relative to SearchPath, at which the include
   /// file was found. This is equal to FileName except for framework includes.
+  ///
+  /// \param RecoveryPath If File is null the client may recover from the
+  /// failure by supplying an additional search path in RecoveryPath.
   virtual void InclusionDirective(SourceLocation HashLoc,
                                   const Token &IncludeTok,
                                   StringRef FileName,
@@ -98,7 +101,8 @@
                                   const FileEntry *File,
                                   SourceLocation EndLoc,
                                   StringRef SearchPath,
-                                  StringRef RelativePath) {
+                                  StringRef RelativePath,
+                                  SmallVectorImpl<char> &RecoveryPath) {
   }
 
   /// EndOfMainFile - This callback is invoked when the end of the main file is
@@ -238,11 +242,12 @@
                                   const FileEntry *File,
                                   SourceLocation EndLoc,
                                   StringRef SearchPath,
-                                  StringRef RelativePath) {
+                                  StringRef RelativePath,
+                                  SmallVectorImpl<char> &RecoveryPath) {
     First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, File,
-                              EndLoc, SearchPath, RelativePath);
+                              EndLoc, SearchPath, RelativePath, RecoveryPath);
     Second->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, File,
-                               EndLoc, SearchPath, RelativePath);
+                               EndLoc, SearchPath, RelativePath, RecoveryPath);
   }
 
   virtual void EndOfMainFile() {
Index: include/clang/Lex/PreprocessingRecord.h
===================================================================
--- include/clang/Lex/PreprocessingRecord.h	(revision 144239)
+++ include/clang/Lex/PreprocessingRecord.h	(working copy)
@@ -545,7 +545,8 @@
                                     const FileEntry *File,
                                     SourceLocation EndLoc,
                                     StringRef SearchPath,
-                                    StringRef RelativePath);
+                                    StringRef RelativePath,
+                                    SmallVectorImpl<char> &RecoveryPath);
 
   private:
     /// \brief Cached result of the last \see getPreprocessedEntitiesInRange
Index: include/clang/Lex/Preprocessor.h
===================================================================
--- include/clang/Lex/Preprocessor.h	(revision 144239)
+++ include/clang/Lex/Preprocessor.h	(working copy)
@@ -1008,7 +1008,8 @@
                               const DirectoryLookup *&CurDir,
                               SmallVectorImpl<char> *SearchPath,
                               SmallVectorImpl<char> *RelativePath,
-                              StringRef *SuggestedModule);
+                              StringRef *SuggestedModule,
+                              bool SkipCache = false);
 
   /// GetCurLookup - The DirectoryLookup structure used to find the current
   /// FileEntry, if CurLexer is non-null and if applicable.  This allows us to
Index: tools/libclang/Indexing.cpp
===================================================================
--- tools/libclang/Indexing.cpp	(revision 144239)
+++ tools/libclang/Indexing.cpp	(working copy)
@@ -52,7 +52,8 @@
                                   const FileEntry *File,
                                   SourceLocation EndLoc,
                                   StringRef SearchPath,
-                                  StringRef RelativePath) {
+                                  StringRef RelativePath,
+                                  SmallVectorImpl<char> &RecoveryPath) {
     bool isImport = (IncludeTok.is(tok::identifier) &&
             IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import);
     IndexCtx.ppIncludedFile(HashLoc, FileName, File, isImport, IsAngled);
Index: lib/Frontend/DependencyFile.cpp
===================================================================
--- lib/Frontend/DependencyFile.cpp	(revision 144239)
+++ lib/Frontend/DependencyFile.cpp	(working copy)
@@ -61,7 +61,8 @@
                                   const FileEntry *File,
                                   SourceLocation EndLoc,
                                   StringRef SearchPath,
-                                  StringRef RelativePath);
+                                  StringRef RelativePath,
+                                  SmallVectorImpl<char> &RecoveryPath);
 
   virtual void EndOfMainFile() {
     OutputDependencyFile();
@@ -144,7 +145,8 @@
                                                 const FileEntry *File,
                                                 SourceLocation EndLoc,
                                                 StringRef SearchPath,
-                                                StringRef RelativePath) {
+                                                StringRef RelativePath,
+                                                SmallVectorImpl<char> &) {
   if (AddMissingHeaderDeps && !File)
     AddFilename(FileName);
 }
Index: lib/Lex/PPDirectives.cpp
===================================================================
--- lib/Lex/PPDirectives.cpp	(revision 144239)
+++ lib/Lex/PPDirectives.cpp	(working copy)
@@ -486,7 +486,8 @@
     const DirectoryLookup *&CurDir,
     SmallVectorImpl<char> *SearchPath,
     SmallVectorImpl<char> *RelativePath,
-    StringRef *SuggestedModule) {
+    StringRef *SuggestedModule,
+    bool SkipCache) {
   // If the header lookup mechanism may be relative to the current file, pass in
   // info about where the current file is.
   const FileEntry *CurFileEnt = 0;
@@ -510,7 +511,7 @@
   CurDir = CurDirLookup;
   const FileEntry *FE = HeaderInfo.LookupFile(
       Filename, isAngled, FromDir, CurDir, CurFileEnt,
-      SearchPath, RelativePath, SuggestedModule);
+      SearchPath, RelativePath, SuggestedModule, SkipCache);
   if (FE) return FE;
 
   // Otherwise, see if this is a subframework header.  If so, this is relative
@@ -1285,10 +1286,25 @@
   }
   
   // Notify the callback object that we've seen an inclusion directive.
-  if (Callbacks)
+  if (Callbacks) {
+    llvm::SmallString<128> RecoveryPath;
     Callbacks->InclusionDirective(HashLoc, IncludeTok, Filename, isAngled, File,
-                                  End, SearchPath, RelativePath);
+                                  End, SearchPath, RelativePath, RecoveryPath);
 
+    if (!File && !RecoveryPath.empty()) {
+      if (const DirectoryEntry *DE = FileMgr.getDirectory(RecoveryPath)) {
+        // Add the recovery path to the list of search paths.
+        DirectoryLookup DL(DE, SrcMgr::C_User, true, false);
+        HeaderInfo.AddSearchPath(DL, isAngled);
+        
+        // Try the lookup again skipping the cache.
+        File = LookupFile(Filename, isAngled, LookupFrom, CurDir, NULL, NULL,
+                          AutoModuleImport? &SuggestedModule : 0,
+                          /*SkipCache*/true);
+      }
+    }
+  }
+
   if (File == 0) {
     if (!SuppressIncludeNotFoundError)
       Diag(FilenameTok, diag::err_pp_file_not_found) << Filename;
Index: lib/Lex/HeaderSearch.cpp
===================================================================
--- lib/Lex/HeaderSearch.cpp	(revision 144239)
+++ lib/Lex/HeaderSearch.cpp	(working copy)
@@ -334,7 +334,8 @@
     const FileEntry *CurFileEnt,
     SmallVectorImpl<char> *SearchPath,
     SmallVectorImpl<char> *RelativePath,
-    StringRef *SuggestedModule) 
+    StringRef *SuggestedModule,
+    bool SkipCache) 
 {
   if (SuggestedModule)
     *SuggestedModule = StringRef();
@@ -410,7 +411,7 @@
   // If the entry has been previously looked up, the first value will be
   // non-zero.  If the value is equal to i (the start point of our search), then
   // this is a matching hit.
-  if (CacheLookup.first == i+1) {
+  if (!SkipCache && CacheLookup.first == i+1) {
     // Skip querying potentially lots of directories for this lookup.
     i = CacheLookup.second;
   } else {
Index: lib/Lex/PreprocessingRecord.cpp
===================================================================
--- lib/Lex/PreprocessingRecord.cpp	(revision 144239)
+++ lib/Lex/PreprocessingRecord.cpp	(working copy)
@@ -368,7 +368,8 @@
     const FileEntry *File,
     clang::SourceLocation EndLoc,
     StringRef SearchPath,
-    StringRef RelativePath) {
+    StringRef RelativePath,
+    SmallVectorImpl<char> &RecoveryPath) {
   InclusionDirective::InclusionKind Kind = InclusionDirective::Include;
   
   switch (IncludeTok.getIdentifierInfo()->getPPKeywordID()) {
