Clang Project

clang_source_code/include/clang/Basic/Sanitizers.def
1//===--- Sanitizers.def - Runtime sanitizer options -------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the options for specifying which runtime sanitizers to
10// enable. Users of this file must define the SANITIZER macro to make use of
11// this information. Users of this file can also define the SANITIZER_GROUP
12// macro to get information on options which refer to sets of sanitizers.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef SANITIZER
17#error "Define SANITIZER prior to including this file!"
18#endif
19
20// SANITIZER(NAME, ID)
21
22// The first value is the name of the sanitizer as a string. The sanitizer can
23// be enabled by specifying -fsanitize=NAME.
24
25// The second value is an identifier which can be used to refer to the
26// sanitizer.
27
28
29// SANITIZER_GROUP(NAME, ID, ALIAS)
30
31// The first two values have the same semantics as the corresponding SANITIZER
32// values. The third value is an expression ORing together the IDs of individual
33// sanitizers in this group.
34
35#ifndef SANITIZER_GROUP
36#define SANITIZER_GROUP(NAME, ID, ALIAS)
37#endif
38
39
40// AddressSanitizer
41SANITIZER("address", Address)
42
43// Kernel AddressSanitizer (KASan)
44SANITIZER("kernel-address", KernelAddress)
45
46// Hardware-assisted AddressSanitizer
47SANITIZER("hwaddress", HWAddress)
48
49// Kernel Hardware-assisted AddressSanitizer (KHWASan)
50SANITIZER("kernel-hwaddress", KernelHWAddress)
51
52// MemorySanitizer
53SANITIZER("memory", Memory)
54
55// Kernel MemorySanitizer (KMSAN)
56SANITIZER("kernel-memory", KernelMemory)
57
58// libFuzzer
59SANITIZER("fuzzer", Fuzzer)
60
61// libFuzzer-required instrumentation, no linking.
62SANITIZER("fuzzer-no-link", FuzzerNoLink)
63
64// ThreadSanitizer
65SANITIZER("thread", Thread)
66
67// LeakSanitizer
68SANITIZER("leak", Leak)
69
70// UndefinedBehaviorSanitizer
71SANITIZER("alignment", Alignment)
72SANITIZER("array-bounds", ArrayBounds)
73SANITIZER("bool", Bool)
74SANITIZER("builtin", Builtin)
75SANITIZER("enum", Enum)
76SANITIZER("float-cast-overflow", FloatCastOverflow)
77SANITIZER("float-divide-by-zero", FloatDivideByZero)
78SANITIZER("function", Function)
79SANITIZER("integer-divide-by-zero", IntegerDivideByZero)
80SANITIZER("nonnull-attribute", NonnullAttribute)
81SANITIZER("null", Null)
82SANITIZER("nullability-arg", NullabilityArg)
83SANITIZER("nullability-assign", NullabilityAssign)
84SANITIZER("nullability-return", NullabilityReturn)
85SANITIZER_GROUP("nullability", Nullability,
86                NullabilityArg | NullabilityAssign | NullabilityReturn)
87SANITIZER("object-size", ObjectSize)
88SANITIZER("pointer-overflow", PointerOverflow)
89SANITIZER("return", Return)
90SANITIZER("returns-nonnull-attribute", ReturnsNonnullAttribute)
91SANITIZER("shift-base", ShiftBase)
92SANITIZER("shift-exponent", ShiftExponent)
93SANITIZER_GROUP("shift", Shift, ShiftBase | ShiftExponent)
94SANITIZER("signed-integer-overflow", SignedIntegerOverflow)
95SANITIZER("unreachable", Unreachable)
96SANITIZER("vla-bound", VLABound)
97SANITIZER("vptr", Vptr)
98
99// IntegerSanitizer
100SANITIZER("unsigned-integer-overflow", UnsignedIntegerOverflow)
101
102// DataFlowSanitizer
103SANITIZER("dataflow", DataFlow)
104
105// Control Flow Integrity
106SANITIZER("cfi-cast-strict", CFICastStrict)
107SANITIZER("cfi-derived-cast", CFIDerivedCast)
108SANITIZER("cfi-icall", CFIICall)
109SANITIZER("cfi-mfcall", CFIMFCall)
110SANITIZER("cfi-unrelated-cast", CFIUnrelatedCast)
111SANITIZER("cfi-nvcall", CFINVCall)
112SANITIZER("cfi-vcall", CFIVCall)
113SANITIZER_GROUP("cfi", CFI,
114                CFIDerivedCast | CFIICall | CFIMFCall | CFIUnrelatedCast |
115                    CFINVCall | CFIVCall)
116
117// Safe Stack
118SANITIZER("safe-stack", SafeStack)
119
120// Shadow Call Stack
121SANITIZER("shadow-call-stack", ShadowCallStack)
122
123// -fsanitize=undefined includes all the sanitizers which have low overhead, no
124// ABI or address space layout implications, and only catch undefined behavior.
125SANITIZER_GROUP("undefined", Undefined,
126                Alignment | Bool | Builtin | ArrayBounds | Enum |
127                    FloatCastOverflow | FloatDivideByZero |
128                    IntegerDivideByZero | NonnullAttribute | Null | ObjectSize |
129                    PointerOverflow | Return | ReturnsNonnullAttribute | Shift |
130                    SignedIntegerOverflow | Unreachable | VLABound | Function |
131                    Vptr)
132
133// -fsanitize=undefined-trap is an alias for -fsanitize=undefined.
134SANITIZER_GROUP("undefined-trap", UndefinedTrap, Undefined)
135
136// ImplicitConversionSanitizer
137SANITIZER("implicit-unsigned-integer-truncation",
138          ImplicitUnsignedIntegerTruncation)
139SANITIZER("implicit-signed-integer-truncation", ImplicitSignedIntegerTruncation)
140SANITIZER_GROUP("implicit-integer-truncation", ImplicitIntegerTruncation,
141                ImplicitUnsignedIntegerTruncation |
142                    ImplicitSignedIntegerTruncation)
143
144SANITIZER("implicit-integer-sign-change", ImplicitIntegerSignChange)
145
146SANITIZER_GROUP("implicit-integer-arithmetic-value-change",
147                ImplicitIntegerArithmeticValueChange,
148                ImplicitIntegerSignChange | ImplicitSignedIntegerTruncation)
149
150// FIXME:
151//SANITIZER_GROUP("implicit-integer-conversion", ImplicitIntegerConversion,
152//                ImplicitIntegerArithmeticValueChange |
153//                    ImplicitUnsignedIntegerTruncation)
154//SANITIZER_GROUP("implicit-conversion", ImplicitConversion,
155//                ImplicitIntegerConversion)
156
157SANITIZER_GROUP("implicit-conversion", ImplicitConversion,
158                ImplicitIntegerArithmeticValueChange |
159                    ImplicitUnsignedIntegerTruncation)
160
161SANITIZER_GROUP("integer", Integer,
162                ImplicitConversion | IntegerDivideByZero | Shift |
163                    SignedIntegerOverflow | UnsignedIntegerOverflow)
164
165SANITIZER("local-bounds", LocalBounds)
166SANITIZER_GROUP("bounds", Bounds, ArrayBounds | LocalBounds)
167
168// Scudo hardened allocator
169SANITIZER("scudo", Scudo)
170
171// Magic group, containing all sanitizers. For example, "-fno-sanitize=all"
172// can be used to disable all the sanitizers.
173SANITIZER_GROUP("all", All, ~SanitizerMask())
174
175#undef SANITIZER
176#undef SANITIZER_GROUP
177