SpecialCaseList.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 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.
  13. //
  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
  24. // semantics.
  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:
  28. // ---
  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
  36. //
  37. // # Functions with pure functional semantics:
  38. // fun:cos=functional
  39. // fun:sin=functional
  40. // ---
  41. // Note that the wild card is in fact an llvm::Regex, but * is automatically
  42. // replaced with .*
  43. // This is similar to the "ignore" feature of ThreadSanitizer.
  44. // http://code.google.com/p/data-race-test/wiki/ThreadSanitizerIgnores
  45. //
  46. //===----------------------------------------------------------------------===//
  47. #ifndef LLVM_SUPPORT_SPECIALCASELIST_H
  48. #define LLVM_SUPPORT_SPECIALCASELIST_H
  49. #include "llvm/ADT/StringMap.h"
  50. #include <string>
  51. #include <vector>
  52. namespace llvm {
  53. class MemoryBuffer;
  54. class Regex;
  55. class StringRef;
  56. class SpecialCaseList {
  57. public:
  58. /// Parses the special case list entries from files. On failure, returns
  59. /// 0 and writes an error message to string.
  60. static std::unique_ptr<SpecialCaseList>
  61. create(const std::vector<std::string> &Paths, std::string &Error);
  62. /// Parses the special case list from a memory buffer. On failure, returns
  63. /// 0 and writes an error message to string.
  64. static std::unique_ptr<SpecialCaseList> create(const MemoryBuffer *MB,
  65. std::string &Error);
  66. /// Parses the special case list entries from files. On failure, reports a
  67. /// fatal error.
  68. static std::unique_ptr<SpecialCaseList>
  69. createOrDie(const std::vector<std::string> &Paths);
  70. ~SpecialCaseList();
  71. /// Returns true, if special case list contains a line
  72. /// \code
  73. /// @Section:<E>=@Category
  74. /// \endcode
  75. /// and @Query satisfies a wildcard expression <E>.
  76. bool inSection(StringRef Section, StringRef Query,
  77. StringRef Category = StringRef()) const;
  78. private:
  79. SpecialCaseList(SpecialCaseList const &) = delete;
  80. SpecialCaseList &operator=(SpecialCaseList const &) = delete;
  81. struct Entry;
  82. StringMap<StringMap<Entry>> Entries;
  83. StringMap<StringMap<std::string>> Regexps;
  84. bool IsCompiled;
  85. SpecialCaseList();
  86. /// Parses just-constructed SpecialCaseList entries from a memory buffer.
  87. bool parse(const MemoryBuffer *MB, std::string &Error);
  88. /// compile() should be called once, after parsing all the memory buffers.
  89. void compile();
  90. };
  91. } // namespace llvm
  92. #endif // LLVM_SUPPORT_SPECIALCASELIST_H