Skip to content

Commit 93f9ca2

Browse files
authored
[clang][analyzer] Load config through the proper VFS (llvm#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.
1 parent 19659ee commit 93f9ca2

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

clang/lib/StaticAnalyzer/Checkers/Yaml.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKER_YAML_H
1515
#define LLVM_CLANG_LIB_STATICANALYZER_CHECKER_YAML_H
1616

17+
#include "clang/Basic/SourceManager.h"
1718
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
1819
#include "llvm/Support/VirtualFileSystem.h"
1920
#include "llvm/Support/YAMLTraits.h"
@@ -31,9 +32,12 @@ std::optional<T> getConfiguration(CheckerManager &Mgr, Checker *Chk,
3132
if (ConfigFile.trim().empty())
3233
return std::nullopt;
3334

34-
llvm::vfs::FileSystem *FS = llvm::vfs::getRealFileSystem().get();
35+
auto &VFS = Mgr.getASTContext()
36+
.getSourceManager()
37+
.getFileManager()
38+
.getVirtualFileSystem();
3539
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer =
36-
FS->getBufferForFile(ConfigFile.str());
40+
VFS.getBufferForFile(ConfigFile.str());
3741

3842
if (Buffer.getError()) {
3943
Mgr.reportInvalidCheckerOptionValue(Chk, Option,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
'version': 0,
3+
'use-external-names': true,
4+
'roots': [
5+
{
6+
'name': 'DIR',
7+
'type': 'directory',
8+
'contents': [
9+
{
10+
'name': 'taint-generic-config-virtual.yaml',
11+
'type': 'file',
12+
'external-contents': 'DIR/taint-generic-config.yaml'
13+
}
14+
]
15+
}
16+
]
17+
}

clang/test/Analysis/taint-generic.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// RUN: rm -rf %t && mkdir %t
2+
// RUN: sed -e "s|DIR|%/S/Inputs|g" %S/Inputs/taint-generic-config-vfs.json > %t/taint-generic-config-vfs.json
3+
14
// RUN: %clang_analyze_cc1 -Wno-format-security -Wno-pointer-to-int-cast \
25
// RUN: -Wno-incompatible-library-redeclaration -verify %s \
36
// RUN: -analyzer-checker=optin.taint.GenericTaint \
@@ -6,7 +9,8 @@
69
// RUN: -analyzer-checker=security.ArrayBound \
710
// RUN: -analyzer-checker=debug.ExprInspection \
811
// RUN: -analyzer-config \
9-
// RUN: optin.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml
12+
// RUN: optin.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config-virtual.yaml \
13+
// RUN: -ivfsoverlay %t/taint-generic-config-vfs.json
1014

1115
// RUN: %clang_analyze_cc1 -Wno-format-security -Wno-pointer-to-int-cast \
1216
// RUN: -Wno-incompatible-library-redeclaration -verify %s \

0 commit comments

Comments
 (0)