ubsan_handlers_cxx.cc revision 7cbd7e502e993320a3a1578179d336c268b80604
1//===-- ubsan_handlers_cxx.cc ---------------------------------------------===//
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// Error logging entry points for the UBSan runtime, which are only used for C++
11// compilations. This file is permitted to use language features which require
12// linking against a C++ ABI library.
13//
14//===----------------------------------------------------------------------===//
15
16#include "ubsan_handlers_cxx.h"
17#include "ubsan_diag.h"
18#include "ubsan_type_hash.h"
19
20#include "sanitizer_common/sanitizer_common.h"
21
22using namespace __sanitizer;
23using namespace __ubsan;
24
25namespace __ubsan {
26  extern const char *TypeCheckKinds[];
27}
28
29void __ubsan::__ubsan_handle_dynamic_type_cache_miss(
30  DynamicTypeCacheMissData *Data, ValueHandle Pointer, ValueHandle Hash) {
31  if (checkDynamicType((void*)Pointer, Data->TypeInfo, Hash))
32    // Just a cache miss. The type matches after all.
33    return;
34
35  Diag(Data->Loc, "%0 address %1 which does not point to an object of type %2")
36    << TypeCheckKinds[Data->TypeCheckKind] << (void*)Pointer << Data->Type;
37  // FIXME: If possible, say what type it actually points to. Produce a note
38  //        pointing out the vptr:
39  // lib/VMCore/Instructions.cpp:2020:10: runtime error: member call on address
40  //       0xb7a4440 which does not point to an object of type
41  //       'llvm::OverflowingBinaryOperator'
42  //   return cast<OverflowingBinaryOperator>(this)->hasNoSignedWrap();
43  //                                               ^
44  // 0xb7a4440: note: object is of type 'llvm::BinaryOperator'
45  //   00 00 00 00  e0 f7 c5 09 00 00 00 00  20 00 00 00
46  //                ^~~~~~~~~~~
47  //                vptr for 'llvm::BinaryOperator'
48  Die();
49}
50