================
@@ -3073,14 +3073,43 @@ 
SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
 
     // See comments below about -gsimple-template-names for why we attempt to
     // compute missing template parameter names.
-    ConstString template_params;
-    if (type_system) {
-      DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
-      if (dwarf_ast)
-        template_params = dwarf_ast->GetDIEClassTemplateParams(die);
+    std::vector<std::string> template_params;
+    DWARFDeclContext die_dwarf_decl_ctx;
+    DWARFASTParser *dwarf_ast = type_system ? type_system->GetDWARFParser() : 
nullptr;
+    for (DWARFDIE ctx_die = die; ctx_die && !isUnitType(ctx_die.Tag());
+         ctx_die = ctx_die.GetParentDeclContextDIE()) {
+      die_dwarf_decl_ctx.AppendDeclContext(ctx_die.Tag(), ctx_die.GetName());
+      template_params.push_back(
+          (ctx_die.IsStructUnionOrClass() && dwarf_ast)
+              ? dwarf_ast->GetDIEClassTemplateParams(ctx_die)
+              : "");
     }
+    const bool any_template_params = llvm::any_of(
+        template_params, [](llvm::StringRef p) { return !p.empty(); });
 
-    const DWARFDeclContext die_dwarf_decl_ctx = die.GetDWARFDeclContext();
+    auto die_matches = [&](DWARFDIE type_die) {
+      // Resolve the type if both have the same tag or {class, struct} tags.
+      const bool tag_matches =
+          type_die.Tag() == tag ||
+          (IsStructOrClassTag(type_die.Tag()) && IsStructOrClassTag(tag));
----------------
dwblaikie wrote:

FWIW, I'm pretty sure that the only difference between class and struct is the 
access control.

Though C++ technically rejects things like forward declaring a thing as a 
struct, then actually defining it as a class - not sure if that'd ever come up 
for lldb (for instance when interacting with clang header modules? If the DWARF 
contained a declaration of a thing and always created it as a struct, but then 
tried to load a module with that name as a class definition) I guess it'd also 
maybe break technically valid user code in expression evaluation - if the name 
was used for a varibale and a type, the user should be able to disambiguate in 
favor of the type by saying, eg: "sizeof(class MyType)" but if lldb made 
everything a struct ... hmm, nope, that'd be fine:
```
$ cat test.cpp
struct MyType { };
int MyType = 3;
static_assert(sizeof(class MyType) == 1);
$ clang++-tot test.cpp -fsyntax-only
```

I guess printing types in lldb would be technically wrong, since it'd print as 
"struct MyType {" instead of "class MyType {"?

(but it might mean not having to have the access modifier hack? If everything 
was made as a struct, and none of the members were given other access modifiers 
- everything would be accessible by default anyway)
```

https://github.com/llvm/llvm-project/pull/95905
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to