diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-12-18 04:23:18 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-12-18 04:23:18 +0000 |
commit | 5f1164955fb28a9bcb826abc195aa2119feb0f97 (patch) | |
tree | 8c48a8795cb47b12e4756a31049b14bd1c31ac18 /lib/ubsan/ubsan_handlers.cc | |
parent | fe0b77be4057ba90a0321107cc5d0f603f297bfa (diff) |
ubsan: if the frontend didn't provide us with a source location, try to work
one out from the return address. Currently, we can only resolve this address to
a file and line number if we have an external symbolizer.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@170407 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ubsan/ubsan_handlers.cc')
-rw-r--r-- | lib/ubsan/ubsan_handlers.cc | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/lib/ubsan/ubsan_handlers.cc b/lib/ubsan/ubsan_handlers.cc index 91ff4df0a..1f3bf6823 100644 --- a/lib/ubsan/ubsan_handlers.cc +++ b/lib/ubsan/ubsan_handlers.cc @@ -26,24 +26,32 @@ namespace __ubsan { }; } -void __ubsan::__ubsan_handle_type_mismatch(TypeMismatchData *Data, - ValueHandle Pointer) { +static void handleTypeMismatchImpl(TypeMismatchData *Data, ValueHandle Pointer, + Location FallbackLoc) { + Location Loc = Data->Loc; + if (Data->Loc.isInvalid()) + Loc = FallbackLoc; + if (!Pointer) - Diag(Data->Loc, "%0 null pointer of type %1") + Diag(Loc, "%0 null pointer of type %1") << TypeCheckKinds[Data->TypeCheckKind] << Data->Type; else if (Data->Alignment && (Pointer & (Data->Alignment - 1))) - Diag(Data->Loc, "%0 misaligned address %1 for type %3, " - "which requires %2 byte alignment") + Diag(Loc, "%0 misaligned address %1 for type %3, " + "which requires %2 byte alignment") << TypeCheckKinds[Data->TypeCheckKind] << (void*)Pointer << Data->Alignment << Data->Type; else - Diag(Data->Loc, "%0 address %1 with insufficient space " - "for an object of type %2") + Diag(Loc, "%0 address %1 with insufficient space " + "for an object of type %2") << TypeCheckKinds[Data->TypeCheckKind] << (void*)Pointer << Data->Type; } +void __ubsan::__ubsan_handle_type_mismatch(TypeMismatchData *Data, + ValueHandle Pointer) { + handleTypeMismatchImpl(Data, Pointer, getCallerLocation()); +} void __ubsan::__ubsan_handle_type_mismatch_abort(TypeMismatchData *Data, - ValueHandle Pointer) { - __ubsan_handle_type_mismatch(Data, Pointer); + ValueHandle Pointer) { + handleTypeMismatchImpl(Data, Pointer, getCallerLocation()); Die(); } @@ -167,27 +175,32 @@ void __ubsan::__ubsan_handle_vla_bound_not_positive_abort(VLABoundData *Data, Die(); } + void __ubsan::__ubsan_handle_float_cast_overflow(FloatCastOverflowData *Data, ValueHandle From) { - Diag(SourceLocation(), "value %0 is outside the range of representable " - "values of type %2") + Diag(getCallerLocation(), "value %0 is outside the range of representable " + "values of type %2") << Value(Data->FromType, From) << Data->FromType << Data->ToType; } void __ubsan::__ubsan_handle_float_cast_overflow_abort( FloatCastOverflowData *Data, ValueHandle From) { - __ubsan_handle_float_cast_overflow(Data, From); + Diag(getCallerLocation(), "value %0 is outside the range of representable " + "values of type %2") + << Value(Data->FromType, From) << Data->FromType << Data->ToType; Die(); } void __ubsan::__ubsan_handle_load_invalid_value(InvalidValueData *Data, ValueHandle Val) { - Diag(SourceLocation(), "load of value %0, which is not a valid value for " - "type %1") + Diag(getCallerLocation(), "load of value %0, which is not a valid value for " + "type %1") << Value(Data->Type, Val) << Data->Type; } void __ubsan::__ubsan_handle_load_invalid_value_abort(InvalidValueData *Data, ValueHandle Val) { - __ubsan_handle_load_invalid_value(Data, Val); + Diag(getCallerLocation(), "load of value %0, which is not a valid value for " + "type %1") + << Value(Data->Type, Val) << Data->Type; Die(); } |