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 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> 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 \