Skip to content

Commit 2e96cd6

Browse files
authored
[clang][analyzer] Delay checking the model-path (#150133)
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 `model-path` is an existing directory.
1 parent 4d2e1e1 commit 2e96cd6

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,11 +1326,6 @@ static void parseAnalyzerConfigs(AnalyzerOptions &AnOpts,
13261326
if (!AnOpts.CTUDir.empty() && !llvm::sys::fs::is_directory(AnOpts.CTUDir))
13271327
Diags->Report(diag::err_analyzer_config_invalid_input) << "ctu-dir"
13281328
<< "a filename";
1329-
1330-
if (!AnOpts.ModelPath.empty() &&
1331-
!llvm::sys::fs::is_directory(AnOpts.ModelPath))
1332-
Diags->Report(diag::err_analyzer_config_invalid_input) << "model-path"
1333-
<< "a filename";
13341329
}
13351330

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

clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "ModelInjector.h"
1010
#include "clang/AST/Decl.h"
1111
#include "clang/AST/DeclObjC.h"
12+
#include "clang/Basic/DiagnosticDriver.h"
1213
#include "clang/Basic/LangStandard.h"
1314
#include "clang/Basic/Stack.h"
1415
#include "clang/Frontend/ASTUnit.h"
@@ -24,7 +25,15 @@
2425
using namespace clang;
2526
using namespace ento;
2627

27-
ModelInjector::ModelInjector(CompilerInstance &CI) : CI(CI) {}
28+
ModelInjector::ModelInjector(CompilerInstance &CI) : CI(CI) {
29+
if (CI.getAnalyzerOpts().ShouldEmitErrorsOnInvalidConfigValue &&
30+
!CI.getAnalyzerOpts().ModelPath.empty()) {
31+
auto S = CI.getVirtualFileSystem().status(CI.getAnalyzerOpts().ModelPath);
32+
if (!S || S->getType() != llvm::sys::fs::file_type::directory_file)
33+
CI.getDiagnostics().Report(diag::err_analyzer_config_invalid_input)
34+
<< "model-path" << "a filename";
35+
}
36+
}
2837

2938
Stmt *ModelInjector::getBody(const FunctionDecl *D) {
3039
onBodySynthesis(D);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// RUN: not %clang_analyze_cc1 -analyzer-checker=core -analyzer-config model-path=%t/blah %s -o - 2>&1 | FileCheck %s
2+
// CHECK: error: invalid input for analyzer-config option 'model-path', that expects a filename value
3+
// CHECK-NEXT: 1 error generated

0 commit comments

Comments
 (0)