diff options
| author | Reid Kleckner <rnk@google.com> | 2015-11-02 20:49:29 +0000 |
|---|---|---|
| committer | Reid Kleckner <rnk@google.com> | 2015-11-02 20:49:29 +0000 |
| commit | 06665475cdb099f397080da382cf3c18ebe0aa33 (patch) | |
| tree | baee04098a1bdc8906f88a98c45435026990b8e9 | |
| parent | f7e61478df6fed6c5768ef37e82ddf11650a15e5 (diff) | |
| download | bcm5719-llvm-06665475cdb099f397080da382cf3c18ebe0aa33.tar.gz bcm5719-llvm-06665475cdb099f397080da382cf3c18ebe0aa33.zip | |
[Support] Assert that reported key+data lenghts match reality
This found a bug in Clang's PTH implementation.
llvm-svn: 251829
| -rw-r--r-- | llvm/include/llvm/Support/OnDiskHashTable.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/include/llvm/Support/OnDiskHashTable.h b/llvm/include/llvm/Support/OnDiskHashTable.h index 48ec40ffbaf..c47134f46c8 100644 --- a/llvm/include/llvm/Support/OnDiskHashTable.h +++ b/llvm/include/llvm/Support/OnDiskHashTable.h @@ -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 } } |

