SymbolFile: ensure that we have a value before invoking `getBitWidth`
authorSaleem Abdulrasool <compnerd@compnerd.org>
Tue, 21 Mar 2023 16:03:54 +0000 (12:03 -0400)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Wed, 22 Mar 2023 18:14:13 +0000 (14:14 -0400)
Ensure that the variant returned by `member->getValue()` has a value and
is not `Empty`.  Failure to do so will trigger an assertion failure in
`llvm::pdb::Variant::getBitWidth()`.  This can occur when the `static`
member is a forward declaration.

Differential Revision: https://reviews.llvm.org/D146536
Reviewed By: sgraenitz

lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp

index da57338..b1a8824 100644 (file)
@@ -1299,6 +1299,15 @@ void PDBASTParser::AddRecordMembers(
       // Query the symbol's value as the variable initializer if valid.
       if (member_comp_type.IsConst()) {
         auto value = member->getValue();
+        if (value.Type == llvm::pdb::Empty) {
+          LLDB_LOG(GetLog(LLDBLog::AST),
+                   "Class '{0}' has member '{1}' of type '{2}' with an unknown "
+                   "constant size.",
+                   record_type.GetTypeName(), member_name,
+                   member_comp_type.GetTypeName());
+          continue;
+        }
+
         clang::QualType qual_type = decl->getType();
         unsigned type_width = m_ast.getASTContext().getIntWidth(qual_type);
         unsigned constant_width = value.getBitWidth();