Skip to content

Commit

Permalink
[ubsan] Minimize size of data for type_mismatch (Redo of D19668)
Browse files Browse the repository at this point in the history
Summary: This is the compiler-rt side of D28242.

Reviewers: kcc, vitalybuka, pgousseau, gbedwell

Subscribers: kubabrecka, llvm-commits

Differential Revision: https://reviews.llvm.org/D28244

llvm-svn: 291237
  • Loading branch information
filcab committed Jan 6, 2017
1 parent fe5e5af commit b5304e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions compiler-rt/lib/ubsan/ubsan_handlers.cc
Expand Up @@ -45,10 +45,11 @@ static void handleTypeMismatchImpl(TypeMismatchData *Data, ValueHandle Pointer,
ReportOptions Opts) {
Location Loc = Data->Loc.acquire();

uptr Alignment = (uptr)1 << Data->LogAlignment;
ErrorType ET;
if (!Pointer)
ET = ErrorType::NullPointerUse;
else if (Data->Alignment && (Pointer & (Data->Alignment - 1)))
else if (Pointer & (Alignment - 1))
ET = ErrorType::MisalignedPointerUse;
else
ET = ErrorType::InsufficientObjectSize;
Expand All @@ -74,8 +75,8 @@ static void handleTypeMismatchImpl(TypeMismatchData *Data, ValueHandle Pointer,
case ErrorType::MisalignedPointerUse:
Diag(Loc, DL_Error, "%0 misaligned address %1 for type %3, "
"which requires %2 byte alignment")
<< TypeCheckKinds[Data->TypeCheckKind] << (void *)Pointer
<< Data->Alignment << Data->Type;
<< TypeCheckKinds[Data->TypeCheckKind] << (void *)Pointer << Alignment
<< Data->Type;
break;
case ErrorType::InsufficientObjectSize:
Diag(Loc, DL_Error, "%0 address %1 with insufficient space "
Expand All @@ -90,13 +91,13 @@ static void handleTypeMismatchImpl(TypeMismatchData *Data, ValueHandle Pointer,
Diag(Pointer, DL_Note, "pointer points here");
}

void __ubsan::__ubsan_handle_type_mismatch(TypeMismatchData *Data,
ValueHandle Pointer) {
void __ubsan::__ubsan_handle_type_mismatch_v1(TypeMismatchData *Data,
ValueHandle Pointer) {
GET_REPORT_OPTIONS(false);
handleTypeMismatchImpl(Data, Pointer, Opts);
}
void __ubsan::__ubsan_handle_type_mismatch_abort(TypeMismatchData *Data,
ValueHandle Pointer) {
void __ubsan::__ubsan_handle_type_mismatch_v1_abort(TypeMismatchData *Data,
ValueHandle Pointer) {
GET_REPORT_OPTIONS(true);
handleTypeMismatchImpl(Data, Pointer, Opts);
Die();
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/ubsan/ubsan_handlers.h
Expand Up @@ -20,7 +20,7 @@ namespace __ubsan {
struct TypeMismatchData {
SourceLocation Loc;
const TypeDescriptor &Type;
uptr Alignment;
unsigned char LogAlignment;
unsigned char TypeCheckKind;
};

Expand All @@ -37,7 +37,7 @@ struct TypeMismatchData {
/// \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.
RECOVERABLE(type_mismatch, TypeMismatchData *Data, ValueHandle Pointer)
RECOVERABLE(type_mismatch_v1, TypeMismatchData *Data, ValueHandle Pointer)

struct OverflowData {
SourceLocation Loc;
Expand Down

0 comments on commit b5304e2

Please sign in to comment.