diff --git a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp index 918f7c968ef90..008da47164092 100644 --- a/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp +++ b/clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp @@ -108,10 +108,18 @@ class Action : public clang::ASTFrontendAction { } void EndSourceFile() override { + const auto &SM = getCompilerInstance().getSourceManager(); + if (SM.getDiagnostics().hasUncompilableErrorOccurred()) { + llvm::errs() + << "Skipping file " << getCurrentFile() + << " due to compiler errors. clang-include-cleaner expects to " + "work on compilable source code.\n"; + return; + } + if (!HTMLReportPath.empty()) writeHTML(); - const auto &SM = getCompilerInstance().getSourceManager(); auto &HS = getCompilerInstance().getPreprocessor().getHeaderSearchInfo(); llvm::StringRef Path = SM.getFileEntryForID(SM.getMainFileID())->tryGetRealPathName();