[llvm-commits] [compiler-rt] r166965 - in /compiler-rt/trunk/lib/ubsan: ubsan_type_hash.cc ubsan_type_hash.h

Richard Smith richard-llvm at metafoo.co.uk
Mon Oct 29 13:54:34 PDT 2012


Author: rsmith
Date: Mon Oct 29 15:54:34 2012
New Revision: 166965

URL: http://llvm.org/viewvc/llvm-project?rev=166965&view=rev
Log:
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.

Modified:
    compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cc
    compiler-rt/trunk/lib/ubsan/ubsan_type_hash.h

Modified: compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cc?rev=166965&r1=166964&r2=166965&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cc Mon Oct 29 15:54:34 2012
@@ -89,7 +89,7 @@
 //        (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 @@
   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 @@
   // 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 @@
     return false;
 
   // Success. Cache this result.
-  __ubsan_vptr_type_cache[Hash % CacheSize] = Hash;
+  __ubsan_vptr_type_cache[Hash % VptrTypeCacheSize] = Hash;
   *Bucket = Hash;
   return true;
 }

Modified: compiler-rt/trunk/lib/ubsan/ubsan_type_hash.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_type_hash.h?rev=166965&r1=166964&r2=166965&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_type_hash.h (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_type_hash.h Mon Oct 29 15:54:34 2012
@@ -22,7 +22,16 @@
 /// \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
 





More information about the llvm-commits mailing list