ubsan_handlers.h revision 58561700a4abad310911a24a867da49a14fae91e
1//===-- ubsan_handlers.h ----------------------------------------*- 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// Entry points to the runtime library for Clang's undefined behavior sanitizer.
11//
12//===----------------------------------------------------------------------===//
13#ifndef UBSAN_HANDLERS_H
14#define UBSAN_HANDLERS_H
15
16#include "ubsan_value.h"
17
18namespace __ubsan {
19
20struct TypeMismatchData {
21  SourceLocation Loc;
22  const TypeDescriptor &Type;
23  uptr Alignment;
24  unsigned char TypeCheckKind;
25};
26
27/// \brief Handle a runtime type check failure, caused by either a misaligned
28/// pointer, a null pointer, or a pointer to insufficient storage for the
29/// type.
30extern "C" void __ubsan_handle_type_mismatch(TypeMismatchData *Data,
31                                             ValueHandle Pointer);
32
33struct OverflowData {
34  SourceLocation Loc;
35  const TypeDescriptor &Type;
36};
37
38/// \brief Handle a signed integer addition overflow.
39extern "C" void __ubsan_handle_add_overflow(OverflowData *Data,
40                                            ValueHandle LHS,
41                                            ValueHandle RHS);
42/// \brief Handle a signed integer subtraction overflow.
43extern "C" void __ubsan_handle_sub_overflow(OverflowData *Data,
44                                            ValueHandle LHS,
45                                            ValueHandle RHS);
46/// \brief Handle a signed integer multiplication overflow.
47extern "C" void __ubsan_handle_mul_overflow(OverflowData *Data,
48                                            ValueHandle LHS,
49                                            ValueHandle RHS);
50/// \brief Handle a signed integer overflow for a unary negate operator.
51extern "C" void __ubsan_handle_negate_overflow(OverflowData *Data,
52                                               ValueHandle OldVal);
53/// \brief Handle an INT_MIN/-1 overflow or division by zero.
54extern "C" void __ubsan_handle_divrem_overflow(OverflowData *Data,
55                                               ValueHandle LHS,
56                                               ValueHandle RHS);
57
58struct ShiftOutOfBoundsData {
59  SourceLocation Loc;
60  const TypeDescriptor &LHSType;
61  const TypeDescriptor &RHSType;
62};
63
64/// \brief Handle a shift where the RHS is out of bounds or a left shift where
65/// the LHS is negative or overflows.
66extern "C" void __ubsan_handle_shift_out_of_bounds(ShiftOutOfBoundsData *Data,
67                                                   ValueHandle LHS,
68                                                   ValueHandle RHS);
69
70struct UnreachableData {
71  SourceLocation Loc;
72};
73
74/// \brief Handle a __builtin_unreachable which is reached.
75extern "C" void __ubsan_handle_builtin_unreachable(UnreachableData *Data);
76/// \brief Handle reaching the end of a value-returning function.
77extern "C" void __ubsan_handle_missing_return(UnreachableData *Data);
78
79struct VLABoundData {
80  SourceLocation Loc;
81  const TypeDescriptor &Type;
82};
83
84/// \brief Handle a VLA with a non-positive bound.
85extern "C" void __ubsan_handle_vla_bound_not_positive(VLABoundData *Data,
86                                                      ValueHandle Bound);
87
88struct FloatCastOverflowData {
89  // FIXME: SourceLocation Loc;
90  const TypeDescriptor &FromType;
91  const TypeDescriptor &ToType;
92};
93
94/// \brief Handle overflow in a conversion to or from a floating-point type.
95extern "C" void __ubsan_handle_float_cast_overflow(FloatCastOverflowData *Data,
96                                                   ValueHandle From);
97
98}
99
100#endif // UBSAN_HANDLERS_H
101