diff --git a/oi/type_graph/Flattener.cpp b/oi/type_graph/Flattener.cpp index fd48112..34b93f3 100644 --- a/oi/type_graph/Flattener.cpp +++ b/oi/type_graph/Flattener.cpp @@ -42,7 +42,7 @@ namespace { void flattenParent(const Parent& parent, std::vector& flattenedMembers) { Type& parentType = stripTypedefs(parent.type()); - if (Class* parentClass = dynamic_cast(&parentType)) { + if (auto* parentClass = dynamic_cast(&parentType)) { for (size_t i = 0; i < parentClass->members.size(); i++) { const auto& member = parentClass->members[i]; flattenedMembers.push_back(member); @@ -52,11 +52,15 @@ void flattenParent(const Parent& parent, std::max(flattenedMembers.back().align, parentClass->align()); } } - } else if (Container* parentContainer = - dynamic_cast(&parentType)) { + } else if (auto* parentContainer = dynamic_cast(&parentType)) { // Create a new member to represent this parent container flattenedMembers.emplace_back(*parentContainer, Flattener::ParentPrefix, parent.bitOffset); + } else if (auto* parentPrimitive = dynamic_cast(&parentType); + parentPrimitive && + parentPrimitive->kind() == Primitive::Kind::Incomplete) { + // Bad DWARF can lead to us seeing incomplete parent types. Just ignore + // these as there is nothing we can do to recover the missing info. } else { throw std::runtime_error("Invalid type for parent"); } diff --git a/test/test_flattener.cpp b/test/test_flattener.cpp index e0da517..fb26382 100644 --- a/test/test_flattener.cpp +++ b/test/test_flattener.cpp @@ -952,3 +952,14 @@ TEST(FlattenerTest, ClassParam) { Primitive: int32_t )"); } + +TEST(FlattenerTest, IncompleteParent) { + test(Flattener::createPass(), R"( +[0] Class: MyClass (size: 4) + Parent (offset: 0) + Primitive: void (incomplete) +)", + R"( +[0] Class: MyClass (size: 4) +)"); +}