Skip to content

Commit 32d55c6

Browse files
committed
[clang][analyzer] Delay checking the ctu-dir (llvm#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. (cherry picked from commit 1fc090f)
1 parent 9531922 commit 32d55c6

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
@@ -1373,10 +1373,6 @@ static void parseAnalyzerConfigs(AnalyzerOptions &AnOpts,
13731373
if (AnOpts.ShouldTrackConditionsDebug && !AnOpts.ShouldTrackConditions)
13741374
Diags->Report(diag::err_analyzer_config_invalid_input)
13751375
<< "track-conditions-debug" << "'track-conditions' to also be enabled";
1376-
1377-
if (!AnOpts.CTUDir.empty() && !llvm::sys::fs::is_directory(AnOpts.CTUDir))
1378-
Diags->Report(diag::err_analyzer_config_invalid_input) << "ctu-dir"
1379-
<< "a filename";
13801376
}
13811377

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

0 commit comments

Comments
 (0)