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 for instrumentation passes (like AddressSanitizer
10 // or ThreadSanitizer) to avoid instrumenting some functions or global
11 // variables based on a user-supplied list.
13 // The list can also specify categories for specific globals, which can be used
14 // to instruct an instrumentation pass to treat certain functions or global
15 // variables in a specific way, such as by omitting certain aspects of
16 // instrumentation while keeping others, or informing the instrumentation pass
17 // that a specific uninstrumentable function has certain semantics, thus
18 // allowing the pass to instrument callers according to those semantics.
20 // For example, AddressSanitizer uses the "init" category for globals whose
21 // initializers should not be instrumented, but which in all other respects
22 // should be instrumented.
24 // Each line contains a prefix, followed by a colon and a wild card expression,
25 // followed optionally by an equals sign and an instrumentation-specific
26 // category. Empty lines and lines starting with "#" are ignored.
28 // # Blacklisted items:
29 // fun:*_ZN4base6subtle*
30 // global:*global_with_bad_access_or_initialization*
31 // global:*global_with_initialization_issues*=init
32 // type:*Namespace::ClassName*=init
33 // src:file_with_tricky_code.cc
34 // src:ignore-global-initializers-issues.cc=init
36 // # Functions with pure functional semantics:
40 // Note that the wild card is in fact an llvm::Regex, but * is automatically
42 // This is similar to the "ignore" feature of ThreadSanitizer.
43 // http://code.google.com/p/data-race-test/wiki/ThreadSanitizerIgnores
45 //===----------------------------------------------------------------------===//
48 #include "llvm/ADT/StringMap.h"
58 class SpecialCaseList {
60 // FIXME: Switch all users to factories and remove these constructors.
61 SpecialCaseList(const StringRef Path);
62 SpecialCaseList(const MemoryBuffer *MB);
64 /// Parses the special case list from a file. If Path is empty, returns
65 /// an empty special case list. On failure, returns 0 and writes an error
66 /// message to string.
67 static SpecialCaseList *create(const StringRef Path, std::string &Error);
68 /// Parses the special case list from a memory buffer. On failure, returns
69 /// 0 and writes an error message to string.
70 static SpecialCaseList *create(const MemoryBuffer *MB, std::string &Error);
74 /// Returns whether either this function or its source file are listed in the
75 /// given category, which may be omitted to search the empty category.
76 bool isIn(const Function &F, const StringRef Category = StringRef()) const;
78 /// Returns whether this global, its type or its source file are listed in the
79 /// given category, which may be omitted to search the empty category.
80 bool isIn(const GlobalVariable &G,
81 const StringRef Category = StringRef()) const;
83 /// Returns whether this module is listed in the given category, which may be
84 /// omitted to search the empty category.
85 bool isIn(const Module &M, const StringRef Category = StringRef()) const;
87 /// Returns whether either this function or its source file are listed in any
88 /// category. Category will contain the name of an arbitrary category in
89 /// which this function is listed.
90 bool findCategory(const Function &F, StringRef &Category) const;
92 /// Returns whether this global, its type or its source file are listed in any
93 /// category. Category will contain the name of an arbitrary category in
94 /// which this global is listed.
95 bool findCategory(const GlobalVariable &G, StringRef &Category) const;
97 /// Returns whether this module is listed in any category. Category will
98 /// contain the name of an arbitrary category in which this module is listed.
99 bool findCategory(const Module &M, StringRef &Category) const;
102 SpecialCaseList(SpecialCaseList const &) LLVM_DELETED_FUNCTION;
103 SpecialCaseList &operator=(SpecialCaseList const &) LLVM_DELETED_FUNCTION;
106 StringMap<StringMap<Entry> > Entries;
109 /// Parses just-constructed SpecialCaseList entries from a memory buffer.
110 bool parse(const MemoryBuffer *MB, std::string &Error);
112 bool findCategory(const StringRef Section, const StringRef Query,
113 StringRef &Category) const;
114 bool inSectionCategory(const StringRef Section, const StringRef Query,
115 const StringRef Category) const;