[clang] 2e96cd6 - [clang][analyzer] Delay checking the model-path (#150133)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 2 10:43:08 PDT 2025
Author: Jan Svoboda
Date: 2025-09-02T10:43:04-07:00
New Revision: 2e96cd6562f64e11b4b3359f867bab8d45a79672
URL: https://github.com/llvm/llvm-project/commit/2e96cd6562f64e11b4b3359f867bab8d45a79672
DIFF: https://github.com/llvm/llvm-project/commit/2e96cd6562f64e11b4b3359f867bab8d45a79672.diff
LOG: [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.
Added:
clang/test/Analysis/model-file-missing.cpp
Modified:
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp
Removed:
################################################################################
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index aadda694a0854..3c301debb9503 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1326,11 +1326,6 @@ static void parseAnalyzerConfigs(AnalyzerOptions &AnOpts,
if (!AnOpts.CTUDir.empty() && !llvm::sys::fs::is_directory(AnOpts.CTUDir))
Diags->Report(diag::err_analyzer_config_invalid_input) << "ctu-dir"
<< "a filename";
-
- if (!AnOpts.ModelPath.empty() &&
- !llvm::sys::fs::is_directory(AnOpts.ModelPath))
- Diags->Report(diag::err_analyzer_config_invalid_input) << "model-path"
- << "a filename";
}
/// Generate a remark argument. This is an inverse of `ParseOptimizationRemark`.
diff --git a/clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp b/clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp
index 7bc34f61255f4..975c72af0b031 100644
--- a/clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/ModelInjector.cpp
@@ -9,6 +9,7 @@
#include "ModelInjector.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h"
+#include "clang/Basic/DiagnosticDriver.h"
#include "clang/Basic/LangStandard.h"
#include "clang/Basic/Stack.h"
#include "clang/Frontend/ASTUnit.h"
@@ -24,7 +25,15 @@
using namespace clang;
using namespace ento;
-ModelInjector::ModelInjector(CompilerInstance &CI) : CI(CI) {}
+ModelInjector::ModelInjector(CompilerInstance &CI) : CI(CI) {
+ if (CI.getAnalyzerOpts().ShouldEmitErrorsOnInvalidConfigValue &&
+ !CI.getAnalyzerOpts().ModelPath.empty()) {
+ auto S = CI.getVirtualFileSystem().status(CI.getAnalyzerOpts().ModelPath);
+ if (!S || S->getType() != llvm::sys::fs::file_type::directory_file)
+ CI.getDiagnostics().Report(diag::err_analyzer_config_invalid_input)
+ << "model-path" << "a filename";
+ }
+}
Stmt *ModelInjector::getBody(const FunctionDecl *D) {
onBodySynthesis(D);
diff --git a/clang/test/Analysis/model-file-missing.cpp b/clang/test/Analysis/model-file-missing.cpp
new file mode 100644
index 0000000000000..c9dfb4ec1b244
--- /dev/null
+++ b/clang/test/Analysis/model-file-missing.cpp
@@ -0,0 +1,3 @@
+// RUN: not %clang_analyze_cc1 -analyzer-checker=core -analyzer-config model-path=%t/blah %s -o - 2>&1 | FileCheck %s
+// CHECK: error: invalid input for analyzer-config option 'model-path', that expects a filename value
+// CHECK-NEXT: 1 error generated
More information about the cfe-commits
mailing list