[llvm] r251829 - [Support] Assert that reported key+data lenghts match reality

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 2 12:49:30 PST 2015


Author: rnk
Date: Mon Nov  2 14:49:29 2015
New Revision: 251829

URL: http://llvm.org/viewvc/llvm-project?rev=251829&view=rev
Log:
[Support] Assert that reported key+data lenghts match reality

This found a bug in Clang's PTH implementation.

Modified:
    llvm/trunk/include/llvm/Support/OnDiskHashTable.h

Modified: llvm/trunk/include/llvm/Support/OnDiskHashTable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/OnDiskHashTable.h?rev=251829&r1=251828&r2=251829&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/OnDiskHashTable.h (original)
+++ llvm/trunk/include/llvm/Support/OnDiskHashTable.h Mon Nov  2 14:49:29 2015
@@ -171,8 +171,22 @@ public:
         LE.write<typename Info::hash_value_type>(I->Hash);
         const std::pair<offset_type, offset_type> &Len =
             InfoObj.EmitKeyDataLength(Out, I->Key, I->Data);
+#ifdef NDEBUG
         InfoObj.EmitKey(Out, I->Key, Len.first);
         InfoObj.EmitData(Out, I->Key, I->Data, Len.second);
+#else
+        // In asserts mode, check that the users length matches the data they
+        // wrote.
+        uint64_t KeyStart = Out.tell();
+        InfoObj.EmitKey(Out, I->Key, Len.first);
+        uint64_t DataStart = Out.tell();
+        InfoObj.EmitData(Out, I->Key, I->Data, Len.second);
+        uint64_t End = Out.tell();
+        assert(offset_type(DataStart - KeyStart) == Len.first &&
+               "key length does not match bytes written");
+        assert(offset_type(End - DataStart) == Len.second &&
+               "data length does not match bytes written");
+#endif
       }
     }
 




More information about the llvm-commits mailing list