* crtstuff.c (USE_EH_FRAME_REGISTRY): Let USE_EH_FRAME_REGISTRY_ALWAYS
[official-gcc.git] / libsanitizer / ubsan / ubsan_handlers.h
blob641fbfe993f97ad91ff9718c73b0c3ee3f47b4fc
1 //===-- ubsan_handlers.h ----------------------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // Entry points to the runtime library for Clang's undefined behavior sanitizer.
9 //
10 //===----------------------------------------------------------------------===//
11 #ifndef UBSAN_HANDLERS_H
12 #define UBSAN_HANDLERS_H
14 #include "ubsan_value.h"
16 namespace __ubsan {
18 struct TypeMismatchData {
19 SourceLocation Loc;
20 const TypeDescriptor &Type;
21 uptr Alignment;
22 unsigned char TypeCheckKind;
25 #define RECOVERABLE(checkname, ...) \
26 extern "C" SANITIZER_INTERFACE_ATTRIBUTE \
27 void __ubsan_handle_ ## checkname( __VA_ARGS__ ); \
28 extern "C" SANITIZER_INTERFACE_ATTRIBUTE \
29 void __ubsan_handle_ ## checkname ## _abort( __VA_ARGS__ );
31 /// \brief Handle a runtime type check failure, caused by either a misaligned
32 /// pointer, a null pointer, or a pointer to insufficient storage for the
33 /// type.
34 RECOVERABLE(type_mismatch, TypeMismatchData *Data, ValueHandle Pointer)
36 struct OverflowData {
37 SourceLocation Loc;
38 const TypeDescriptor &Type;
41 /// \brief Handle an integer addition overflow.
42 RECOVERABLE(add_overflow, OverflowData *Data, ValueHandle LHS, ValueHandle RHS)
44 /// \brief Handle an integer subtraction overflow.
45 RECOVERABLE(sub_overflow, OverflowData *Data, ValueHandle LHS, ValueHandle RHS)
47 /// \brief Handle an integer multiplication overflow.
48 RECOVERABLE(mul_overflow, OverflowData *Data, ValueHandle LHS, ValueHandle RHS)
50 /// \brief Handle a signed integer overflow for a unary negate operator.
51 RECOVERABLE(negate_overflow, OverflowData *Data, ValueHandle OldVal)
53 /// \brief Handle an INT_MIN/-1 overflow or division by zero.
54 RECOVERABLE(divrem_overflow, OverflowData *Data,
55 ValueHandle LHS, ValueHandle RHS)
57 struct ShiftOutOfBoundsData {
58 SourceLocation Loc;
59 const TypeDescriptor &LHSType;
60 const TypeDescriptor &RHSType;
63 /// \brief Handle a shift where the RHS is out of bounds or a left shift where
64 /// the LHS is negative or overflows.
65 RECOVERABLE(shift_out_of_bounds, ShiftOutOfBoundsData *Data,
66 ValueHandle LHS, ValueHandle RHS)
68 struct OutOfBoundsData {
69 SourceLocation Loc;
70 const TypeDescriptor &ArrayType;
71 const TypeDescriptor &IndexType;
74 /// \brief Handle an array index out of bounds error.
75 RECOVERABLE(out_of_bounds, OutOfBoundsData *Data, ValueHandle Index)
77 struct UnreachableData {
78 SourceLocation Loc;
81 /// \brief Handle a __builtin_unreachable which is reached.
82 extern "C" SANITIZER_INTERFACE_ATTRIBUTE
83 void __ubsan_handle_builtin_unreachable(UnreachableData *Data);
84 /// \brief Handle reaching the end of a value-returning function.
85 extern "C" SANITIZER_INTERFACE_ATTRIBUTE
86 void __ubsan_handle_missing_return(UnreachableData *Data);
88 struct VLABoundData {
89 SourceLocation Loc;
90 const TypeDescriptor &Type;
93 /// \brief Handle a VLA with a non-positive bound.
94 RECOVERABLE(vla_bound_not_positive, VLABoundData *Data, ValueHandle Bound)
96 struct FloatCastOverflowData {
97 // FIXME: SourceLocation Loc;
98 const TypeDescriptor &FromType;
99 const TypeDescriptor &ToType;
102 /// \brief Handle overflow in a conversion to or from a floating-point type.
103 RECOVERABLE(float_cast_overflow, FloatCastOverflowData *Data, ValueHandle From)
105 struct InvalidValueData {
106 SourceLocation Loc;
107 const TypeDescriptor &Type;
110 /// \brief Handle a load of an invalid value for the type.
111 RECOVERABLE(load_invalid_value, InvalidValueData *Data, ValueHandle Val)
113 struct FunctionTypeMismatchData {
114 SourceLocation Loc;
115 const TypeDescriptor &Type;
118 RECOVERABLE(function_type_mismatch,
119 FunctionTypeMismatchData *Data,
120 ValueHandle Val)
122 struct NonNullReturnData {
123 SourceLocation Loc;
124 SourceLocation AttrLoc;
127 /// \brief Handle returning null from function with returns_nonnull attribute.
128 RECOVERABLE(nonnull_return, NonNullReturnData *Data)
130 struct NonNullArgData {
131 SourceLocation Loc;
132 SourceLocation AttrLoc;
133 int ArgIndex;
136 /// \brief Handle passing null pointer to function with nonnull attribute.
137 RECOVERABLE(nonnull_arg, NonNullArgData *Data)
141 #endif // UBSAN_HANDLERS_H