[PATCH] D153271: [include-cleaner] Bailout on invalid code for the command-line tool

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 19 05:59:24 PDT 2023


hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang-tools-extra.

The binary tool only works on working source code, if the source code is
not compilable, don't perform any analysis and edits.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153271

Files:
  clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp


Index: clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
===================================================================
--- clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
+++ clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
@@ -108,10 +108,18 @@
   }
 
   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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153271.532622.patch
Type: text/x-patch
Size: 969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230619/4f998c2d/attachment.bin>


More information about the cfe-commits mailing list