]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Basic/Sanitizers.h
Merge clang trunk r238337 from ^/vendor/clang/dist, resolve conflicts,
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Basic / Sanitizers.h
1 //===--- Sanitizers.h - C Language Family Language Options ------*- 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 ///
10 /// \file
11 /// \brief Defines the clang::SanitizerKind enum.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_BASIC_SANITIZERS_H
16 #define LLVM_CLANG_BASIC_SANITIZERS_H
17
18 #include "clang/Basic/LLVM.h"
19 #include "llvm/ADT/StringRef.h"
20
21 #include <stdint.h>
22
23 namespace clang {
24
25 typedef uint64_t SanitizerMask;
26
27 namespace SanitizerKind {
28
29 // Assign ordinals to possible values of -fsanitize= flag, which we will use as
30 // bit positions.
31 enum SanitizerOrdinal : uint64_t {
32 #define SANITIZER(NAME, ID) SO_##ID,
33 #define SANITIZER_GROUP(NAME, ID, ALIAS) SO_##ID##Group,
34 #include "clang/Basic/Sanitizers.def"
35   SO_Count
36 };
37
38 // Define the set of sanitizer kinds, as well as the set of sanitizers each
39 // sanitizer group expands into.
40 #define SANITIZER(NAME, ID) \
41   const SanitizerMask ID = 1ULL << SO_##ID;
42 #define SANITIZER_GROUP(NAME, ID, ALIAS) \
43   const SanitizerMask ID = ALIAS; \
44   const SanitizerMask ID##Group = 1ULL << SO_##ID##Group;
45 #include "clang/Basic/Sanitizers.def"
46
47 }
48
49 struct SanitizerSet {
50   SanitizerSet();
51
52   /// \brief Check if a certain (single) sanitizer is enabled.
53   bool has(SanitizerMask K) const;
54
55   /// \brief Enable or disable a certain (single) sanitizer.
56   void set(SanitizerMask K, bool Value);
57
58   /// \brief Disable all sanitizers.
59   void clear();
60
61   /// \brief Returns true if at least one sanitizer is enabled.
62   bool empty() const;
63
64   /// \brief Bitmask of enabled sanitizers.
65   SanitizerMask Mask;
66 };
67
68 /// Parse a single value from a -fsanitize= or -fno-sanitize= value list.
69 /// Returns a non-zero SanitizerMask, or \c 0 if \p Value is not known.
70 SanitizerMask parseSanitizerValue(StringRef Value, bool AllowGroups);
71
72 /// For each sanitizer group bit set in \p Kinds, set the bits for sanitizers
73 /// this group enables.
74 SanitizerMask expandSanitizerGroups(SanitizerMask Kinds);
75
76 }  // end namespace clang
77
78 #endif