1 //===-- ubsan_handlers_cxx.cc ---------------------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // Error logging entry points for the UBSan runtime, which are only used for C++
9 // compilations. This file is permitted to use language features which require
10 // linking against a C++ ABI library.
12 //===----------------------------------------------------------------------===//
14 #include "ubsan_handlers_cxx.h"
15 #include "ubsan_diag.h"
16 #include "ubsan_type_hash.h"
18 #include "sanitizer_common/sanitizer_common.h"
19 #include "sanitizer_common/sanitizer_suppressions.h"
21 using namespace __sanitizer
;
22 using namespace __ubsan
;
25 extern const char *TypeCheckKinds
[];
28 static void HandleDynamicTypeCacheMiss(
29 DynamicTypeCacheMissData
*Data
, ValueHandle Pointer
, ValueHandle Hash
,
31 if (checkDynamicType((void*)Pointer
, Data
->TypeInfo
, Hash
))
32 // Just a cache miss. The type matches after all.
35 // Check if error report should be suppressed.
36 DynamicTypeInfo DTI
= getDynamicTypeInfo((void*)Pointer
);
38 MatchSuppression(DTI
.getMostDerivedTypeName(), SuppressionVptrCheck
))
41 SourceLocation Loc
= Data
->Loc
.acquire();
45 ScopedReport
R(Opts
, Loc
);
48 "%0 address %1 which does not point to an object of type %2")
49 << TypeCheckKinds
[Data
->TypeCheckKind
] << (void*)Pointer
<< Data
->Type
;
51 // If possible, say what type it actually points to.
53 Diag(Pointer
, DL_Note
, "object has invalid vptr")
54 << MangledName(DTI
.getMostDerivedTypeName())
55 << Range(Pointer
, Pointer
+ sizeof(uptr
), "invalid vptr");
56 else if (!DTI
.getOffset())
57 Diag(Pointer
, DL_Note
, "object is of type %0")
58 << MangledName(DTI
.getMostDerivedTypeName())
59 << Range(Pointer
, Pointer
+ sizeof(uptr
), "vptr for %0");
61 // FIXME: Find the type at the specified offset, and include that
63 Diag(Pointer
- DTI
.getOffset(), DL_Note
,
64 "object is base class subobject at offset %0 within object of type %1")
65 << DTI
.getOffset() << MangledName(DTI
.getMostDerivedTypeName())
66 << MangledName(DTI
.getSubobjectTypeName())
67 << Range(Pointer
, Pointer
+ sizeof(uptr
),
68 "vptr for %2 base class of %1");
71 void __ubsan::__ubsan_handle_dynamic_type_cache_miss(
72 DynamicTypeCacheMissData
*Data
, ValueHandle Pointer
, ValueHandle Hash
) {
73 GET_REPORT_OPTIONS(false);
74 HandleDynamicTypeCacheMiss(Data
, Pointer
, Hash
, Opts
);
76 void __ubsan::__ubsan_handle_dynamic_type_cache_miss_abort(
77 DynamicTypeCacheMissData
*Data
, ValueHandle Pointer
, ValueHandle Hash
) {
78 GET_REPORT_OPTIONS(true);
79 HandleDynamicTypeCacheMiss(Data
, Pointer
, Hash
, Opts
);