[clang][analyzer] Delay checking the ctu-dir (#150139)

This PR is part of an effort to remove file system usage from the
command line parsing code. The reason for that is that it's impossible
to do file system access correctly without a configured VFS, and the VFS
can only be configured after the command line is parsed. I don't want to
intertwine command line parsing and VFS configuration, so I decided to
perform the file system access after the command line is parsed and the
VFS is configured - ideally right before the file system entity is used
for the first time.

This patch delays checking that `ctu-dir` is an existing directory.
This commit is contained in:
Jan Svoboda
2025-09-02 11:39:26 -07:00
committed by GitHub
parent 95d3ecee82
commit 1fc090f7f1
2 changed files with 11 additions and 5 deletions

View File

@@ -13,6 +13,7 @@
#include "clang/AST/ASTImporter.h"
#include "clang/AST/Decl.h"
#include "clang/AST/ParentMapContext.h"
#include "clang/Basic/DiagnosticDriver.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/CrossTU/CrossTUDiagnostic.h"
#include "clang/Frontend/ASTUnit.h"
@@ -237,7 +238,16 @@ template <typename T> static bool hasBodyOrInit(const T *D) {
}
CrossTranslationUnitContext::CrossTranslationUnitContext(CompilerInstance &CI)
: Context(CI.getASTContext()), ASTStorage(CI) {}
: Context(CI.getASTContext()), ASTStorage(CI) {
if (CI.getAnalyzerOpts().ShouldEmitErrorsOnInvalidConfigValue &&
!CI.getAnalyzerOpts().CTUDir.empty()) {
auto S = CI.getVirtualFileSystem().status(CI.getAnalyzerOpts().CTUDir);
if (!S || S->getType() != llvm::sys::fs::file_type::directory_file)
CI.getDiagnostics().Report(diag::err_analyzer_config_invalid_input)
<< "ctu-dir"
<< "a filename";
}
}
CrossTranslationUnitContext::~CrossTranslationUnitContext() {}

View File

@@ -1322,10 +1322,6 @@ static void parseAnalyzerConfigs(AnalyzerOptions &AnOpts,
if (AnOpts.ShouldTrackConditionsDebug && !AnOpts.ShouldTrackConditions)
Diags->Report(diag::err_analyzer_config_invalid_input)
<< "track-conditions-debug" << "'track-conditions' to also be enabled";
if (!AnOpts.CTUDir.empty() && !llvm::sys::fs::is_directory(AnOpts.CTUDir))
Diags->Report(diag::err_analyzer_config_invalid_input) << "ctu-dir"
<< "a filename";
}
/// Generate a remark argument. This is an inverse of `ParseOptimizationRemark`.