Skip to content

Conversation

@jansvoboda11
Copy link
Contributor

This PR ensures that the Clang static analyzer loads the config file through the properly-configured VFS rather than through the bare real file system. This enables correctly going through VFS overlays, unifying the behavior with the rest of the compiler.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Sep 16, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 16, 2025

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Jan Svoboda (jansvoboda11)

Changes

This PR ensures that the Clang static analyzer loads the config file through the properly-configured VFS rather than through the bare real file system. This enables correctly going through VFS overlays, unifying the behavior with the rest of the compiler.


Full diff: https://github.com/llvm/llvm-project/pull/159164.diff

1 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/Yaml.h (+6-2)
diff --git a/clang/lib/StaticAnalyzer/Checkers/Yaml.h b/clang/lib/StaticAnalyzer/Checkers/Yaml.h
index b2d17420686ee..ec521cbfcdc8e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/Yaml.h
+++ b/clang/lib/StaticAnalyzer/Checkers/Yaml.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKER_YAML_H
 #define LLVM_CLANG_LIB_STATICANALYZER_CHECKER_YAML_H
 
+#include "clang/Basic/SourceManager.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/YAMLTraits.h"
@@ -31,9 +32,12 @@ std::optional<T> getConfiguration(CheckerManager &Mgr, Checker *Chk,
   if (ConfigFile.trim().empty())
     return std::nullopt;
 
-  llvm::vfs::FileSystem *FS = llvm::vfs::getRealFileSystem().get();
+  auto &VFS = Mgr.getASTContext()
+                  .getSourceManager()
+                  .getFileManager()
+                  .getVirtualFileSystem();
   llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer =
-      FS->getBufferForFile(ConfigFile.str());
+      VFS.getBufferForFile(ConfigFile.str());
 
   if (Buffer.getError()) {
     Mgr.reportInvalidCheckerOptionValue(Chk, Option,

@llvmbot
Copy link
Member

llvmbot commented Sep 16, 2025

@llvm/pr-subscribers-clang

Author: Jan Svoboda (jansvoboda11)

Changes

This PR ensures that the Clang static analyzer loads the config file through the properly-configured VFS rather than through the bare real file system. This enables correctly going through VFS overlays, unifying the behavior with the rest of the compiler.


Full diff: https://github.com/llvm/llvm-project/pull/159164.diff

1 Files Affected:

  • (modified) clang/lib/StaticAnalyzer/Checkers/Yaml.h (+6-2)
diff --git a/clang/lib/StaticAnalyzer/Checkers/Yaml.h b/clang/lib/StaticAnalyzer/Checkers/Yaml.h
index b2d17420686ee..ec521cbfcdc8e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/Yaml.h
+++ b/clang/lib/StaticAnalyzer/Checkers/Yaml.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKER_YAML_H
 #define LLVM_CLANG_LIB_STATICANALYZER_CHECKER_YAML_H
 
+#include "clang/Basic/SourceManager.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/YAMLTraits.h"
@@ -31,9 +32,12 @@ std::optional<T> getConfiguration(CheckerManager &Mgr, Checker *Chk,
   if (ConfigFile.trim().empty())
     return std::nullopt;
 
-  llvm::vfs::FileSystem *FS = llvm::vfs::getRealFileSystem().get();
+  auto &VFS = Mgr.getASTContext()
+                  .getSourceManager()
+                  .getFileManager()
+                  .getVirtualFileSystem();
   llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer =
-      FS->getBufferForFile(ConfigFile.str());
+      VFS.getBufferForFile(ConfigFile.str());
 
   if (Buffer.getError()) {
     Mgr.reportInvalidCheckerOptionValue(Chk, Option,

@cachemeifyoucan
Copy link
Collaborator

Can you add a test case?

@jansvoboda11 jansvoboda11 merged commit 93f9ca2 into llvm:main Sep 19, 2025
9 checks passed
@jansvoboda11 jansvoboda11 deleted the analyzer-config-vfs branch September 19, 2025 20:01
jansvoboda11 added a commit to swiftlang/llvm-project that referenced this pull request Oct 18, 2025
This PR ensures that the Clang static analyzer loads the config file
through the properly-configured VFS rather than through the bare real
file system. This enables correctly going through VFS overlays, unifying
the behavior with the rest of the compiler.
jansvoboda11 added a commit to swiftlang/llvm-project that referenced this pull request Oct 23, 2025
This PR ensures that the Clang static analyzer loads the config file
through the properly-configured VFS rather than through the bare real
file system. This enables correctly going through VFS overlays, unifying
the behavior with the rest of the compiler.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:static analyzer clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants