re PR fortran/59440 (ICE in force_decl_die, at dwarf2out.c:20111 with -g)
[official-gcc.git] / libsanitizer / ubsan / ubsan_type_hash.h
blob138559f204dd0c1f3efff970e8872b9d9bff3175
1 //===-- ubsan_type_hash.h ---------------------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // Hashing of types for Clang's undefined behavior checker.
9 //
10 //===----------------------------------------------------------------------===//
11 #ifndef UBSAN_TYPE_HASH_H
12 #define UBSAN_TYPE_HASH_H
14 #include "sanitizer_common/sanitizer_common.h"
16 namespace __ubsan {
18 typedef uptr HashValue;
20 /// \brief Information about the dynamic type of an object (extracted from its
21 /// vptr).
22 class DynamicTypeInfo {
23 const char *MostDerivedTypeName;
24 sptr Offset;
25 const char *SubobjectTypeName;
27 public:
28 DynamicTypeInfo(const char *MDTN, sptr Offset, const char *STN)
29 : MostDerivedTypeName(MDTN), Offset(Offset), SubobjectTypeName(STN) {}
31 /// Determine whether the object had a valid dynamic type.
32 bool isValid() const { return MostDerivedTypeName; }
33 /// Get the name of the most-derived type of the object.
34 const char *getMostDerivedTypeName() const { return MostDerivedTypeName; }
35 /// Get the offset from the most-derived type to this base class.
36 sptr getOffset() const { return Offset; }
37 /// Get the name of the most-derived type at the specified offset.
38 const char *getSubobjectTypeName() const { return SubobjectTypeName; }
41 /// \brief Get information about the dynamic type of an object.
42 DynamicTypeInfo getDynamicTypeInfo(void *Object);
44 /// \brief Check whether the dynamic type of \p Object has a \p Type subobject
45 /// at offset 0.
46 /// \return \c true if the type matches, \c false if not.
47 bool checkDynamicType(void *Object, void *Type, HashValue Hash);
49 const unsigned VptrTypeCacheSize = 128;
51 /// \brief A cache of the results of checkDynamicType. \c checkDynamicType would
52 /// return \c true (modulo hash collisions) if
53 /// \code
54 /// __ubsan_vptr_type_cache[Hash % VptrTypeCacheSize] == Hash
55 /// \endcode
56 extern "C" SANITIZER_INTERFACE_ATTRIBUTE
57 HashValue __ubsan_vptr_type_cache[VptrTypeCacheSize];
59 } // namespace __ubsan
61 #endif // UBSAN_TYPE_HASH_H