================
@@ -233,6 +233,32 @@ Error UdtRecordCompleter::visitKnownMember(
 
 Error UdtRecordCompleter::visitKnownMember(CVMemberRecord &cvr,
                                            NestedTypeRecord &nested) {
+  // Typedefs can only be added on structs.
+  if (m_record.record.kind != Member::Struct)
+    return Error::success();
+
+  clang::QualType qt =
+      m_ast_builder.GetOrCreateType(PdbTypeSymId(nested.Type, false));
+  if (qt.isNull())
+    return Error::success();
+  CompilerType ct = m_ast_builder.ToCompilerType(qt);
+
+  // There's no distinction between nested types and typedefs, so check if we
+  // encountered a nested type.
+  auto *pdb = static_cast<SymbolFileNativePDB *>(
+      m_ast_builder.clang().GetSymbolFile()->GetBackingSymbolFile());
+  std::optional<TypeIndex> parent = pdb->GetParentType(nested.Type);
+  if (parent && *parent == m_id.index && ct.GetTypeName(true) == nested.Name)
----------------
Nerixyz wrote:

> So `ct.GetTypeName(true)` returns the type name `Bar` for both `Bar` and 
> `Baz`?

Yes

> Shouldn't it be the base name of the parent?

The last check is there to see if this `LF_NESTTYPE` originates from an actual 
nested type or a typedef.
In the example above, both `Bar`'s and `Baz`' parent is `Foo`. For `Bar`, we 
don't want to create a typedef, because we already have `Bar` as the nested 
type. For `Baz`, we do want to create a typedef. If we were to use the base 
name of the parent (i.e. the current tag record), we'd get `Foo`. 

The output of llvm-pdbutil is a bit confusing, because [it outputs 
`NestedTypeRecord::Type` as 
`parent`](https://github.com/llvm/llvm-project/blob/5ebb9285321157fe89496746d59b46fbc2480232/llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp#L528).




https://github.com/llvm/llvm-project/pull/169248
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to