Author: Jan Svoboda
Date: 2025-09-19T13:01:02-07:00
New Revision: 93f9ca21f060a7aa34e5bb94557409634bf0e39d

URL: 
https://github.com/llvm/llvm-project/commit/93f9ca21f060a7aa34e5bb94557409634bf0e39d
DIFF: 
https://github.com/llvm/llvm-project/commit/93f9ca21f060a7aa34e5bb94557409634bf0e39d.diff

LOG: [clang][analyzer] Load config through the proper VFS (#159164)

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.

Added: 
    clang/test/Analysis/Inputs/taint-generic-config-vfs.json

Modified: 
    clang/lib/StaticAnalyzer/Checkers/Yaml.h
    clang/test/Analysis/taint-generic.c

Removed: 
    


################################################################################
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,

diff  --git a/clang/test/Analysis/Inputs/taint-generic-config-vfs.json 
b/clang/test/Analysis/Inputs/taint-generic-config-vfs.json
new file mode 100644
index 0000000000000..74f3cd99a9707
--- /dev/null
+++ b/clang/test/Analysis/Inputs/taint-generic-config-vfs.json
@@ -0,0 +1,17 @@
+{
+  'version': 0,
+  'use-external-names': true,
+  'roots': [
+    {
+      'name': 'DIR',
+      'type': 'directory',
+      'contents': [
+        {
+          'name': 'taint-generic-config-virtual.yaml',
+          'type': 'file',
+          'external-contents': 'DIR/taint-generic-config.yaml'
+        }
+      ]
+    }
+  ]
+}

diff  --git a/clang/test/Analysis/taint-generic.c 
b/clang/test/Analysis/taint-generic.c
index 9d6d2942df4a9..6017483f06b6d 100644
--- a/clang/test/Analysis/taint-generic.c
+++ b/clang/test/Analysis/taint-generic.c
@@ -1,3 +1,6 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: sed -e "s|DIR|%/S/Inputs|g" %S/Inputs/taint-generic-config-vfs.json > 
%t/taint-generic-config-vfs.json
+
 // RUN: %clang_analyze_cc1 -Wno-format-security -Wno-pointer-to-int-cast \
 // RUN:   -Wno-incompatible-library-redeclaration -verify %s \
 // RUN:   -analyzer-checker=optin.taint.GenericTaint \
@@ -6,7 +9,8 @@
 // RUN:   -analyzer-checker=security.ArrayBound \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-config \
-// RUN:     
optin.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml
+// RUN:     
optin.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config-virtual.yaml 
\
+// RUN:   -ivfsoverlay %t/taint-generic-config-vfs.json
 
 // RUN: %clang_analyze_cc1 -Wno-format-security -Wno-pointer-to-int-cast \
 // RUN:   -Wno-incompatible-library-redeclaration -verify %s \


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to