diff --git a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp index 9a6844d5f7d40..8b0ab2eb37189 100644 --- a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp +++ b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp @@ -210,6 +210,8 @@ CreateFrontendAction(CompilerInstance &CI) { } bool ExecuteCompilerInvocation(CompilerInstance *Clang) { + unsigned NumErrorsBefore = Clang->getDiagnostics().getNumErrors(); + // Honor -help. if (Clang->getFrontendOpts().ShowHelp) { driver::getDriverOptTable().printHelp( @@ -292,9 +294,12 @@ bool ExecuteCompilerInvocation(CompilerInstance *Clang) { } #endif - // If there were errors in processing arguments, don't do anything else. - if (Clang->getDiagnostics().hasErrorOccurred()) + // If there were errors in the above, don't do anything else. + // This intentionally ignores errors emitted before this function to + // accommodate lenient callers that decided to make progress despite errors. + if (Clang->getDiagnostics().getNumErrors() != NumErrorsBefore) return false; + // Create and execute the frontend action. std::unique_ptr Act(CreateFrontendAction(*Clang)); if (!Act)