1//===-- SanitizerHandler.h - Definition of sanitizer handlers ---*- 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 is the internal per-function state used for llvm translation.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_CODEGEN_SANITIZER_HANDLER_H
14#define LLVM_CLANG_LIB_CODEGEN_SANITIZER_HANDLER_H
15
16// To add new checks, append them to the end of this list.
17#define LIST_SANITIZER_CHECKS \
18 SANITIZER_CHECK(AddOverflow, add_overflow, 0, "Integer addition overflowed") \
19 SANITIZER_CHECK(BuiltinUnreachable, builtin_unreachable, 0, \
20 "_builtin_unreachable(), execution reached an unreachable " \
21 "program point") \
22 SANITIZER_CHECK(CFICheckFail, cfi_check_fail, 0, \
23 "Control flow integrity check failed") \
24 SANITIZER_CHECK(DivremOverflow, divrem_overflow, 0, \
25 "Integer divide or remainder overflowed") \
26 SANITIZER_CHECK(DynamicTypeCacheMiss, dynamic_type_cache_miss, 0, \
27 "Dynamic type cache miss, member call made on an object " \
28 "whose dynamic type differs from the expected type") \
29 SANITIZER_CHECK(FloatCastOverflow, float_cast_overflow, 0, \
30 "Floating-point to integer conversion overflowed") \
31 SANITIZER_CHECK(FunctionTypeMismatch, function_type_mismatch, 0, \
32 "Function called with mismatched signature") \
33 SANITIZER_CHECK(ImplicitConversion, implicit_conversion, 0, \
34 "Implicit integer conversion overflowed or lost data") \
35 SANITIZER_CHECK(InvalidBuiltin, invalid_builtin, 0, \
36 "Invalid use of builtin function") \
37 SANITIZER_CHECK(InvalidObjCCast, invalid_objc_cast, 0, \
38 "Invalid Objective-C cast") \
39 SANITIZER_CHECK(LoadInvalidValue, load_invalid_value, 0, \
40 "Loaded an invalid or uninitialized value for the type") \
41 SANITIZER_CHECK(MissingReturn, missing_return, 0, \
42 "Execution reached the end of a value-returning function " \
43 "without returning a value") \
44 SANITIZER_CHECK(MulOverflow, mul_overflow, 0, \
45 "Integer multiplication overflowed") \
46 SANITIZER_CHECK(NegateOverflow, negate_overflow, 0, \
47 "Integer negation overflowed") \
48 SANITIZER_CHECK( \
49 NullabilityArg, nullability_arg, 0, \
50 "Passing null as an argument which is annotated with _Nonnull") \
51 SANITIZER_CHECK(NullabilityReturn, nullability_return, 1, \
52 "Returning null from a function with a return type " \
53 "annotated with _Nonnull") \
54 SANITIZER_CHECK(NonnullArg, nonnull_arg, 0, \
55 "Passing null pointer as an argument which is declared to " \
56 "never be null") \
57 SANITIZER_CHECK(NonnullReturn, nonnull_return, 1, \
58 "Returning null pointer from a function which is declared " \
59 "to never return null") \
60 SANITIZER_CHECK(OutOfBounds, out_of_bounds, 0, "Array index out of bounds") \
61 SANITIZER_CHECK(PointerOverflow, pointer_overflow, 0, \
62 "Pointer arithmetic overflowed bounds") \
63 SANITIZER_CHECK(ShiftOutOfBounds, shift_out_of_bounds, 0, \
64 "Shift exponent is too large for the type") \
65 SANITIZER_CHECK(SubOverflow, sub_overflow, 0, \
66 "Integer subtraction overflowed") \
67 SANITIZER_CHECK(TypeMismatch, type_mismatch, 1, \
68 "Alignment, null, or object-size error") \
69 SANITIZER_CHECK(AlignmentAssumption, alignment_assumption, 0, \
70 "Alignment assumption violated") \
71 SANITIZER_CHECK( \
72 VLABoundNotPositive, vla_bound_not_positive, 0, \
73 "Variable length array bound evaluates to non-positive value") \
74 /* BoundsSafety Msg is empty because it is not considered part of UBSan; */ \
75 /* therefore, no trap reason is emitted for this case. */ \
76 SANITIZER_CHECK(BoundsSafety, bounds_safety, 0, "") \
77 SANITIZER_CHECK(ReturnAlignmentAssumption, return_alignment_assumption, 0, \
78 "Alignment assumption violated")
79
80enum SanitizerHandler {
81#define SANITIZER_CHECK(Enum, Name, Version, Msg) Enum,
82 LIST_SANITIZER_CHECKS
83#undef SANITIZER_CHECK
84};
85
86static_assert(BoundsSafety == 0x19,
87 "BoundsSafety must stay 0x19: it is encoded in -fbounds-safety "
88 "trap instructions (brk #0x5519, ud1l 0x19(%eax)) that debuggers "
89 "decode; append new checks at the end of LIST_SANITIZER_CHECKS");
90
91#endif // LLVM_CLANG_LIB_CODEGEN_SANITIZER_HANDLER_H
92