diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2013-07-09 22:03:17 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2013-07-09 22:03:17 +0000 |
commit | 46e11c4c97fe1c424241e4098801456303a5c86e (patch) | |
tree | 16ead929d708047b076e827d2157d951c57d81ab /include/llvm/Transforms | |
parent | c7087f8e423c8f3eda453d7fc3843191dac4143b (diff) | |
download | llvm-46e11c4c97fe1c424241e4098801456303a5c86e.tar.gz llvm-46e11c4c97fe1c424241e4098801456303a5c86e.tar.bz2 llvm-46e11c4c97fe1c424241e4098801456303a5c86e.tar.xz |
Implement categories for special case lists.
A special case list can now specify categories for specific globals,
which can be used to instruct an instrumentation pass to treat certain
functions or global variables in a specific way, such as by omitting
certain aspects of instrumentation while keeping others, or informing
the instrumentation pass that a specific uninstrumentable function
has certain semantics, thus allowing the pass to instrument callers
according to those semantics.
For example, AddressSanitizer now uses the "init" category instead of
global-init prefixes for globals whose initializers should not be
instrumented, but which in all other respects should be instrumented.
The motivating use case is DataFlowSanitizer, which will have a
number of different categories for uninstrumentable functions, such
as "functional" which specifies that a function has pure functional
semantics, or "discard" which indicates that a function's return
value should not be labelled.
Differential Revision: http://llvm-reviews.chandlerc.com/D1092
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185978 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Transforms')
-rw-r--r-- | include/llvm/Transforms/Utils/SpecialCaseList.h | 74 |
1 files changed, 56 insertions, 18 deletions
diff --git a/include/llvm/Transforms/Utils/SpecialCaseList.h b/include/llvm/Transforms/Utils/SpecialCaseList.h index 30e3e46ef5..9f74953c7f 100644 --- a/include/llvm/Transforms/Utils/SpecialCaseList.h +++ b/include/llvm/Transforms/Utils/SpecialCaseList.h @@ -1,4 +1,4 @@ -//===-- SpecialCaseList.h - blacklist for sanitizers ------------*- C++ -*-===// +//===-- SpecialCaseList.h - special case list for sanitizers ----*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -8,19 +8,34 @@ // // This is a utility class for instrumentation passes (like AddressSanitizer // or ThreadSanitizer) to avoid instrumenting some functions or global -// variables based on a user-supplied blacklist. +// variables based on a user-supplied list. // -// The blacklist disables instrumentation of various functions and global -// variables. Each line contains a prefix, followed by a wild card expression. -// Empty lines and lines starting with "#" are ignored. +// The list can also specify categories for specific globals, which can be used +// to instruct an instrumentation pass to treat certain functions or global +// variables in a specific way, such as by omitting certain aspects of +// instrumentation while keeping others, or informing the instrumentation pass +// that a specific uninstrumentable function has certain semantics, thus +// allowing the pass to instrument callers according to those semantics. +// +// For example, AddressSanitizer uses the "init" category for globals whose +// initializers should not be instrumented, but which in all other respects +// should be instrumented. +// +// Each line contains a prefix, followed by a colon and a wild card expression, +// followed optionally by an equals sign and an instrumentation-specific +// category. Empty lines and lines starting with "#" are ignored. // --- // # Blacklisted items: // fun:*_ZN4base6subtle* // global:*global_with_bad_access_or_initialization* -// global-init:*global_with_initialization_issues* -// global-init-type:*Namespace::ClassName* +// global:*global_with_initialization_issues*=init +// type:*Namespace::ClassName*=init // src:file_with_tricky_code.cc -// global-init-src:ignore-global-initializers-issues.cc +// src:ignore-global-initializers-issues.cc=init +// +// # Functions with pure functional semantics: +// fun:cos=functional +// fun:sin=functional // --- // Note that the wild card is in fact an llvm::Regex, but * is automatically // replaced with .* @@ -44,20 +59,43 @@ class SpecialCaseList { public: SpecialCaseList(const StringRef Path); SpecialCaseList(const MemoryBuffer *MB); + ~SpecialCaseList(); + + /// Returns whether either this function or its source file are listed in the + /// given category, which may be omitted to search the empty category. + bool isIn(const Function &F, const StringRef Category = StringRef()) const; + + /// Returns whether this global, its type or its source file are listed in the + /// given category, which may be omitted to search the empty category. + bool isIn(const GlobalVariable &G, + const StringRef Category = StringRef()) const; + + /// Returns whether this module is listed in the given category, which may be + /// omitted to search the empty category. + bool isIn(const Module &M, const StringRef Category = StringRef()) const; + + /// Returns whether either this function or its source file are listed in any + /// category. Category will contain the name of an arbitrary category in + /// which this function is listed. + bool findCategory(const Function &F, StringRef &Category) const; + + /// Returns whether this global, its type or its source file are listed in any + /// category. Category will contain the name of an arbitrary category in + /// which this global is listed. + bool findCategory(const GlobalVariable &G, StringRef &Category) const; + + /// Returns whether this module is listed in any category. Category will + /// contain the name of an arbitrary category in which this module is listed. + bool findCategory(const Module &M, StringRef &Category) const; - // Returns whether either this function or it's source file are blacklisted. - bool isIn(const Function &F) const; - // Returns whether either this global or it's source file are blacklisted. - bool isIn(const GlobalVariable &G) const; - // Returns whether this module is blacklisted by filename. - bool isIn(const Module &M) const; - // Returns whether a global should be excluded from initialization checking. - bool isInInit(const GlobalVariable &G) const; private: - StringMap<Regex*> Entries; + StringMap<StringMap<Regex*> > Entries; void init(const MemoryBuffer *MB); - bool inSection(const StringRef Section, const StringRef Query) const; + bool findCategory(const StringRef Section, const StringRef Query, + StringRef &Category) const; + bool inSectionCategory(const StringRef Section, const StringRef Query, + const StringRef Category) const; }; } // namespace llvm |