-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clang] Don't fail ExecuteCompilerInvocation()
due to caller errors
#158695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: Jan Svoboda (jansvoboda11) ChangesThis PR changes the behavior of Full diff: https://github.com/llvm/llvm-project/pull/158695.diff 1 Files Affected:
diff --git a/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index 9a6844d5f7d40..f1965a4e27e07 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(
@@ -293,7 +295,7 @@ bool ExecuteCompilerInvocation(CompilerInstance *Clang) {
#endif
// If there were errors in processing arguments, don't do anything else.
- if (Clang->getDiagnostics().hasErrorOccurred())
+ if (Clang->getDiagnostics().getNumErrors() != NumErrorsBefore)
return false;
// Create and execute the frontend action.
std::unique_ptr<FrontendAction> Act(CreateFrontendAction(*Clang));
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add more comment to explain when do we actually call this function when Diagnostics Engine already has error? This will help to evaluate what is a right thing to do.
Currently we don't, but with #158381 we'll try to initialize the VFS overlays before calling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you summarize the reason and leave a comment in the code?
clang::ExecuteCompilerInvocation()
for unrelated errorsclang::ExecuteCompilerInvocation()
for caller errors
clang::ExecuteCompilerInvocation()
for caller errorsExecuteCompilerInvocation()
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.
…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.
This PR changes the behavior of
clang::ExecuteCompilerInvocation()
so that it only returns early when theDiagnosticsEngine
emitted errors within the function. Handling errors emitted before the function got called is a responsibility of the caller. Necessary for #158381.