Bail when an unrecoverable error has been detected.

If for example an include file is not found, iwyu should not continue
to run because it would be working with a garbage ast.
This commit is contained in:
Tom Rix 2018-12-30 08:19:30 -08:00 committed by Kim Gräsman
parent 9945e543d8
commit 4909f206b4
1 changed files with 12 additions and 1 deletions

13
iwyu.cc
View File

@ -3596,7 +3596,18 @@ class IwyuAstConsumer
ParseFunctionTemplates(context.getTranslationUnitDecl());
TraverseDecl(context.getTranslationUnitDecl());
// Check if any unrecoverable errors have occurred.
// There is no point in continuing when the AST is in a bad state.
//
// EXIT_INVALIDARGS is not a great choice for the return status
// because a compile error will not have a strong connection to the
// command line arguments, but there are only 2 error codes and
// this is the least bad choice.
// TODO : Readdress when error codes are reworked.
if (compiler()->getDiagnostics().hasUnrecoverableErrorOccurred())
exit(EXIT_INVALIDARGS);
const set<const FileEntry*>* const files_to_report_iwyu_violations_for
= preprocessor_info().files_to_report_iwyu_violations_for();