1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

Reland 9f3fdb0d7fab: [Driver] Use VFS to check if sanitizer blacklists exist

With updates to various LLVM tools that use SpecialCastList.

It was tempting to use RealFileSystem as the default, but that makes it
too easy to accidentally forget passing VFS in clang code.
This commit is contained in:
Ilya Biryukov 2019-11-21 11:32:17 +01:00
parent 290efde9ec
commit a1512ae17b
7 changed files with 29 additions and 16 deletions

View File

@ -69,7 +69,8 @@ public:
/// Parses the special case list entries from files. On failure, returns
/// 0 and writes an error message to string.
static std::unique_ptr<SpecialCaseList>
create(const std::vector<std::string> &Paths, std::string &Error);
create(const std::vector<std::string> &Paths, llvm::vfs::FileSystem &FS,
std::string &Error);
/// Parses the special case list from a memory buffer. On failure, returns
/// 0 and writes an error message to string.
static std::unique_ptr<SpecialCaseList> create(const MemoryBuffer *MB,
@ -77,7 +78,7 @@ public:
/// Parses the special case list entries from files. On failure, reports a
/// fatal error.
static std::unique_ptr<SpecialCaseList>
createOrDie(const std::vector<std::string> &Paths);
createOrDie(const std::vector<std::string> &Paths, llvm::vfs::FileSystem &FS);
~SpecialCaseList();
@ -103,8 +104,8 @@ public:
protected:
// Implementations of the create*() functions that can also be used by derived
// classes.
bool createInternal(const std::vector<std::string> &Paths, std::string &Error,
vfs::FileSystem &VFS = *vfs::getRealFileSystem());
bool createInternal(const std::vector<std::string> &Paths,
vfs::FileSystem &VFS, std::string &Error);
bool createInternal(const MemoryBuffer *MB, std::string &Error);
SpecialCaseList() = default;

View File

@ -18,6 +18,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/VirtualFileSystem.h"
#include <string>
#include <system_error>
#include <utility>
@ -71,9 +72,9 @@ unsigned SpecialCaseList::Matcher::match(StringRef Query) const {
std::unique_ptr<SpecialCaseList>
SpecialCaseList::create(const std::vector<std::string> &Paths,
std::string &Error) {
llvm::vfs::FileSystem &FS, std::string &Error) {
std::unique_ptr<SpecialCaseList> SCL(new SpecialCaseList());
if (SCL->createInternal(Paths, Error))
if (SCL->createInternal(Paths, FS, Error))
return SCL;
return nullptr;
}
@ -87,15 +88,16 @@ std::unique_ptr<SpecialCaseList> SpecialCaseList::create(const MemoryBuffer *MB,
}
std::unique_ptr<SpecialCaseList>
SpecialCaseList::createOrDie(const std::vector<std::string> &Paths) {
SpecialCaseList::createOrDie(const std::vector<std::string> &Paths,
llvm::vfs::FileSystem &FS) {
std::string Error;
if (auto SCL = create(Paths, Error))
if (auto SCL = create(Paths, FS, Error))
return SCL;
report_fatal_error(Error);
}
bool SpecialCaseList::createInternal(const std::vector<std::string> &Paths,
std::string &Error, vfs::FileSystem &VFS) {
vfs::FileSystem &VFS, std::string &Error) {
StringMap<size_t> Sections;
for (const auto &Path : Paths) {
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =

View File

@ -88,6 +88,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/SpecialCaseList.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Transforms/Instrumentation.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
@ -480,7 +481,9 @@ DataFlowSanitizer::DataFlowSanitizer(
std::vector<std::string> AllABIListFiles(std::move(ABIListFiles));
AllABIListFiles.insert(AllABIListFiles.end(), ClABIListFiles.begin(),
ClABIListFiles.end());
ABIList.set(SpecialCaseList::createOrDie(AllABIListFiles));
// FIXME: should we propagate vfs::FileSystem to this constructor?
ABIList.set(
SpecialCaseList::createOrDie(AllABIListFiles, *vfs::getRealFileSystem()));
}
FunctionType *DataFlowSanitizer::getArgsFunctionType(FunctionType *T) {

View File

@ -24,6 +24,7 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/SpecialCaseList.h"
#include "llvm/Support/VirtualFileSystem.h"
#include <cstdlib>
@ -261,7 +262,8 @@ int main(int argc, char **argv) {
std::unique_ptr<SpecialCaseList> SpecialCaseList;
if (BlacklistFilename != "-") {
std::string Error;
SpecialCaseList = SpecialCaseList::create({BlacklistFilename}, Error);
SpecialCaseList = SpecialCaseList::create({BlacklistFilename},
*vfs::getRealFileSystem(), Error);
if (!SpecialCaseList) {
errs() << "Failed to get blacklist: " << Error << "\n";
exit(EXIT_FAILURE);

View File

@ -36,6 +36,7 @@
#include "llvm/Support/ThreadPool.h"
#include "llvm/Support/Threading.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/VirtualFileSystem.h"
#include <functional>
#include <map>
@ -704,8 +705,8 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
// Read in -name-whitelist files.
if (!NameFilterFiles.empty()) {
std::string SpecialCaseListErr;
NameWhitelist =
SpecialCaseList::create(NameFilterFiles, SpecialCaseListErr);
NameWhitelist = SpecialCaseList::create(
NameFilterFiles, *vfs::getRealFileSystem(), SpecialCaseListErr);
if (!NameWhitelist)
error(SpecialCaseListErr);
}

View File

@ -45,6 +45,7 @@
#include "llvm/Support/SpecialCaseList.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/YAMLParser.h"
#include "llvm/Support/raw_ostream.h"
@ -510,7 +511,8 @@ private:
if (ClBlacklist.empty())
return std::unique_ptr<SpecialCaseList>();
return SpecialCaseList::createOrDie({{ClBlacklist}});
return SpecialCaseList::createOrDie({{ClBlacklist}},
*vfs::getRealFileSystem());
}
std::unique_ptr<SpecialCaseList> DefaultBlacklist;
std::unique_ptr<SpecialCaseList> UserBlacklist;

View File

@ -9,6 +9,7 @@
#include "llvm/Support/SpecialCaseList.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "gtest/gtest.h"
using namespace llvm;
@ -161,7 +162,8 @@ TEST_F(SpecialCaseListTest, InvalidSpecialCaseList) {
EXPECT_EQ("malformed regex in line 2: 'fun(a': parentheses not balanced",
Error);
std::vector<std::string> Files(1, "unexisting");
EXPECT_EQ(nullptr, SpecialCaseList::create(Files, Error));
EXPECT_EQ(nullptr,
SpecialCaseList::create(Files, *vfs::getRealFileSystem(), Error));
EXPECT_EQ(0U, Error.find("can't open file 'unexisting':"));
}
@ -177,7 +179,7 @@ TEST_F(SpecialCaseListTest, MultipleBlacklists) {
"src:ban=init\n"));
Files.push_back(makeSpecialCaseListFile("src:baz\n"
"src:*fog*\n"));
auto SCL = SpecialCaseList::createOrDie(Files);
auto SCL = SpecialCaseList::createOrDie(Files, *vfs::getRealFileSystem());
EXPECT_TRUE(SCL->inSection("", "src", "bar"));
EXPECT_TRUE(SCL->inSection("", "src", "baz"));
EXPECT_FALSE(SCL->inSection("", "src", "ban"));