Index: include/clang/Basic/Diagnostic.h =================================================================== --- include/clang/Basic/Diagnostic.h +++ include/clang/Basic/Diagnostic.h @@ -618,6 +618,8 @@ /// a fatal error. void setSuppressAfterFatalError(bool Val) { SuppressAfterFatalError = Val; } + bool getSuppressAfterFatalError() { return SuppressAfterFatalError; } + /// When set to true mask warnings that come from system headers. void setSuppressSystemWarnings(bool Val) { GetCurDiagState()->SuppressSystemWarnings = Val; Index: include/clang/Basic/DiagnosticLexKinds.td =================================================================== --- include/clang/Basic/DiagnosticLexKinds.td +++ include/clang/Basic/DiagnosticLexKinds.td @@ -399,6 +399,7 @@ def err_pp_directive_required : Error< "%0 must be used within a preprocessing directive">; def err_pp_file_not_found : Error<"'%0' file not found">, DefaultFatal; +def err_pp_file_not_found_keep_going : Error<"'%0' file not found">; def err_pp_through_header_not_found : Error< "'%0' required for precompiled header not found">, DefaultFatal; def err_pp_through_header_not_seen : Error< Index: include/clang/Lex/PreprocessorOptions.h =================================================================== --- include/clang/Lex/PreprocessorOptions.h +++ include/clang/Lex/PreprocessorOptions.h @@ -142,6 +142,12 @@ /// compiler invocation and its buffers will be reused. bool RetainRemappedFileBuffers = false; + /// Whether to emit normal error instead of fatal in case the include is + /// missing. This should help to provide more meaningful information for the + /// code that uses data from the following headers which are ignored + /// otherwise. + bool KeepGoingAfterMissingInclude = false; + /// The Objective-C++ ARC standard library that we should support, /// by providing appropriate definitions to retrofit the standard library /// with support for lifetime-qualified pointers. Index: lib/Frontend/ASTUnit.cpp =================================================================== --- lib/Frontend/ASTUnit.cpp +++ lib/Frontend/ASTUnit.cpp @@ -1735,6 +1735,7 @@ PPOpts.RemappedFilesKeepOriginalName = RemappedFilesKeepOriginalName; PPOpts.AllowPCHWithCompilerErrors = AllowPCHWithCompilerErrors; PPOpts.SingleFileParseMode = SingleFileParse; + PPOpts.KeepGoingAfterMissingInclude = !Diags->getSuppressAfterFatalError(); // Override the resources path. CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath; Index: lib/Lex/PPDirectives.cpp =================================================================== --- lib/Lex/PPDirectives.cpp +++ lib/Lex/PPDirectives.cpp @@ -1866,8 +1866,10 @@ // If the file is still not found, just go with the vanilla diagnostic if (!File) { - Diag(FilenameTok, diag::err_pp_file_not_found) << OriginalFilename - << FilenameRange; + Diag(FilenameTok, PPOpts->KeepGoingAfterMissingInclude + ? diag::err_pp_file_not_found_keep_going + : diag::err_pp_file_not_found) + << OriginalFilename << FilenameRange; if (IsFrameworkFound) { size_t SlashPos = OriginalFilename.find('/'); assert(SlashPos != StringRef::npos && Index: lib/Lex/Pragma.cpp =================================================================== --- lib/Lex/Pragma.cpp +++ lib/Lex/Pragma.cpp @@ -29,6 +29,7 @@ #include "clang/Lex/ModuleLoader.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Lex/PreprocessorOptions.h" #include "clang/Lex/PreprocessorLexer.h" #include "clang/Lex/Token.h" #include "clang/Lex/TokenLexer.h" @@ -508,8 +509,12 @@ LookupFile(FilenameTok.getLocation(), Filename, isAngled, nullptr, nullptr, CurDir, nullptr, nullptr, nullptr, nullptr, nullptr); if (!File) { - if (!SuppressIncludeNotFoundError) - Diag(FilenameTok, diag::err_pp_file_not_found) << Filename; + if (!SuppressIncludeNotFoundError) { + Diag(FilenameTok, PPOpts->KeepGoingAfterMissingInclude + ? diag::err_pp_file_not_found_keep_going + : diag::err_pp_file_not_found) + << Filename; + } return; }