LLVM 22.0.0git
llvm::SpecialCaseList Class Reference

This is a utility class used to parse user-provided text files with "special case lists" for code sanitizers. More...

#include "llvm/Support/SpecialCaseList.h"

Classes

class  Matcher
 Represents a set of globs and their line numbers. More...
struct  Section

Public Member Functions

LLVM_ABI ~SpecialCaseList ()
LLVM_ABI bool inSection (StringRef Section, StringRef Prefix, StringRef Query, StringRef Category=StringRef()) const
 Returns true, if special case list contains a line.
LLVM_ABI std::pair< unsigned, unsignedinSectionBlame (StringRef Section, StringRef Prefix, StringRef Query, StringRef Category=StringRef()) const
 Returns the file index and the line number <FileIdx, LineNo> corresponding to the special case list entry if the special case list contains a line.

Static Public Member Functions

static LLVM_ABI std::unique_ptr< SpecialCaseListcreate (const std::vector< std::string > &Paths, llvm::vfs::FileSystem &FS, std::string &Error)
 Parses the special case list entries from files.
static LLVM_ABI std::unique_ptr< SpecialCaseListcreate (const MemoryBuffer *MB, std::string &Error)
 Parses the special case list from a memory buffer.
static LLVM_ABI std::unique_ptr< SpecialCaseListcreateOrDie (const std::vector< std::string > &Paths, llvm::vfs::FileSystem &FS)
 Parses the special case list entries from files.

Static Public Attributes

static constexpr std::pair< unsigned, unsignedNotFound = {0, 0}

Protected Types

using SectionEntries = StringMap<StringMap<Matcher>>

Protected Member Functions

LLVM_ABI bool createInternal (const std::vector< std::string > &Paths, vfs::FileSystem &VFS, std::string &Error)
LLVM_ABI bool createInternal (const MemoryBuffer *MB, std::string &Error)
 SpecialCaseList ()=default
 SpecialCaseList (SpecialCaseList const &)=delete
SpecialCaseListoperator= (SpecialCaseList const &)=delete
LLVM_ABI Expected< Section * > addSection (StringRef SectionStr, unsigned FileIdx, unsigned LineNo, bool UseGlobs=true)
LLVM_ABI bool parse (unsigned FileIdx, const MemoryBuffer *MB, std::string &Error)
 Parses just-constructed SpecialCaseList entries from a memory buffer.
LLVM_ABI unsigned inSectionBlame (const SectionEntries &Entries, StringRef Prefix, StringRef Query, StringRef Category) const

Protected Attributes

std::vector< SectionSections

Detailed Description

This is a utility class used to parse user-provided text files with "special case lists" for code sanitizers.

Such files are used to define an "ABI list" for DataFlowSanitizer and allow/exclusion lists for sanitizers like AddressSanitizer or UndefinedBehaviorSanitizer.

Empty lines and lines starting with "#" are ignored. Sections are defined using a '[section_name]' header and can be used to specify sanitizers the entries below it apply to. Section names are globs, and entries without a section header match all sections (e.g. an '[*]' header is assumed.) The remaining lines should have the form: prefix:glob_pattern[=category] If category is not specified, it is assumed to be empty string. Definitions of "prefix" and "category" are sanitizer-specific. For example, sanitizer exclusion support prefixes "src", "mainfile", "fun" and "global". "glob_pattern" defines source files, main files, functions or globals which shouldn't be instrumented. Examples of categories: "functional": used in DFSan to list functions with pure functional semantics. "init": used in ASan exclusion list to disable initialization-order bugs detection for certain globals or source files.

Full special case list file example:

[address]

Excluded items:

fun:_ZN4base6subtle global:global_with_bad_access_or_initialization global:global_with_initialization_issues=init type:Namespace::ClassName=init src:file_with_tricky_code.cc src:ignore-global-initializers-issues.cc=init mainfile:main_file.cc

[dataflow]

Functions with pure functional semantics:

fun:cos=functional

fun:sin=functional

Definition at line 71 of file SpecialCaseList.h.

Member Typedef Documentation

◆ SectionEntries

Definition at line 144 of file SpecialCaseList.h.

Constructor & Destructor Documentation

◆ ~SpecialCaseList()

llvm::SpecialCaseList::~SpecialCaseList ( )
default

References LLVM_ABI.

◆ SpecialCaseList() [1/2]

llvm::SpecialCaseList::SpecialCaseList ( )
protecteddefault

◆ SpecialCaseList() [2/2]

llvm::SpecialCaseList::SpecialCaseList ( SpecialCaseList const & )
protecteddelete

References SpecialCaseList().

Member Function Documentation

◆ addSection()

Expected< SpecialCaseList::Section * > llvm::SpecialCaseList::addSection ( StringRef SectionStr,
unsigned FileIdx,
unsigned LineNo,
bool UseGlobs = true )
protected

◆ create() [1/2]

std::unique_ptr< SpecialCaseList > llvm::SpecialCaseList::create ( const MemoryBuffer * MB,
std::string & Error )
static

Parses the special case list from a memory buffer.

On failure, returns 0 and writes an error message to string.

Definition at line 89 of file SpecialCaseList.cpp.

References SpecialCaseList().

◆ create() [2/2]

std::unique_ptr< SpecialCaseList > llvm::SpecialCaseList::create ( const std::vector< std::string > & Paths,
llvm::vfs::FileSystem & FS,
std::string & Error )
static

Parses the special case list entries from files.

On failure, returns 0 and writes an error message to string.

Definition at line 81 of file SpecialCaseList.cpp.

References SpecialCaseList().

Referenced by createOrDie().

◆ createInternal() [1/2]

bool llvm::SpecialCaseList::createInternal ( const MemoryBuffer * MB,
std::string & Error )
protected

Definition at line 125 of file SpecialCaseList.cpp.

References parse().

◆ createInternal() [2/2]

bool llvm::SpecialCaseList::createInternal ( const std::vector< std::string > & Paths,
vfs::FileSystem & VFS,
std::string & Error )
protected

◆ createOrDie()

std::unique_ptr< SpecialCaseList > llvm::SpecialCaseList::createOrDie ( const std::vector< std::string > & Paths,
llvm::vfs::FileSystem & FS )
static

Parses the special case list entries from files.

On failure, reports a fatal error.

Definition at line 98 of file SpecialCaseList.cpp.

References create(), and llvm::report_fatal_error().

Referenced by llvm::SanitizerBinaryMetadataPass::run(), and llvm::SanitizerCoveragePass::SanitizerCoveragePass().

◆ inSection()

bool llvm::SpecialCaseList::inSection ( StringRef Section,
StringRef Prefix,
StringRef Query,
StringRef Category = StringRef() ) const

Returns true, if special case list contains a line.

@Prefix:<E>=@Category
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

where @Query satisfies the glob <E> in a given @Section.

Definition at line 211 of file SpecialCaseList.cpp.

References inSectionBlame().

◆ inSectionBlame() [1/2]

unsigned llvm::SpecialCaseList::inSectionBlame ( const SectionEntries & Entries,
StringRef Prefix,
StringRef Query,
StringRef Category ) const
protected

◆ inSectionBlame() [2/2]

std::pair< unsigned, unsigned > llvm::SpecialCaseList::inSectionBlame ( StringRef Section,
StringRef Prefix,
StringRef Query,
StringRef Category = StringRef() ) const

Returns the file index and the line number <FileIdx, LineNo> corresponding to the special case list entry if the special case list contains a line.

@Prefix:<E>=@Category

where @Query satisfies the glob <E> in a given @Section. Returns (zero, zero) if there is no exclusion entry corresponding to this expression.

Definition at line 218 of file SpecialCaseList.cpp.

References inSectionBlame(), NotFound, llvm::reverse(), and Sections.

Referenced by inSection(), and inSectionBlame().

◆ operator=()

SpecialCaseList & llvm::SpecialCaseList::operator= ( SpecialCaseList const & )
protecteddelete

References SpecialCaseList().

◆ parse()

bool llvm::SpecialCaseList::parse ( unsigned FileIdx,
const MemoryBuffer * MB,
std::string & Error )
protected

Member Data Documentation

◆ NotFound

std::pair<unsigned, unsigned> llvm::SpecialCaseList::NotFound = {0, 0}
staticconstexpr

Definition at line 73 of file SpecialCaseList.h.

Referenced by inSectionBlame().

◆ Sections

std::vector<Section> llvm::SpecialCaseList::Sections
protected

Definition at line 156 of file SpecialCaseList.h.

Referenced by addSection(), and inSectionBlame().


The documentation for this class was generated from the following files: