summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-10-29 20:54:34 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-10-29 20:54:34 +0000
commit26a725f0b2fd30b98adae6353b432d0c955e10bd (patch)
tree33a9af595ecaa486f597f5db89575c443cf85c59
parent71a8273b3729ffaef40d178739f48dc38417d86a (diff)
downloadcompiler-rt-26a725f0b2fd30b98adae6353b432d0c955e10bd.tar.gz
Don't define an extern "C" variable in its first declaration, to appease a
bogus gcc warning. Take this opportunity to move the declaration to the header, since it's part of the API of this file. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@166965 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/ubsan/ubsan_type_hash.cc12
-rw-r--r--lib/ubsan/ubsan_type_hash.h11
2 files changed, 15 insertions, 8 deletions
diff --git a/lib/ubsan/ubsan_type_hash.cc b/lib/ubsan/ubsan_type_hash.cc
index 6d0443692..6630c843c 100644
--- a/lib/ubsan/ubsan_type_hash.cc
+++ b/lib/ubsan/ubsan_type_hash.cc
@@ -89,7 +89,7 @@ namespace abi = __cxxabiv1;
// (worst-case, we could miss a bug or see a slowdown) but we should
// avoid upsetting race detectors.
-// Find a bucket to store the given value in.
+/// Find a bucket to store the given hash value in.
static __ubsan::HashValue *getTypeCacheHashTableBucket(__ubsan::HashValue V) {
static const unsigned HashTableSize = 65537;
static __ubsan::HashValue __ubsan_vptr_hash_set[HashTableSize] = { 1 };
@@ -107,10 +107,8 @@ static __ubsan::HashValue *getTypeCacheHashTableBucket(__ubsan::HashValue V) {
return &__ubsan_vptr_hash_set[V];
}
-// A cache of recently-checked hashes. Mini hash table with "random" evictions.
-// The bottom 7 bits of the hash are used as the key.
-static const unsigned CacheSize = 128;
-extern "C" __ubsan::HashValue __ubsan_vptr_type_cache[CacheSize] = { 1 };
+/// A cache of recently-checked hashes. Mini hash table with "random" evictions.
+__ubsan::HashValue __ubsan_vptr_type_cache[__ubsan::VptrTypeCacheSize] = { 1 };
/// \brief Determine whether \p Derived has a \p Base base class subobject at
/// offset \p Offset.
@@ -174,7 +172,7 @@ bool __ubsan::checkDynamicType(void *Object, void *Type, HashValue Hash) {
// Check whether this is something we've evicted from the cache.
HashValue *Bucket = getTypeCacheHashTableBucket(Hash);
if (*Bucket == Hash) {
- __ubsan_vptr_type_cache[Hash % CacheSize] = Hash;
+ __ubsan_vptr_type_cache[Hash % VptrTypeCacheSize] = Hash;
return true;
}
@@ -194,7 +192,7 @@ bool __ubsan::checkDynamicType(void *Object, void *Type, HashValue Hash) {
return false;
// Success. Cache this result.
- __ubsan_vptr_type_cache[Hash % CacheSize] = Hash;
+ __ubsan_vptr_type_cache[Hash % VptrTypeCacheSize] = Hash;
*Bucket = Hash;
return true;
}
diff --git a/lib/ubsan/ubsan_type_hash.h b/lib/ubsan/ubsan_type_hash.h
index 982ebdfbc..ac1be4944 100644
--- a/lib/ubsan/ubsan_type_hash.h
+++ b/lib/ubsan/ubsan_type_hash.h
@@ -22,7 +22,16 @@ typedef uptr HashValue;
/// \brief Check whether the dynamic type of \p Object has a \p Type subobject
/// at offset 0.
/// \return \c true if the type matches, \c false if not.
-bool checkDynamicType(void *Object, void *Type, HashValue CacheSlot);
+bool checkDynamicType(void *Object, void *Type, HashValue Hash);
+
+const unsigned VptrTypeCacheSize = 128;
+
+/// \brief A cache of the results of checkDynamicType. \c checkDynamicType would
+/// return \c true (modulo hash collisions) if
+/// \code
+/// __ubsan_vptr_type_cache[Hash % VptrTypeCacheSize] == Hash
+/// \endcode
+extern "C" HashValue __ubsan_vptr_type_cache[VptrTypeCacheSize];
} // namespace __ubsan