ubsan_handlers.h revision a82a5d360b19080f2b1beae374c12d4f26146450
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#define RECOVERABLE(checkname, ...) \ 28 extern "C" void __ubsan_handle_ ## checkname( __VA_ARGS__ ); \ 29 extern "C" void __ubsan_handle_ ## checkname ## _abort( __VA_ARGS__ ); 30 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. 34RECOVERABLE(type_mismatch, TypeMismatchData *Data, ValueHandle Pointer) 35 36struct OverflowData { 37 SourceLocation Loc; 38 const TypeDescriptor &Type; 39}; 40 41/// \brief Handle an integer addition overflow. 42RECOVERABLE(add_overflow, OverflowData *Data, ValueHandle LHS, ValueHandle RHS) 43 44/// \brief Handle an integer subtraction overflow. 45RECOVERABLE(sub_overflow, OverflowData *Data, ValueHandle LHS, ValueHandle RHS) 46 47/// \brief Handle an integer multiplication overflow. 48RECOVERABLE(mul_overflow, OverflowData *Data, ValueHandle LHS, ValueHandle RHS) 49 50/// \brief Handle a signed integer overflow for a unary negate operator. 51RECOVERABLE(negate_overflow, OverflowData *Data, ValueHandle OldVal) 52 53/// \brief Handle an INT_MIN/-1 overflow or division by zero. 54RECOVERABLE(divrem_overflow, OverflowData *Data, 55 ValueHandle LHS, ValueHandle RHS) 56 57struct ShiftOutOfBoundsData { 58 SourceLocation Loc; 59 const TypeDescriptor &LHSType; 60 const TypeDescriptor &RHSType; 61}; 62 63/// \brief Handle a shift where the RHS is out of bounds or a left shift where 64/// the LHS is negative or overflows. 65RECOVERABLE(shift_out_of_bounds, ShiftOutOfBoundsData *Data, 66 ValueHandle LHS, ValueHandle RHS) 67 68struct UnreachableData { 69 SourceLocation Loc; 70}; 71 72/// \brief Handle a __builtin_unreachable which is reached. 73extern "C" void __ubsan_handle_builtin_unreachable(UnreachableData *Data); 74/// \brief Handle reaching the end of a value-returning function. 75extern "C" void __ubsan_handle_missing_return(UnreachableData *Data); 76 77struct VLABoundData { 78 SourceLocation Loc; 79 const TypeDescriptor &Type; 80}; 81 82/// \brief Handle a VLA with a non-positive bound. 83RECOVERABLE(vla_bound_not_positive, VLABoundData *Data, ValueHandle Bound) 84 85struct FloatCastOverflowData { 86 // FIXME: SourceLocation Loc; 87 const TypeDescriptor &FromType; 88 const TypeDescriptor &ToType; 89}; 90 91/// \brief Handle overflow in a conversion to or from a floating-point type. 92RECOVERABLE(float_cast_overflow, FloatCastOverflowData *Data, ValueHandle From) 93 94} 95 96#endif // UBSAN_HANDLERS_H 97