[llvm] r329659 - [DebugInfo][COFF] Fix reading variable-length encoded records

Alexandre Ganea via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 9 18:58:46 PDT 2018


Author: aganea
Date: Mon Apr  9 18:58:45 2018
New Revision: 329659

URL: http://llvm.org/viewvc/llvm-project?rev=329659&view=rev
Log:
[DebugInfo][COFF] Fix reading variable-length encoded records

While reading Codeview records which contain variable-length encoded integers,
such as LF_BCLASS, LF_ENUMERATE, LF_MEMBER, LF_VBCLASS or LF_IVBCLASS,
the record's size would be improperly calculated in cases where the value was
indeed of a variable length (>= LF_NUMERIC). This caused a bad alignement on
the next record, which would/might crash later on.

Differential Revision: https://reviews.llvm.org/D45104

Modified:
    llvm/trunk/lib/DebugInfo/CodeView/TypeIndexDiscovery.cpp
    llvm/trunk/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp

Modified: llvm/trunk/lib/DebugInfo/CodeView/TypeIndexDiscovery.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/CodeView/TypeIndexDiscovery.cpp?rev=329659&r1=329658&r2=329659&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/CodeView/TypeIndexDiscovery.cpp (original)
+++ llvm/trunk/lib/DebugInfo/CodeView/TypeIndexDiscovery.cpp Mon Apr  9 18:58:45 2018
@@ -58,7 +58,7 @@ static inline uint32_t getEncodedInteger
       8,  // LF_UQUADWORD
   };
 
-  return Sizes[N - LF_NUMERIC];
+  return 2 + Sizes[N - LF_NUMERIC];
 }
 
 static inline uint32_t getCStringLength(ArrayRef<uint8_t> Data) {
@@ -393,7 +393,7 @@ static bool discoverTypeIndices(ArrayRef
     Refs.push_back({TiRefKind::TypeRef, 0, 1}); // Type
     break;
   case SymbolKind::S_REGISTER:
-    Refs.push_back({TiRefKind::TypeRef, 0, 1}); // Type;
+    Refs.push_back({TiRefKind::TypeRef, 0, 1}); // Type
     break;
   case SymbolKind::S_CONSTANT:
     Refs.push_back({TiRefKind::TypeRef, 0, 1}); // Type

Modified: llvm/trunk/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp?rev=329659&r1=329658&r2=329659&view=diff
==============================================================================
--- llvm/trunk/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp (original)
+++ llvm/trunk/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp Mon Apr  9 18:58:45 2018
@@ -593,3 +593,11 @@ TEST_F(TypeIndexIteratorTest, Precomp) {
   writeTypeRecords(P, EP);
   checkTypeReferences(0);
 }
+
+// This is a test for getEncodedIntegerLength()
+TEST_F(TypeIndexIteratorTest, VariableSizeIntegers) {
+  BaseClassRecord BaseClass1(MemberAccess::Public, TypeIndex(47), (uint64_t)-1);
+  BaseClassRecord BaseClass2(MemberAccess::Public, TypeIndex(48), 1);
+  writeFieldList(BaseClass1, BaseClass2);
+  checkTypeReferences(0, TypeIndex(47), TypeIndex(48));
+}
\ No newline at end of file




More information about the llvm-commits mailing list