2012-10-10 03:34:32 +08:00
|
|
|
//===-- ubsan_handlers.h ----------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Entry points to the runtime library for Clang's undefined behavior sanitizer.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef UBSAN_HANDLERS_H
|
|
|
|
#define UBSAN_HANDLERS_H
|
|
|
|
|
|
|
|
#include "ubsan_value.h"
|
|
|
|
|
|
|
|
namespace __ubsan {
|
|
|
|
|
|
|
|
struct TypeMismatchData {
|
|
|
|
SourceLocation Loc;
|
|
|
|
const TypeDescriptor &Type;
|
|
|
|
uptr Alignment;
|
|
|
|
unsigned char TypeCheckKind;
|
|
|
|
};
|
|
|
|
|
2012-12-03 03:47:29 +08:00
|
|
|
#define RECOVERABLE(checkname, ...) \
|
2013-01-11 01:01:13 +08:00
|
|
|
extern "C" SANITIZER_INTERFACE_ATTRIBUTE \
|
|
|
|
void __ubsan_handle_ ## checkname( __VA_ARGS__ ); \
|
|
|
|
extern "C" SANITIZER_INTERFACE_ATTRIBUTE \
|
|
|
|
void __ubsan_handle_ ## checkname ## _abort( __VA_ARGS__ );
|
2012-12-03 03:47:29 +08:00
|
|
|
|
2012-10-10 03:34:32 +08:00
|
|
|
/// \brief Handle a runtime type check failure, caused by either a misaligned
|
|
|
|
/// pointer, a null pointer, or a pointer to insufficient storage for the
|
|
|
|
/// type.
|
2012-12-03 03:47:29 +08:00
|
|
|
RECOVERABLE(type_mismatch, TypeMismatchData *Data, ValueHandle Pointer)
|
2012-10-10 03:34:32 +08:00
|
|
|
|
|
|
|
struct OverflowData {
|
|
|
|
SourceLocation Loc;
|
|
|
|
const TypeDescriptor &Type;
|
|
|
|
};
|
|
|
|
|
2012-11-27 23:01:43 +08:00
|
|
|
/// \brief Handle an integer addition overflow.
|
2012-12-03 03:47:29 +08:00
|
|
|
RECOVERABLE(add_overflow, OverflowData *Data, ValueHandle LHS, ValueHandle RHS)
|
|
|
|
|
2012-11-27 23:01:43 +08:00
|
|
|
/// \brief Handle an integer subtraction overflow.
|
2012-12-03 03:47:29 +08:00
|
|
|
RECOVERABLE(sub_overflow, OverflowData *Data, ValueHandle LHS, ValueHandle RHS)
|
|
|
|
|
2012-11-27 23:01:43 +08:00
|
|
|
/// \brief Handle an integer multiplication overflow.
|
2012-12-03 03:47:29 +08:00
|
|
|
RECOVERABLE(mul_overflow, OverflowData *Data, ValueHandle LHS, ValueHandle RHS)
|
|
|
|
|
2012-10-10 03:34:32 +08:00
|
|
|
/// \brief Handle a signed integer overflow for a unary negate operator.
|
2012-12-03 03:47:29 +08:00
|
|
|
RECOVERABLE(negate_overflow, OverflowData *Data, ValueHandle OldVal)
|
|
|
|
|
2012-10-10 03:34:32 +08:00
|
|
|
/// \brief Handle an INT_MIN/-1 overflow or division by zero.
|
2012-12-03 03:47:29 +08:00
|
|
|
RECOVERABLE(divrem_overflow, OverflowData *Data,
|
|
|
|
ValueHandle LHS, ValueHandle RHS)
|
2012-10-10 03:34:32 +08:00
|
|
|
|
|
|
|
struct ShiftOutOfBoundsData {
|
|
|
|
SourceLocation Loc;
|
|
|
|
const TypeDescriptor &LHSType;
|
|
|
|
const TypeDescriptor &RHSType;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Handle a shift where the RHS is out of bounds or a left shift where
|
|
|
|
/// the LHS is negative or overflows.
|
2012-12-03 03:47:29 +08:00
|
|
|
RECOVERABLE(shift_out_of_bounds, ShiftOutOfBoundsData *Data,
|
|
|
|
ValueHandle LHS, ValueHandle RHS)
|
2012-10-10 03:34:32 +08:00
|
|
|
|
2013-02-23 10:40:07 +08:00
|
|
|
struct OutOfBoundsData {
|
|
|
|
SourceLocation Loc;
|
|
|
|
const TypeDescriptor &ArrayType;
|
|
|
|
const TypeDescriptor &IndexType;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Handle an array index out of bounds error.
|
|
|
|
RECOVERABLE(out_of_bounds, OutOfBoundsData *Data, ValueHandle Index)
|
|
|
|
|
2012-10-10 03:34:32 +08:00
|
|
|
struct UnreachableData {
|
|
|
|
SourceLocation Loc;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Handle a __builtin_unreachable which is reached.
|
2013-01-11 01:01:13 +08:00
|
|
|
extern "C" SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __ubsan_handle_builtin_unreachable(UnreachableData *Data);
|
2012-10-10 03:34:32 +08:00
|
|
|
/// \brief Handle reaching the end of a value-returning function.
|
2013-01-11 01:01:13 +08:00
|
|
|
extern "C" SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __ubsan_handle_missing_return(UnreachableData *Data);
|
2012-10-10 03:34:32 +08:00
|
|
|
|
2012-10-10 09:10:59 +08:00
|
|
|
struct VLABoundData {
|
|
|
|
SourceLocation Loc;
|
|
|
|
const TypeDescriptor &Type;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Handle a VLA with a non-positive bound.
|
2012-12-03 03:47:29 +08:00
|
|
|
RECOVERABLE(vla_bound_not_positive, VLABoundData *Data, ValueHandle Bound)
|
2012-10-10 09:10:59 +08:00
|
|
|
|
2012-10-13 06:57:15 +08:00
|
|
|
struct FloatCastOverflowData {
|
|
|
|
// FIXME: SourceLocation Loc;
|
|
|
|
const TypeDescriptor &FromType;
|
|
|
|
const TypeDescriptor &ToType;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Handle overflow in a conversion to or from a floating-point type.
|
2012-12-03 03:47:29 +08:00
|
|
|
RECOVERABLE(float_cast_overflow, FloatCastOverflowData *Data, ValueHandle From)
|
2012-10-13 06:57:15 +08:00
|
|
|
|
2012-12-13 15:00:14 +08:00
|
|
|
struct InvalidValueData {
|
2013-10-02 10:29:47 +08:00
|
|
|
SourceLocation Loc;
|
2012-12-13 15:00:14 +08:00
|
|
|
const TypeDescriptor &Type;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Handle a load of an invalid value for the type.
|
|
|
|
RECOVERABLE(load_invalid_value, InvalidValueData *Data, ValueHandle Val)
|
|
|
|
|
2012-10-10 03:34:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // UBSAN_HANDLERS_H
|