Path: blob/main/contrib/llvm-project/clang/lib/Basic/SanitizerSpecialCaseList.cpp
35233 views
//===--- SanitizerSpecialCaseList.cpp - SCL for sanitizers ----------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// An extension of SpecialCaseList to allowing querying sections by9// SanitizerMask.10//11//===----------------------------------------------------------------------===//12#include "clang/Basic/SanitizerSpecialCaseList.h"1314using namespace clang;1516std::unique_ptr<SanitizerSpecialCaseList>17SanitizerSpecialCaseList::create(const std::vector<std::string> &Paths,18llvm::vfs::FileSystem &VFS,19std::string &Error) {20std::unique_ptr<clang::SanitizerSpecialCaseList> SSCL(21new SanitizerSpecialCaseList());22if (SSCL->createInternal(Paths, VFS, Error)) {23SSCL->createSanitizerSections();24return SSCL;25}26return nullptr;27}2829std::unique_ptr<SanitizerSpecialCaseList>30SanitizerSpecialCaseList::createOrDie(const std::vector<std::string> &Paths,31llvm::vfs::FileSystem &VFS) {32std::string Error;33if (auto SSCL = create(Paths, VFS, Error))34return SSCL;35llvm::report_fatal_error(StringRef(Error));36}3738void SanitizerSpecialCaseList::createSanitizerSections() {39for (auto &It : Sections) {40auto &S = It.second;41SanitizerMask Mask;4243#define SANITIZER(NAME, ID) \44if (S.SectionMatcher->match(NAME)) \45Mask |= SanitizerKind::ID;46#define SANITIZER_GROUP(NAME, ID, ALIAS) SANITIZER(NAME, ID)4748#include "clang/Basic/Sanitizers.def"49#undef SANITIZER50#undef SANITIZER_GROUP5152SanitizerSections.emplace_back(Mask, S.Entries);53}54}5556bool SanitizerSpecialCaseList::inSection(SanitizerMask Mask, StringRef Prefix,57StringRef Query,58StringRef Category) const {59for (auto &S : SanitizerSections)60if ((S.Mask & Mask) &&61SpecialCaseList::inSectionBlame(S.Entries, Prefix, Query, Category))62return true;6364return false;65}666768