2012-10-25 10:07:02 +08:00
|
|
|
//===-- ubsan_handlers.cc -------------------------------------------------===//
|
2012-10-10 03:34:32 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Error logging entry points for the UBSan runtime.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ubsan_handlers.h"
|
|
|
|
#include "ubsan_diag.h"
|
|
|
|
|
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
|
|
|
|
|
|
|
using namespace __sanitizer;
|
|
|
|
using namespace __ubsan;
|
|
|
|
|
2014-09-11 04:43:36 +08:00
|
|
|
static bool ignoreReport(SourceLocation SLoc, ReportOptions Opts) {
|
|
|
|
// If source location is already acquired, we don't need to print an error
|
|
|
|
// report for the second time. However, if we're in an unrecoverable handler,
|
|
|
|
// it's possible that location was required by concurrently running thread.
|
|
|
|
// In this case, we should continue the execution to ensure that any of
|
|
|
|
// threads will grab the report mutex and print the report before
|
|
|
|
// crashing the program.
|
|
|
|
return SLoc.isDisabled() && !Opts.DieAfterReport;
|
|
|
|
}
|
|
|
|
|
2012-10-25 10:07:02 +08:00
|
|
|
namespace __ubsan {
|
2014-10-14 07:59:00 +08:00
|
|
|
const char *TypeCheckKinds[] = {
|
2012-10-10 03:34:32 +08:00
|
|
|
"load of", "store to", "reference binding to", "member access within",
|
2014-10-14 07:59:00 +08:00
|
|
|
"member call on", "constructor call on", "downcast of", "downcast of",
|
|
|
|
"upcast of", "cast to virtual base of"};
|
2012-10-25 10:07:02 +08:00
|
|
|
}
|
|
|
|
|
2012-12-18 12:23:18 +08:00
|
|
|
static void handleTypeMismatchImpl(TypeMismatchData *Data, ValueHandle Pointer,
|
2015-02-11 03:50:20 +08:00
|
|
|
ReportOptions Opts) {
|
2013-01-09 11:40:03 +08:00
|
|
|
Location Loc = Data->Loc.acquire();
|
|
|
|
// Use the SourceLocation from Data to track deduplication, even if 'invalid'
|
2014-09-11 04:43:36 +08:00
|
|
|
if (ignoreReport(Loc.getSourceLocation(), Opts))
|
2013-01-09 11:40:03 +08:00
|
|
|
return;
|
2014-07-30 09:49:19 +08:00
|
|
|
|
2012-12-18 12:23:18 +08:00
|
|
|
if (Data->Loc.isInvalid())
|
2015-02-11 03:50:20 +08:00
|
|
|
Loc = getCallerLocation(Opts.pc);
|
2012-12-18 12:23:18 +08:00
|
|
|
|
2014-09-20 02:33:45 +08:00
|
|
|
ScopedReport R(Opts, Loc);
|
|
|
|
|
2012-10-10 03:34:32 +08:00
|
|
|
if (!Pointer)
|
2012-12-18 14:30:32 +08:00
|
|
|
Diag(Loc, DL_Error, "%0 null pointer of type %1")
|
2012-10-10 03:34:32 +08:00
|
|
|
<< TypeCheckKinds[Data->TypeCheckKind] << Data->Type;
|
|
|
|
else if (Data->Alignment && (Pointer & (Data->Alignment - 1)))
|
2012-12-18 14:30:32 +08:00
|
|
|
Diag(Loc, DL_Error, "%0 misaligned address %1 for type %3, "
|
|
|
|
"which requires %2 byte alignment")
|
2012-10-10 03:34:32 +08:00
|
|
|
<< TypeCheckKinds[Data->TypeCheckKind] << (void*)Pointer
|
|
|
|
<< Data->Alignment << Data->Type;
|
|
|
|
else
|
2012-12-18 14:30:32 +08:00
|
|
|
Diag(Loc, DL_Error, "%0 address %1 with insufficient space "
|
|
|
|
"for an object of type %2")
|
2012-10-10 03:34:32 +08:00
|
|
|
<< TypeCheckKinds[Data->TypeCheckKind] << (void*)Pointer << Data->Type;
|
2012-12-18 14:30:32 +08:00
|
|
|
if (Pointer)
|
|
|
|
Diag(Pointer, DL_Note, "pointer points here");
|
2012-12-03 03:47:29 +08:00
|
|
|
}
|
2014-07-30 09:49:19 +08:00
|
|
|
|
2012-12-18 12:23:18 +08:00
|
|
|
void __ubsan::__ubsan_handle_type_mismatch(TypeMismatchData *Data,
|
|
|
|
ValueHandle Pointer) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(false);
|
2015-02-11 03:50:20 +08:00
|
|
|
handleTypeMismatchImpl(Data, Pointer, Opts);
|
2012-12-18 12:23:18 +08:00
|
|
|
}
|
2012-12-03 03:47:29 +08:00
|
|
|
void __ubsan::__ubsan_handle_type_mismatch_abort(TypeMismatchData *Data,
|
2012-12-18 12:23:18 +08:00
|
|
|
ValueHandle Pointer) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(true);
|
2015-02-11 03:50:20 +08:00
|
|
|
handleTypeMismatchImpl(Data, Pointer, Opts);
|
2014-09-11 04:43:36 +08:00
|
|
|
Die();
|
2012-10-10 03:34:32 +08:00
|
|
|
}
|
|
|
|
|
2012-11-27 23:01:43 +08:00
|
|
|
/// \brief Common diagnostic emission for various forms of integer overflow.
|
2014-07-30 09:49:19 +08:00
|
|
|
template <typename T>
|
|
|
|
static void handleIntegerOverflowImpl(OverflowData *Data, ValueHandle LHS,
|
2014-08-23 05:42:04 +08:00
|
|
|
const char *Operator, T RHS,
|
|
|
|
ReportOptions Opts) {
|
2013-01-09 11:40:03 +08:00
|
|
|
SourceLocation Loc = Data->Loc.acquire();
|
2014-09-11 04:43:36 +08:00
|
|
|
if (ignoreReport(Loc, Opts))
|
2013-01-09 11:40:03 +08:00
|
|
|
return;
|
|
|
|
|
2014-09-20 02:33:45 +08:00
|
|
|
ScopedReport R(Opts, Loc);
|
2014-07-30 09:49:19 +08:00
|
|
|
|
2013-01-09 11:40:03 +08:00
|
|
|
Diag(Loc, DL_Error, "%0 integer overflow: "
|
|
|
|
"%1 %2 %3 cannot be represented in type %4")
|
2012-11-27 23:01:43 +08:00
|
|
|
<< (Data->Type.isSignedIntegerTy() ? "signed" : "unsigned")
|
2012-10-10 03:34:32 +08:00
|
|
|
<< Value(Data->Type, LHS) << Operator << RHS << Data->Type;
|
|
|
|
}
|
|
|
|
|
2014-07-30 09:49:19 +08:00
|
|
|
#define UBSAN_OVERFLOW_HANDLER(handler_name, op, abort) \
|
|
|
|
void __ubsan::handler_name(OverflowData *Data, ValueHandle LHS, \
|
|
|
|
ValueHandle RHS) { \
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(abort); \
|
|
|
|
handleIntegerOverflowImpl(Data, LHS, op, Value(Data->Type, RHS), Opts); \
|
2014-09-11 04:43:36 +08:00
|
|
|
if (abort) Die(); \
|
2014-07-30 09:49:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
UBSAN_OVERFLOW_HANDLER(__ubsan_handle_add_overflow, "+", false)
|
|
|
|
UBSAN_OVERFLOW_HANDLER(__ubsan_handle_add_overflow_abort, "+", true)
|
|
|
|
UBSAN_OVERFLOW_HANDLER(__ubsan_handle_sub_overflow, "-", false)
|
|
|
|
UBSAN_OVERFLOW_HANDLER(__ubsan_handle_sub_overflow_abort, "-", true)
|
|
|
|
UBSAN_OVERFLOW_HANDLER(__ubsan_handle_mul_overflow, "*", false)
|
|
|
|
UBSAN_OVERFLOW_HANDLER(__ubsan_handle_mul_overflow_abort, "*", true)
|
|
|
|
|
|
|
|
static void handleNegateOverflowImpl(OverflowData *Data, ValueHandle OldVal,
|
2014-08-23 05:42:04 +08:00
|
|
|
ReportOptions Opts) {
|
2013-01-09 11:40:03 +08:00
|
|
|
SourceLocation Loc = Data->Loc.acquire();
|
2014-09-11 04:43:36 +08:00
|
|
|
if (ignoreReport(Loc, Opts))
|
2013-01-09 11:40:03 +08:00
|
|
|
return;
|
|
|
|
|
2014-09-20 02:33:45 +08:00
|
|
|
ScopedReport R(Opts, Loc);
|
2014-07-30 09:49:19 +08:00
|
|
|
|
2012-12-31 14:36:44 +08:00
|
|
|
if (Data->Type.isSignedIntegerTy())
|
2013-01-09 11:40:03 +08:00
|
|
|
Diag(Loc, DL_Error,
|
2012-12-31 14:36:44 +08:00
|
|
|
"negation of %0 cannot be represented in type %1; "
|
|
|
|
"cast to an unsigned type to negate this value to itself")
|
|
|
|
<< Value(Data->Type, OldVal) << Data->Type;
|
|
|
|
else
|
2013-01-09 11:40:03 +08:00
|
|
|
Diag(Loc, DL_Error,
|
2012-12-31 14:36:44 +08:00
|
|
|
"negation of %0 cannot be represented in type %1")
|
|
|
|
<< Value(Data->Type, OldVal) << Data->Type;
|
2012-12-03 03:47:29 +08:00
|
|
|
}
|
2014-07-30 09:49:19 +08:00
|
|
|
|
|
|
|
void __ubsan::__ubsan_handle_negate_overflow(OverflowData *Data,
|
|
|
|
ValueHandle OldVal) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(false);
|
|
|
|
handleNegateOverflowImpl(Data, OldVal, Opts);
|
2014-07-30 09:49:19 +08:00
|
|
|
}
|
2012-12-03 03:47:29 +08:00
|
|
|
void __ubsan::__ubsan_handle_negate_overflow_abort(OverflowData *Data,
|
|
|
|
ValueHandle OldVal) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(true);
|
|
|
|
handleNegateOverflowImpl(Data, OldVal, Opts);
|
2014-09-11 04:43:36 +08:00
|
|
|
Die();
|
2012-10-10 03:34:32 +08:00
|
|
|
}
|
|
|
|
|
2014-07-30 09:49:19 +08:00
|
|
|
static void handleDivremOverflowImpl(OverflowData *Data, ValueHandle LHS,
|
2014-08-23 05:42:04 +08:00
|
|
|
ValueHandle RHS, ReportOptions Opts) {
|
2013-01-09 11:40:03 +08:00
|
|
|
SourceLocation Loc = Data->Loc.acquire();
|
2014-09-11 04:43:36 +08:00
|
|
|
if (ignoreReport(Loc, Opts))
|
2013-01-09 11:40:03 +08:00
|
|
|
return;
|
|
|
|
|
2014-09-20 02:33:45 +08:00
|
|
|
ScopedReport R(Opts, Loc);
|
2014-07-30 09:49:19 +08:00
|
|
|
|
2012-10-10 03:34:32 +08:00
|
|
|
Value LHSVal(Data->Type, LHS);
|
|
|
|
Value RHSVal(Data->Type, RHS);
|
|
|
|
if (RHSVal.isMinusOne())
|
2013-01-09 11:40:03 +08:00
|
|
|
Diag(Loc, DL_Error,
|
2012-12-18 14:30:32 +08:00
|
|
|
"division of %0 by -1 cannot be represented in type %1")
|
2012-10-10 03:34:32 +08:00
|
|
|
<< LHSVal << Data->Type;
|
|
|
|
else
|
2013-01-09 11:40:03 +08:00
|
|
|
Diag(Loc, DL_Error, "division by zero");
|
2012-12-03 03:47:29 +08:00
|
|
|
}
|
2014-07-30 09:49:19 +08:00
|
|
|
|
|
|
|
void __ubsan::__ubsan_handle_divrem_overflow(OverflowData *Data,
|
|
|
|
ValueHandle LHS, ValueHandle RHS) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(false);
|
|
|
|
handleDivremOverflowImpl(Data, LHS, RHS, Opts);
|
2014-07-30 09:49:19 +08:00
|
|
|
}
|
2012-12-03 03:47:29 +08:00
|
|
|
void __ubsan::__ubsan_handle_divrem_overflow_abort(OverflowData *Data,
|
|
|
|
ValueHandle LHS,
|
|
|
|
ValueHandle RHS) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(true);
|
|
|
|
handleDivremOverflowImpl(Data, LHS, RHS, Opts);
|
2014-09-11 04:43:36 +08:00
|
|
|
Die();
|
2012-10-10 03:34:32 +08:00
|
|
|
}
|
|
|
|
|
2014-07-30 09:49:19 +08:00
|
|
|
static void handleShiftOutOfBoundsImpl(ShiftOutOfBoundsData *Data,
|
|
|
|
ValueHandle LHS, ValueHandle RHS,
|
2014-08-23 05:42:04 +08:00
|
|
|
ReportOptions Opts) {
|
2013-01-09 11:40:03 +08:00
|
|
|
SourceLocation Loc = Data->Loc.acquire();
|
2014-09-11 04:43:36 +08:00
|
|
|
if (ignoreReport(Loc, Opts))
|
2013-01-09 11:40:03 +08:00
|
|
|
return;
|
|
|
|
|
2014-09-20 02:33:45 +08:00
|
|
|
ScopedReport R(Opts, Loc);
|
2014-07-30 09:49:19 +08:00
|
|
|
|
2012-10-10 03:34:32 +08:00
|
|
|
Value LHSVal(Data->LHSType, LHS);
|
|
|
|
Value RHSVal(Data->RHSType, RHS);
|
|
|
|
if (RHSVal.isNegative())
|
2013-01-09 11:40:03 +08:00
|
|
|
Diag(Loc, DL_Error, "shift exponent %0 is negative") << RHSVal;
|
2012-10-10 03:34:32 +08:00
|
|
|
else if (RHSVal.getPositiveIntValue() >= Data->LHSType.getIntegerBitWidth())
|
2013-01-09 11:40:03 +08:00
|
|
|
Diag(Loc, DL_Error,
|
2012-12-18 14:30:32 +08:00
|
|
|
"shift exponent %0 is too large for %1-bit type %2")
|
2012-10-10 03:34:32 +08:00
|
|
|
<< RHSVal << Data->LHSType.getIntegerBitWidth() << Data->LHSType;
|
|
|
|
else if (LHSVal.isNegative())
|
2013-01-09 11:40:03 +08:00
|
|
|
Diag(Loc, DL_Error, "left shift of negative value %0") << LHSVal;
|
2012-10-10 03:34:32 +08:00
|
|
|
else
|
2013-01-09 11:40:03 +08:00
|
|
|
Diag(Loc, DL_Error,
|
2012-12-18 14:30:32 +08:00
|
|
|
"left shift of %0 by %1 places cannot be represented in type %2")
|
|
|
|
<< LHSVal << RHSVal << Data->LHSType;
|
2012-12-03 03:47:29 +08:00
|
|
|
}
|
2014-07-30 09:49:19 +08:00
|
|
|
|
|
|
|
void __ubsan::__ubsan_handle_shift_out_of_bounds(ShiftOutOfBoundsData *Data,
|
|
|
|
ValueHandle LHS,
|
|
|
|
ValueHandle RHS) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(false);
|
|
|
|
handleShiftOutOfBoundsImpl(Data, LHS, RHS, Opts);
|
2014-07-30 09:49:19 +08:00
|
|
|
}
|
2012-12-03 03:47:29 +08:00
|
|
|
void __ubsan::__ubsan_handle_shift_out_of_bounds_abort(
|
|
|
|
ShiftOutOfBoundsData *Data,
|
|
|
|
ValueHandle LHS,
|
|
|
|
ValueHandle RHS) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(true);
|
|
|
|
handleShiftOutOfBoundsImpl(Data, LHS, RHS, Opts);
|
2014-09-11 04:43:36 +08:00
|
|
|
Die();
|
2012-10-10 03:34:32 +08:00
|
|
|
}
|
|
|
|
|
2014-07-30 09:49:19 +08:00
|
|
|
static void handleOutOfBoundsImpl(OutOfBoundsData *Data, ValueHandle Index,
|
2014-08-23 05:42:04 +08:00
|
|
|
ReportOptions Opts) {
|
2013-02-23 10:40:07 +08:00
|
|
|
SourceLocation Loc = Data->Loc.acquire();
|
2014-09-11 04:43:36 +08:00
|
|
|
if (ignoreReport(Loc, Opts))
|
2013-02-23 10:40:07 +08:00
|
|
|
return;
|
|
|
|
|
2014-09-20 02:33:45 +08:00
|
|
|
ScopedReport R(Opts, Loc);
|
2014-07-30 09:49:19 +08:00
|
|
|
|
2013-02-23 10:40:07 +08:00
|
|
|
Value IndexVal(Data->IndexType, Index);
|
|
|
|
Diag(Loc, DL_Error, "index %0 out of bounds for type %1")
|
|
|
|
<< IndexVal << Data->ArrayType;
|
|
|
|
}
|
2014-07-30 09:49:19 +08:00
|
|
|
|
|
|
|
void __ubsan::__ubsan_handle_out_of_bounds(OutOfBoundsData *Data,
|
|
|
|
ValueHandle Index) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(false);
|
|
|
|
handleOutOfBoundsImpl(Data, Index, Opts);
|
2014-07-30 09:49:19 +08:00
|
|
|
}
|
2013-02-23 10:40:07 +08:00
|
|
|
void __ubsan::__ubsan_handle_out_of_bounds_abort(OutOfBoundsData *Data,
|
|
|
|
ValueHandle Index) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(true);
|
|
|
|
handleOutOfBoundsImpl(Data, Index, Opts);
|
2014-09-11 04:43:36 +08:00
|
|
|
Die();
|
2013-02-23 10:40:07 +08:00
|
|
|
}
|
|
|
|
|
2014-09-11 04:43:36 +08:00
|
|
|
static void handleBuiltinUnreachableImpl(UnreachableData *Data,
|
|
|
|
ReportOptions Opts) {
|
2014-09-20 02:33:45 +08:00
|
|
|
ScopedReport R(Opts, Data->Loc);
|
2012-12-18 14:30:32 +08:00
|
|
|
Diag(Data->Loc, DL_Error, "execution reached a __builtin_unreachable() call");
|
2012-10-10 03:34:32 +08:00
|
|
|
}
|
|
|
|
|
2014-09-11 04:43:36 +08:00
|
|
|
void __ubsan::__ubsan_handle_builtin_unreachable(UnreachableData *Data) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(true);
|
2014-09-11 04:43:36 +08:00
|
|
|
handleBuiltinUnreachableImpl(Data, Opts);
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handleMissingReturnImpl(UnreachableData *Data, ReportOptions Opts) {
|
2014-09-20 02:33:45 +08:00
|
|
|
ScopedReport R(Opts, Data->Loc);
|
2012-12-18 14:30:32 +08:00
|
|
|
Diag(Data->Loc, DL_Error,
|
|
|
|
"execution reached the end of a value-returning function "
|
|
|
|
"without returning a value");
|
2012-10-10 03:34:32 +08:00
|
|
|
}
|
2012-10-10 09:10:59 +08:00
|
|
|
|
2014-09-11 04:43:36 +08:00
|
|
|
void __ubsan::__ubsan_handle_missing_return(UnreachableData *Data) {
|
|
|
|
GET_REPORT_OPTIONS(true);
|
|
|
|
handleMissingReturnImpl(Data, Opts);
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
2014-07-30 09:49:19 +08:00
|
|
|
static void handleVLABoundNotPositive(VLABoundData *Data, ValueHandle Bound,
|
2014-08-23 05:42:04 +08:00
|
|
|
ReportOptions Opts) {
|
2013-01-09 11:40:03 +08:00
|
|
|
SourceLocation Loc = Data->Loc.acquire();
|
2014-09-11 04:43:36 +08:00
|
|
|
if (ignoreReport(Loc, Opts))
|
2013-01-09 11:40:03 +08:00
|
|
|
return;
|
|
|
|
|
2014-09-20 02:33:45 +08:00
|
|
|
ScopedReport R(Opts, Loc);
|
2014-07-30 09:49:19 +08:00
|
|
|
|
2013-01-09 11:40:03 +08:00
|
|
|
Diag(Loc, DL_Error, "variable length array bound evaluates to "
|
|
|
|
"non-positive value %0")
|
2012-10-10 09:10:59 +08:00
|
|
|
<< Value(Data->Type, Bound);
|
2012-12-03 03:47:29 +08:00
|
|
|
}
|
2014-07-30 09:49:19 +08:00
|
|
|
|
|
|
|
void __ubsan::__ubsan_handle_vla_bound_not_positive(VLABoundData *Data,
|
|
|
|
ValueHandle Bound) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(false);
|
|
|
|
handleVLABoundNotPositive(Data, Bound, Opts);
|
2014-07-30 09:49:19 +08:00
|
|
|
}
|
2012-12-03 03:47:29 +08:00
|
|
|
void __ubsan::__ubsan_handle_vla_bound_not_positive_abort(VLABoundData *Data,
|
2014-07-30 09:49:19 +08:00
|
|
|
ValueHandle Bound) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(true);
|
|
|
|
handleVLABoundNotPositive(Data, Bound, Opts);
|
2014-09-11 04:43:36 +08:00
|
|
|
Die();
|
2012-10-10 09:10:59 +08:00
|
|
|
}
|
2012-10-13 06:57:15 +08:00
|
|
|
|
2014-08-23 05:42:04 +08:00
|
|
|
static void handleFloatCastOverflow(FloatCastOverflowData *Data,
|
|
|
|
ValueHandle From, ReportOptions Opts) {
|
2013-01-09 11:40:03 +08:00
|
|
|
// TODO: Add deduplication once a SourceLocation is generated for this check.
|
2015-02-11 03:50:20 +08:00
|
|
|
Location Loc = getCallerLocation(Opts.pc);
|
2014-09-20 02:33:45 +08:00
|
|
|
ScopedReport R(Opts, Loc);
|
2014-07-30 09:49:19 +08:00
|
|
|
|
2014-09-20 02:33:45 +08:00
|
|
|
Diag(Loc, DL_Error,
|
2012-12-18 14:30:32 +08:00
|
|
|
"value %0 is outside the range of representable values of type %2")
|
2014-09-20 02:33:45 +08:00
|
|
|
<< Value(Data->FromType, From) << Data->FromType << Data->ToType;
|
2012-12-03 03:47:29 +08:00
|
|
|
}
|
2014-07-30 09:49:19 +08:00
|
|
|
|
|
|
|
void __ubsan::__ubsan_handle_float_cast_overflow(FloatCastOverflowData *Data,
|
|
|
|
ValueHandle From) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(false);
|
|
|
|
handleFloatCastOverflow(Data, From, Opts);
|
2014-07-30 09:49:19 +08:00
|
|
|
}
|
|
|
|
void
|
|
|
|
__ubsan::__ubsan_handle_float_cast_overflow_abort(FloatCastOverflowData *Data,
|
|
|
|
ValueHandle From) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(true);
|
|
|
|
handleFloatCastOverflow(Data, From, Opts);
|
2014-09-11 04:43:36 +08:00
|
|
|
Die();
|
2012-10-13 06:57:15 +08:00
|
|
|
}
|
2012-12-13 15:00:14 +08:00
|
|
|
|
2014-07-30 09:49:19 +08:00
|
|
|
static void handleLoadInvalidValue(InvalidValueData *Data, ValueHandle Val,
|
2014-08-23 05:42:04 +08:00
|
|
|
ReportOptions Opts) {
|
2013-10-02 10:29:47 +08:00
|
|
|
SourceLocation Loc = Data->Loc.acquire();
|
2014-09-11 04:43:36 +08:00
|
|
|
if (ignoreReport(Loc, Opts))
|
2013-10-02 10:29:47 +08:00
|
|
|
return;
|
|
|
|
|
2014-09-20 02:33:45 +08:00
|
|
|
ScopedReport R(Opts, Loc);
|
2014-07-30 09:49:19 +08:00
|
|
|
|
2013-10-02 10:29:47 +08:00
|
|
|
Diag(Loc, DL_Error,
|
2012-12-18 14:30:32 +08:00
|
|
|
"load of value %0, which is not a valid value for type %1")
|
2012-12-13 15:00:14 +08:00
|
|
|
<< Value(Data->Type, Val) << Data->Type;
|
|
|
|
}
|
2014-07-30 09:49:19 +08:00
|
|
|
|
|
|
|
void __ubsan::__ubsan_handle_load_invalid_value(InvalidValueData *Data,
|
|
|
|
ValueHandle Val) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(false);
|
|
|
|
handleLoadInvalidValue(Data, Val, Opts);
|
2014-07-30 09:49:19 +08:00
|
|
|
}
|
2012-12-13 15:00:14 +08:00
|
|
|
void __ubsan::__ubsan_handle_load_invalid_value_abort(InvalidValueData *Data,
|
|
|
|
ValueHandle Val) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(true);
|
|
|
|
handleLoadInvalidValue(Data, Val, Opts);
|
2014-09-11 04:43:36 +08:00
|
|
|
Die();
|
2012-12-13 15:00:14 +08:00
|
|
|
}
|
2013-10-21 05:29:46 +08:00
|
|
|
|
2014-07-30 09:49:19 +08:00
|
|
|
static void handleFunctionTypeMismatch(FunctionTypeMismatchData *Data,
|
2014-08-23 05:42:04 +08:00
|
|
|
ValueHandle Function,
|
|
|
|
ReportOptions Opts) {
|
2015-02-11 08:05:31 +08:00
|
|
|
SourceLocation CallLoc = Data->Loc.acquire();
|
|
|
|
if (ignoreReport(CallLoc, Opts))
|
|
|
|
return;
|
2013-10-21 05:29:46 +08:00
|
|
|
|
2015-02-11 08:05:31 +08:00
|
|
|
ScopedReport R(Opts, CallLoc);
|
2013-10-21 05:29:46 +08:00
|
|
|
|
2015-02-11 08:05:31 +08:00
|
|
|
const char *FName = "(unknown)";
|
|
|
|
Location FLoc = getFunctionLocation(Function, &FName);
|
2014-07-30 09:49:19 +08:00
|
|
|
|
2015-02-11 08:05:31 +08:00
|
|
|
Diag(CallLoc, DL_Error,
|
2013-10-21 05:29:46 +08:00
|
|
|
"call to function %0 through pointer to incorrect function type %1")
|
2015-02-11 08:05:31 +08:00
|
|
|
<< FName << Data->Type;
|
|
|
|
Diag(FLoc, DL_Note, "%0 defined here") << FName;
|
2013-10-21 05:29:46 +08:00
|
|
|
}
|
|
|
|
|
2014-07-30 09:49:19 +08:00
|
|
|
void
|
|
|
|
__ubsan::__ubsan_handle_function_type_mismatch(FunctionTypeMismatchData *Data,
|
|
|
|
ValueHandle Function) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(false);
|
|
|
|
handleFunctionTypeMismatch(Data, Function, Opts);
|
2014-07-30 09:49:19 +08:00
|
|
|
}
|
|
|
|
|
2013-10-21 05:29:46 +08:00
|
|
|
void __ubsan::__ubsan_handle_function_type_mismatch_abort(
|
2014-07-30 09:49:19 +08:00
|
|
|
FunctionTypeMismatchData *Data, ValueHandle Function) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(true);
|
|
|
|
handleFunctionTypeMismatch(Data, Function, Opts);
|
2014-09-11 04:43:36 +08:00
|
|
|
Die();
|
2013-10-21 05:29:46 +08:00
|
|
|
}
|
2014-08-13 08:26:40 +08:00
|
|
|
|
2014-09-09 01:22:45 +08:00
|
|
|
static void handleNonNullReturn(NonNullReturnData *Data, ReportOptions Opts) {
|
2014-08-13 08:26:40 +08:00
|
|
|
SourceLocation Loc = Data->Loc.acquire();
|
2014-09-11 04:43:36 +08:00
|
|
|
if (ignoreReport(Loc, Opts))
|
2014-08-13 08:26:40 +08:00
|
|
|
return;
|
|
|
|
|
2014-09-20 02:33:45 +08:00
|
|
|
ScopedReport R(Opts, Loc);
|
2014-08-13 08:26:40 +08:00
|
|
|
|
|
|
|
Diag(Loc, DL_Error, "null pointer returned from function declared to never "
|
|
|
|
"return null");
|
2014-09-09 04:17:19 +08:00
|
|
|
if (!Data->AttrLoc.isInvalid())
|
|
|
|
Diag(Data->AttrLoc, DL_Note, "returns_nonnull attribute specified here");
|
2014-08-13 08:26:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void __ubsan::__ubsan_handle_nonnull_return(NonNullReturnData *Data) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(false);
|
2014-09-09 01:22:45 +08:00
|
|
|
handleNonNullReturn(Data, Opts);
|
2014-08-13 08:26:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void __ubsan::__ubsan_handle_nonnull_return_abort(NonNullReturnData *Data) {
|
2014-08-23 05:42:04 +08:00
|
|
|
GET_REPORT_OPTIONS(true);
|
2014-09-09 01:22:45 +08:00
|
|
|
handleNonNullReturn(Data, Opts);
|
2014-09-11 04:43:36 +08:00
|
|
|
Die();
|
2014-09-09 01:22:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handleNonNullArg(NonNullArgData *Data, ReportOptions Opts) {
|
|
|
|
SourceLocation Loc = Data->Loc.acquire();
|
2014-09-11 04:43:36 +08:00
|
|
|
if (ignoreReport(Loc, Opts))
|
2014-09-09 01:22:45 +08:00
|
|
|
return;
|
|
|
|
|
2014-09-20 02:33:45 +08:00
|
|
|
ScopedReport R(Opts, Loc);
|
2014-09-09 01:22:45 +08:00
|
|
|
|
|
|
|
Diag(Loc, DL_Error, "null pointer passed as argument %0, which is declared to "
|
|
|
|
"never be null") << Data->ArgIndex;
|
|
|
|
if (!Data->AttrLoc.isInvalid())
|
|
|
|
Diag(Data->AttrLoc, DL_Note, "nonnull attribute specified here");
|
|
|
|
}
|
|
|
|
|
|
|
|
void __ubsan::__ubsan_handle_nonnull_arg(NonNullArgData *Data) {
|
|
|
|
GET_REPORT_OPTIONS(false);
|
|
|
|
handleNonNullArg(Data, Opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __ubsan::__ubsan_handle_nonnull_arg_abort(NonNullArgData *Data) {
|
|
|
|
GET_REPORT_OPTIONS(true);
|
|
|
|
handleNonNullArg(Data, Opts);
|
2014-09-11 04:43:36 +08:00
|
|
|
Die();
|
2014-08-13 08:26:40 +08:00
|
|
|
}
|