From 330268ba346b679af786879d8f696c8c412a40eb Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Mon, 4 Apr 2022 16:48:30 -0700 Subject: [Support/Hash functions] Change the `final()` and `result()` of the hashing functions to return an array of bytes Returning `std::array` is better ergonomics for the hashing functions usage, instead of a `StringRef`: * When returning `StringRef`, client code is "jumping through hoops" to do string manipulations instead of dealing with fixed array of bytes directly, which is more natural * Returning `std::array` avoids the need for the hasher classes to keep a field just for the purpose of wrapping it and returning it as a `StringRef` As part of this patch also: * Introduce `TruncatedBLAKE3` which is useful for using BLAKE3 as the hasher type for `HashBuilder` with non-default hash sizes. * Make `MD5Result` inherit from `std::array` which improves & simplifies its API. Differential Revision: https://reviews.llvm.org/D123100 --- llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp index fdb07cf282a9..f291827d7f6f 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp @@ -903,7 +903,7 @@ Error BitcodeAnalyzer::parseBlock(unsigned BlockID, unsigned IndentLevel, else { // Recompute the hash and compare it to the one in the bitcode SHA1 Hasher; - StringRef Hash; + std::array Hash; Hasher.update(*CheckHash); { int BlockSize = (CurrentRecordPos / 8) - BlockEntryPos; @@ -911,14 +911,14 @@ Error BitcodeAnalyzer::parseBlock(unsigned BlockID, unsigned IndentLevel, Hasher.update(ArrayRef(Ptr, BlockSize)); Hash = Hasher.result(); } - std::array RecordedHash; + std::array RecordedHash; int Pos = 0; for (auto &Val : Record) { assert(!(Val >> 32) && "Unexpected high bits set"); support::endian::write32be(&RecordedHash[Pos], Val); Pos += 4; } - if (Hash == StringRef(RecordedHash.data(), RecordedHash.size())) + if (Hash == RecordedHash) O->OS << " (match)"; else O->OS << " (!mismatch!)"; -- cgit v1.2.3