aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Ganea <alexandre.ganea@ubisoft.com>2018-04-10 01:58:45 +0000
committerAlexandre Ganea <alexandre.ganea@ubisoft.com>2018-04-10 01:58:45 +0000
commit08df84e4f022d09cf58ea9d11ed1ce4b104a64e9 (patch)
tree05d03a5c6d9da12ef08ec855bc9fc61648a5712b
parent76a0154ce5cd60172ded3479bddfdf198b1dddf9 (diff)
downloadllvm-08df84e4f022d09cf58ea9d11ed1ce4b104a64e9.zip
llvm-08df84e4f022d09cf58ea9d11ed1ce4b104a64e9.tar.gz
llvm-08df84e4f022d09cf58ea9d11ed1ce4b104a64e9.tar.bz2
[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 llvm-svn: 329659
-rw-r--r--llvm/lib/DebugInfo/CodeView/TypeIndexDiscovery.cpp4
-rw-r--r--llvm/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp8
2 files changed, 10 insertions, 2 deletions
diff --git a/llvm/lib/DebugInfo/CodeView/TypeIndexDiscovery.cpp b/llvm/lib/DebugInfo/CodeView/TypeIndexDiscovery.cpp
index d283e9e..95082d4 100644
--- a/llvm/lib/DebugInfo/CodeView/TypeIndexDiscovery.cpp
+++ b/llvm/lib/DebugInfo/CodeView/TypeIndexDiscovery.cpp
@@ -58,7 +58,7 @@ static inline uint32_t getEncodedIntegerLength(ArrayRef<uint8_t> Data) {
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<uint8_t> Content, SymbolKind Kind,
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
diff --git a/llvm/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp b/llvm/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp
index 14d358d..54da2b7 100644
--- a/llvm/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp
+++ b/llvm/unittests/DebugInfo/CodeView/TypeIndexDiscoveryTest.cpp
@@ -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