aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2025-09-15 14:30:13 -0700
committerGitHub <noreply@github.com>2025-09-15 14:30:13 -0700
commitf33fb0d7b2af203c42d0e7096b29560dda3e71ce (patch)
tree478ec242481ba8937d73a37eb59b799d92567374 /clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
parent1b1dce17d54b69149fa383d02119536908fd1767 (diff)
downloadllvm-f33fb0d7b2af203c42d0e7096b29560dda3e71ce.zip
llvm-f33fb0d7b2af203c42d0e7096b29560dda3e71ce.tar.gz
llvm-f33fb0d7b2af203c42d0e7096b29560dda3e71ce.tar.bz2
[clang] Don't fail `ExecuteCompilerInvocation()` due to caller errors (#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 #158381.
Diffstat (limited to 'clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp')
-rw-r--r--clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index 9a6844d..8b0ab2e 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<FrontendAction> Act(CreateFrontendAction(*Clang));
if (!Act)