[PATCH] D21393: [pdbdump] Verify LF_{CLASS, ENUM, INTERFACE, STRUCTURE, UNION} records with different hash function.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 16 08:00:21 PDT 2016


ruiu updated this revision to Diff 60978.
ruiu added a comment.

- Rebased


http://reviews.llvm.org/D21393

Files:
  lib/DebugInfo/PDB/Raw/TpiStream.cpp

Index: lib/DebugInfo/PDB/Raw/TpiStream.cpp
===================================================================
--- lib/DebugInfo/PDB/Raw/TpiStream.cpp
+++ lib/DebugInfo/PDB/Raw/TpiStream.cpp
@@ -65,22 +65,20 @@
 TpiStream::~TpiStream() {}
 
 // Computes a hash for a given TPI record.
-template <typename T> static uint32_t getTpiHash(T &Rec) {
+template <typename T>
+static uint32_t getTpiHash(T &Rec, const CVRecord<TypeLeafKind> &RawRec) {
   auto Opts = static_cast<uint16_t>(Rec.getOptions());
 
-  // We don't know how to calculate a hash value for this yet.
-  // Currently we just skip it.
-  if (Opts & static_cast<uint16_t>(ClassOptions::ForwardReference))
-    return 0;
+  bool ForwardRef =
+      Opts & static_cast<uint16_t>(ClassOptions::ForwardReference);
+  bool Scoped = Opts & static_cast<uint16_t>(ClassOptions::Scoped);
+  bool UniqueName = Opts & static_cast<uint16_t>(ClassOptions::HasUniqueName);
 
-  if (!(Opts & static_cast<uint16_t>(ClassOptions::Scoped)))
+  if (!ForwardRef && !Scoped)
     return hashStringV1(Rec.getName());
-
-  if (Opts & static_cast<uint16_t>(ClassOptions::HasUniqueName))
+  if (!ForwardRef && UniqueName)
     return hashStringV1(Rec.getUniqueName());
-
-  // This case is not implemented yet.
-  return 0;
+  return hashBufferV8(RawRec.RawData);
 }
 
 namespace {
@@ -102,12 +100,14 @@
   void visitStruct(ClassRecord &Rec) { verify(Rec); }
   void visitUnion(UnionRecord &Rec) { verify(Rec); }
 
+  void visitTypeBegin(const CVRecord<TypeLeafKind> &Rec) { RawRecord = &Rec; }
+
   void visitTypeEnd(const CVRecord<TypeLeafKind> &Record) { ++Index; }
 
 private:
   template <typename T> void verify(T &Rec) {
-    uint32_t Hash = getTpiHash(Rec);
-    if (Hash && Hash % NumHashBuckets != HashValues[Index])
+    uint32_t Hash = getTpiHash(Rec, *RawRecord);
+    if (Hash % NumHashBuckets != HashValues[Index])
       parseError();
   }
 
@@ -120,6 +120,7 @@
   }
 
   FixedStreamArray<support::ulittle32_t> HashValues;
+  const CVRecord<TypeLeafKind> *RawRecord;
   uint32_t NumHashBuckets;
   uint32_t Index = 0;
 };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21393.60978.patch
Type: text/x-patch
Size: 2076 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160616/1d9dfff3/attachment.bin>


More information about the llvm-commits mailing list