1 //===-- SpecialCaseList.h - special case list for sanitizers ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //===----------------------------------------------------------------------===//
9 // This is a utility class used to parse user-provided text files with
10 // "special case lists" for code sanitizers. Such files are used to
11 // define "ABI list" for DataFlowSanitizer and blacklists for another sanitizers
12 // like AddressSanitizer or UndefinedBehaviorSanitizer.
14 // Empty lines and lines starting with "#" are ignored. All the rest lines
15 // should have the form:
16 // section:wildcard_expression[=category]
17 // If category is not specified, it is assumed to be empty string.
18 // Definitions of "section" and "category" are sanitizer-specific. For example,
19 // sanitizer blacklists support sections "src", "fun" and "global".
20 // Wildcard expressions define, respectively, source files, functions or
21 // globals which shouldn't be instrumented.
22 // Examples of categories:
23 // "functional": used in DFSan to list functions with pure functional
25 // "init": used in ASan blacklist to disable initialization-order bugs
26 // detection for certain globals or source files.
27 // Full special case list file example:
29 // # Blacklisted items:
30 // fun:*_ZN4base6subtle*
31 // global:*global_with_bad_access_or_initialization*
32 // global:*global_with_initialization_issues*=init
33 // type:*Namespace::ClassName*=init
34 // src:file_with_tricky_code.cc
35 // src:ignore-global-initializers-issues.cc=init
37 // # Functions with pure functional semantics:
41 // Note that the wild card is in fact an llvm::Regex, but * is automatically
43 // This is similar to the "ignore" feature of ThreadSanitizer.
44 // http://code.google.com/p/data-race-test/wiki/ThreadSanitizerIgnores
46 //===----------------------------------------------------------------------===//
48 #ifndef LLVM_SUPPORT_SPECIALCASELIST_H
49 #define LLVM_SUPPORT_SPECIALCASELIST_H
51 #include "llvm/ADT/StringMap.h"
58 class SpecialCaseList {
60 /// Parses the special case list from a file. If Path is empty, returns
61 /// an empty special case list. On failure, returns 0 and writes an error
62 /// message to string.
63 static SpecialCaseList *create(const StringRef Path, std::string &Error);
64 /// Parses the special case list from a memory buffer. On failure, returns
65 /// 0 and writes an error message to string.
66 static SpecialCaseList *create(const MemoryBuffer *MB, std::string &Error);
67 /// Parses the special case list from a file. On failure, reports a fatal
69 static SpecialCaseList *createOrDie(const StringRef Path);
73 /// Returns true, if special case list contains a line
75 /// @Section:<E>=@Category
77 /// and @Query satisfies a wildcard expression <E>.
78 bool inSection(const StringRef Section, const StringRef Query,
79 const StringRef Category = StringRef()) const;
82 SpecialCaseList(SpecialCaseList const &) LLVM_DELETED_FUNCTION;
83 SpecialCaseList &operator=(SpecialCaseList const &) LLVM_DELETED_FUNCTION;
86 StringMap<StringMap<Entry> > Entries;
89 /// Parses just-constructed SpecialCaseList entries from a memory buffer.
90 bool parse(const MemoryBuffer *MB, std::string &Error);
95 #endif // LLVM_SUPPORT_SPECIALCASELIST_H