Skip to content

Commit f33fb0d

Browse files
authored
[clang] Don't fail ExecuteCompilerInvocation() due to caller errors (llvm#158695)
This PR changes the behavior of `clang::ExecuteCompilerInvocation()` so that it only returns early when the `DiagnosticsEngine` emitted errors **within** the function. Handling errors emitted before the function got called is a responsibility of the caller. Necessary for llvm#158381.
1 parent 1b1dce1 commit f33fb0d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ CreateFrontendAction(CompilerInstance &CI) {
210210
}
211211

212212
bool ExecuteCompilerInvocation(CompilerInstance *Clang) {
213+
unsigned NumErrorsBefore = Clang->getDiagnostics().getNumErrors();
214+
213215
// Honor -help.
214216
if (Clang->getFrontendOpts().ShowHelp) {
215217
driver::getDriverOptTable().printHelp(
@@ -292,9 +294,12 @@ bool ExecuteCompilerInvocation(CompilerInstance *Clang) {
292294
}
293295
#endif
294296

295-
// If there were errors in processing arguments, don't do anything else.
296-
if (Clang->getDiagnostics().hasErrorOccurred())
297+
// If there were errors in the above, don't do anything else.
298+
// This intentionally ignores errors emitted before this function to
299+
// accommodate lenient callers that decided to make progress despite errors.
300+
if (Clang->getDiagnostics().getNumErrors() != NumErrorsBefore)
297301
return false;
302+
298303
// Create and execute the frontend action.
299304
std::unique_ptr<FrontendAction> Act(CreateFrontendAction(*Clang));
300305
if (!Act)

0 commit comments

Comments
 (0)