Author: Haojian Wu Date: 2023-06-20T09:07:27+02:00 New Revision: ab32cc6c02f539bc87e71fefc9670f28a7fc7f56
URL: https://github.com/llvm/llvm-project/commit/ab32cc6c02f539bc87e71fefc9670f28a7fc7f56 DIFF: https://github.com/llvm/llvm-project/commit/ab32cc6c02f539bc87e71fefc9670f28a7fc7f56.diff LOG: [include-cleaner] Bailout on invalid code for the command-line tool The binary tool only works on working source code, if the source code is not compilable, don't perform any analysis and edits. Differential Revision: https://reviews.llvm.org/D153271 Added: Modified: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp Removed: ################################################################################ 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(); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits