LLVM API Documentation

SpecialCaseList.h
Go to the documentation of this file.
00001 //===-- SpecialCaseList.h - special case list for sanitizers ----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //===----------------------------------------------------------------------===//
00008 //
00009 // This is a utility class used to parse user-provided text files with
00010 // "special case lists" for code sanitizers. Such files are used to
00011 // define "ABI list" for DataFlowSanitizer and blacklists for another sanitizers
00012 // like AddressSanitizer or UndefinedBehaviorSanitizer.
00013 //
00014 // Empty lines and lines starting with "#" are ignored. All the rest lines
00015 // should have the form:
00016 //   section:wildcard_expression[=category]
00017 // If category is not specified, it is assumed to be empty string.
00018 // Definitions of "section" and "category" are sanitizer-specific. For example,
00019 // sanitizer blacklists support sections "src", "fun" and "global".
00020 // Wildcard expressions define, respectively, source files, functions or
00021 // globals which shouldn't be instrumented.
00022 // Examples of categories:
00023 //   "functional": used in DFSan to list functions with pure functional
00024 //                 semantics.
00025 //   "init": used in ASan blacklist to disable initialization-order bugs
00026 //           detection for certain globals or source files.
00027 // Full special case list file example:
00028 // ---
00029 // # Blacklisted items:
00030 // fun:*_ZN4base6subtle*
00031 // global:*global_with_bad_access_or_initialization*
00032 // global:*global_with_initialization_issues*=init
00033 // type:*Namespace::ClassName*=init
00034 // src:file_with_tricky_code.cc
00035 // src:ignore-global-initializers-issues.cc=init
00036 //
00037 // # Functions with pure functional semantics:
00038 // fun:cos=functional
00039 // fun:sin=functional
00040 // ---
00041 // Note that the wild card is in fact an llvm::Regex, but * is automatically
00042 // replaced with .*
00043 // This is similar to the "ignore" feature of ThreadSanitizer.
00044 // http://code.google.com/p/data-race-test/wiki/ThreadSanitizerIgnores
00045 //
00046 //===----------------------------------------------------------------------===//
00047 
00048 #ifndef LLVM_SUPPORT_SPECIALCASELIST_H
00049 #define LLVM_SUPPORT_SPECIALCASELIST_H
00050 
00051 #include "llvm/ADT/StringMap.h"
00052 
00053 namespace llvm {
00054 class MemoryBuffer;
00055 class Regex;
00056 class StringRef;
00057 
00058 class SpecialCaseList {
00059 public:
00060   /// Parses the special case list from a file. If Path is empty, returns
00061   /// an empty special case list. On failure, returns 0 and writes an error
00062   /// message to string.
00063   static std::unique_ptr<SpecialCaseList> create(StringRef Path,
00064                                                   std::string &Error);
00065   /// Parses the special case list from a memory buffer. On failure, returns
00066   /// 0 and writes an error message to string.
00067   static std::unique_ptr<SpecialCaseList> create(const MemoryBuffer *MB,
00068                                                   std::string &Error);
00069   /// Parses the special case list from a file. On failure, reports a fatal
00070   /// error.
00071   static std::unique_ptr<SpecialCaseList> createOrDie(StringRef Path);
00072 
00073   ~SpecialCaseList();
00074 
00075   /// Returns true, if special case list contains a line
00076   /// \code
00077   ///   @Section:<E>=@Category
00078   /// \endcode
00079   /// and @Query satisfies a wildcard expression <E>.
00080   bool inSection(StringRef Section, StringRef Query,
00081                  StringRef Category = StringRef()) const;
00082 
00083 private:
00084   SpecialCaseList(SpecialCaseList const &) LLVM_DELETED_FUNCTION;
00085   SpecialCaseList &operator=(SpecialCaseList const &) LLVM_DELETED_FUNCTION;
00086 
00087   struct Entry;
00088   StringMap<StringMap<Entry> > Entries;
00089 
00090   SpecialCaseList();
00091   /// Parses just-constructed SpecialCaseList entries from a memory buffer.
00092   bool parse(const MemoryBuffer *MB, std::string &Error);
00093 };
00094 
00095 }  // namespace llvm
00096 
00097 #endif  // LLVM_SUPPORT_SPECIALCASELIST_H
00098