Add forgotten header guards
[oota-llvm.git] / include / llvm / Transforms / Utils / SpecialCaseList.h
1 //===-- SpecialCaseList.h - special case list for sanitizers ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //===----------------------------------------------------------------------===//
8 //
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.
12 //
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.
19 //
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.
23 //
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.
27 // ---
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
35 //
36 // # Functions with pure functional semantics:
37 // fun:cos=functional
38 // fun:sin=functional
39 // ---
40 // Note that the wild card is in fact an llvm::Regex, but * is automatically
41 // replaced with .*
42 // This is similar to the "ignore" feature of ThreadSanitizer.
43 // http://code.google.com/p/data-race-test/wiki/ThreadSanitizerIgnores
44 //
45 //===----------------------------------------------------------------------===//
46
47 #ifndef LLVM_TRANSFORMS_UTILS_SPECIALCASELIST_H
48 #define LLVM_TRANSFORMS_UTILS_SPECIALCASELIST_H
49
50 #include "llvm/ADT/StringMap.h"
51
52 namespace llvm {
53 class Function;
54 class GlobalAlias;
55 class GlobalVariable;
56 class MemoryBuffer;
57 class Module;
58 class Regex;
59 class StringRef;
60
61 class SpecialCaseList {
62  public:
63   /// Parses the special case list from a file. If Path is empty, returns
64   /// an empty special case list. On failure, returns 0 and writes an error
65   /// message to string.
66   static SpecialCaseList *create(const StringRef Path, std::string &Error);
67   /// Parses the special case list from a memory buffer. On failure, returns
68   /// 0 and writes an error message to string.
69   static SpecialCaseList *create(const MemoryBuffer *MB, std::string &Error);
70   /// Parses the special case list from a file. On failure, reports a fatal
71   /// error.
72   static SpecialCaseList *createOrDie(const StringRef Path);
73
74   ~SpecialCaseList();
75
76   /// Returns whether either this function or its source file are listed in the
77   /// given category, which may be omitted to search the empty category.
78   bool isIn(const Function &F, const StringRef Category = StringRef()) const;
79
80   /// Returns whether this global, its type or its source file are listed in the
81   /// given category, which may be omitted to search the empty category.
82   bool isIn(const GlobalVariable &G,
83             const StringRef Category = StringRef()) const;
84
85   /// Returns whether this global alias is listed in the given category, which
86   /// may be omitted to search the empty category.
87   ///
88   /// If GA aliases a function, the alias's name is matched as a function name
89   /// would be.  Similarly, aliases of globals are matched like globals.
90   bool isIn(const GlobalAlias &GA,
91             const StringRef Category = StringRef()) const;
92
93   /// Returns whether this module is listed in the given category, which may be
94   /// omitted to search the empty category.
95   bool isIn(const Module &M, const StringRef Category = StringRef()) const;
96
97  private:
98   SpecialCaseList(SpecialCaseList const &) LLVM_DELETED_FUNCTION;
99   SpecialCaseList &operator=(SpecialCaseList const &) LLVM_DELETED_FUNCTION;
100
101   struct Entry;
102   StringMap<StringMap<Entry> > Entries;
103
104   SpecialCaseList();
105   /// Parses just-constructed SpecialCaseList entries from a memory buffer.
106   bool parse(const MemoryBuffer *MB, std::string &Error);
107
108   bool inSectionCategory(const StringRef Section, const StringRef Query,
109                          const StringRef Category) const;
110 };
111
112 }  // namespace llvm
113
114 #endif  // LLVM_TRANSFORMS_UTILS_SPECIALCASELIST_H