diff options
| -rw-r--r-- | clang-tools-extra/include-fixer/IncludeFixer.cpp | 9 | ||||
| -rw-r--r-- | clang-tools-extra/include-fixer/tool/ClangIncludeFixer.cpp | 6 | ||||
| -rw-r--r-- | clang-tools-extra/test/include-fixer/exit_on_fatal.cpp | 11 |
3 files changed, 23 insertions, 3 deletions
diff --git a/clang-tools-extra/include-fixer/IncludeFixer.cpp b/clang-tools-extra/include-fixer/IncludeFixer.cpp index f64aedcbbe9..d7019128834 100644 --- a/clang-tools-extra/include-fixer/IncludeFixer.cpp +++ b/clang-tools-extra/include-fixer/IncludeFixer.cpp @@ -390,6 +390,10 @@ bool IncludeFixerActionFactory::runInvocation( /*ShouldOwnClient=*/true); Compiler.createSourceManager(*Files); + // We abort on fatal errors so don't let a large number of errors become + // fatal. A missing #include can cause thousands of errors. + Compiler.getDiagnostics().setErrorLimit(0); + // Run the parser, gather missing includes. auto ScopedToolAction = llvm::make_unique<Action>(SymbolIndexMgr, MinimizeIncludePaths); @@ -401,8 +405,9 @@ bool IncludeFixerActionFactory::runInvocation( Replacements); // Technically this should only return true if we're sure that we have a - // parseable file. We don't know that though. - return true; + // parseable file. We don't know that though. Only inform users of fatal + // errors. + return !Compiler.getDiagnostics().hasFatalErrorOccurred(); } } // namespace include_fixer diff --git a/clang-tools-extra/include-fixer/tool/ClangIncludeFixer.cpp b/clang-tools-extra/include-fixer/tool/ClangIncludeFixer.cpp index 541c4a77e4d..3416905098b 100644 --- a/clang-tools-extra/include-fixer/tool/ClangIncludeFixer.cpp +++ b/clang-tools-extra/include-fixer/tool/ClangIncludeFixer.cpp @@ -108,7 +108,11 @@ int includeFixerMain(int argc, const char **argv) { include_fixer::IncludeFixerActionFactory Factory( *SymbolIndexMgr, Replacements, MinimizeIncludePaths); - tool.run(&Factory); // Always succeeds. + if (tool.run(&Factory) != 0) { + llvm::errs() + << "Clang died with a fatal error! (incorrect include paths?)\n"; + return 1; + } if (!Quiet) for (const tooling::Replacement &Replacement : Replacements) diff --git a/clang-tools-extra/test/include-fixer/exit_on_fatal.cpp b/clang-tools-extra/test/include-fixer/exit_on_fatal.cpp new file mode 100644 index 00000000000..10a1af7bf1e --- /dev/null +++ b/clang-tools-extra/test/include-fixer/exit_on_fatal.cpp @@ -0,0 +1,11 @@ +// REQUIRES: shell +// RUN: sed -e 's#//.*$##' %s > %t.cpp +// RUN: not clang-include-fixer -db=fixed -input='foo= "foo.h"' %t.cpp -- +// RUN: FileCheck %s -input-file=%t.cpp + +// CHECK-NOT: #include +// CHECK: #include "doesnotexist.h" +// CHECK-NEXT: foo f; + +#include "doesnotexist.h" +foo f; |

