Skip to content

Commit 1fc090f

Browse files
authored
[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.
1 parent 95d3ece commit 1fc090f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

clang/lib/CrossTU/CrossTranslationUnit.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "clang/AST/ASTImporter.h"
1414
#include "clang/AST/Decl.h"
1515
#include "clang/AST/ParentMapContext.h"
16+
#include "clang/Basic/DiagnosticDriver.h"
1617
#include "clang/Basic/TargetInfo.h"
1718
#include "clang/CrossTU/CrossTUDiagnostic.h"
1819
#include "clang/Frontend/ASTUnit.h"
@@ -237,7 +238,16 @@ template <typename T> static bool hasBodyOrInit(const T *D) {
237238
}
238239

239240
CrossTranslationUnitContext::CrossTranslationUnitContext(CompilerInstance &CI)
240-
: Context(CI.getASTContext()), ASTStorage(CI) {}
241+
: Context(CI.getASTContext()), ASTStorage(CI) {
242+
if (CI.getAnalyzerOpts().ShouldEmitErrorsOnInvalidConfigValue &&
243+
!CI.getAnalyzerOpts().CTUDir.empty()) {
244+
auto S = CI.getVirtualFileSystem().status(CI.getAnalyzerOpts().CTUDir);
245+
if (!S || S->getType() != llvm::sys::fs::file_type::directory_file)
246+
CI.getDiagnostics().Report(diag::err_analyzer_config_invalid_input)
247+
<< "ctu-dir"
248+
<< "a filename";
249+
}
250+
}
241251

242252
CrossTranslationUnitContext::~CrossTranslationUnitContext() {}
243253

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,10 +1322,6 @@ static void parseAnalyzerConfigs(AnalyzerOptions &AnOpts,
13221322
if (AnOpts.ShouldTrackConditionsDebug && !AnOpts.ShouldTrackConditions)
13231323
Diags->Report(diag::err_analyzer_config_invalid_input)
13241324
<< "track-conditions-debug" << "'track-conditions' to also be enabled";
1325-
1326-
if (!AnOpts.CTUDir.empty() && !llvm::sys::fs::is_directory(AnOpts.CTUDir))
1327-
Diags->Report(diag::err_analyzer_config_invalid_input) << "ctu-dir"
1328-
<< "a filename";
13291325
}
13301326

13311327
/// Generate a remark argument. This is an inverse of `ParseOptimizationRemark`.

0 commit comments

Comments
 (0)