ubsan_handlers_cxx.cc revision a82a5d360b19080f2b1beae374c12d4f26146450
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
29static void HandleDynamicTypeCacheMiss(
30  DynamicTypeCacheMissData *Data, ValueHandle Pointer, ValueHandle Hash,
31  bool abort) {
32  if (checkDynamicType((void*)Pointer, Data->TypeInfo, Hash))
33    // Just a cache miss. The type matches after all.
34    return;
35
36  Diag(Data->Loc, "%0 address %1 which does not point to an object of type %2")
37    << TypeCheckKinds[Data->TypeCheckKind] << (void*)Pointer << Data->Type;
38  // FIXME: If possible, say what type it actually points to. Produce a note
39  //        pointing out the vptr:
40  // lib/VMCore/Instructions.cpp:2020:10: runtime error: member call on address
41  //       0xb7a4440 which does not point to an object of type
42  //       'llvm::OverflowingBinaryOperator'
43  //   return cast<OverflowingBinaryOperator>(this)->hasNoSignedWrap();
44  //                                               ^
45  // 0xb7a4440: note: object is of type 'llvm::BinaryOperator'
46  //   00 00 00 00  e0 f7 c5 09 00 00 00 00  20 00 00 00
47  //                ^~~~~~~~~~~
48  //                vptr for 'llvm::BinaryOperator'
49  if (abort)
50    Die();
51}
52
53void __ubsan::__ubsan_handle_dynamic_type_cache_miss(
54  DynamicTypeCacheMissData *Data, ValueHandle Pointer, ValueHandle Hash) {
55  HandleDynamicTypeCacheMiss(Data, Pointer, Hash, false);
56}
57void __ubsan::__ubsan_handle_dynamic_type_cache_miss_abort(
58  DynamicTypeCacheMissData *Data, ValueHandle Pointer, ValueHandle Hash) {
59  HandleDynamicTypeCacheMiss(Data, Pointer, Hash, true);
60}
61