Skip to content

Commit

Permalink
[include-cleaner] Bailout on invalid code for the command-line tool
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hokein committed Jun 20, 2023
1 parent 18ec203 commit ab32cc6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit ab32cc6

Please sign in to comment.