@@ -3072,14 +3072,43 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
30723072
30733073 // See comments below about -gsimple-template-names for why we attempt to
30743074 // compute missing template parameter names.
3075- ConstString template_params;
3076- if (type_system) {
3077- DWARFASTParser *dwarf_ast = type_system->GetDWARFParser ();
3078- if (dwarf_ast)
3079- template_params = dwarf_ast->GetDIEClassTemplateParams (die);
3075+ std::vector<std::string> template_params;
3076+ DWARFDeclContext die_dwarf_decl_ctx;
3077+ DWARFASTParser *dwarf_ast = type_system ? type_system->GetDWARFParser () : nullptr ;
3078+ for (DWARFDIE ctx_die = die; ctx_die && !isUnitType (ctx_die.Tag ());
3079+ ctx_die = ctx_die.GetParentDeclContextDIE ()) {
3080+ die_dwarf_decl_ctx.AppendDeclContext (ctx_die.Tag (), ctx_die.GetName ());
3081+ template_params.push_back (
3082+ (ctx_die.IsStructUnionOrClass () && dwarf_ast)
3083+ ? dwarf_ast->GetDIEClassTemplateParams (ctx_die)
3084+ : " " );
30803085 }
3086+ const bool any_template_params = llvm::any_of (
3087+ template_params, [](llvm::StringRef p) { return !p.empty (); });
30813088
3082- const DWARFDeclContext die_dwarf_decl_ctx = die.GetDWARFDeclContext ();
3089+ auto die_matches = [&](DWARFDIE type_die) {
3090+ // Resolve the type if both have the same tag or {class, struct} tags.
3091+ const bool tag_matches =
3092+ type_die.Tag () == tag ||
3093+ (IsStructOrClassTag (type_die.Tag ()) && IsStructOrClassTag (tag));
3094+ if (!tag_matches)
3095+ return false ;
3096+ if (any_template_params) {
3097+ size_t pos = 0 ;
3098+ for (DWARFDIE ctx_die = type_die;
3099+ ctx_die && !isUnitType (ctx_die.Tag ()) &&
3100+ pos < template_params.size ();
3101+ ctx_die = ctx_die.GetParentDeclContextDIE (), ++pos) {
3102+ if (template_params[pos].empty ())
3103+ continue ;
3104+ if (template_params[pos] != dwarf_ast->GetDIEClassTemplateParams (ctx_die))
3105+ return false ;
3106+ }
3107+ if (pos != template_params.size ())
3108+ return false ;
3109+ }
3110+ return true ;
3111+ };
30833112 m_index->GetFullyQualifiedType (die_dwarf_decl_ctx, [&](DWARFDIE type_die) {
30843113 // Make sure type_die's language matches the type system we are
30853114 // looking for. We don't want to find a "Foo" type from Java if we
@@ -3088,13 +3117,7 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
30883117 !type_system->SupportsLanguage (GetLanguage (*type_die.GetCU ())))
30893118 return true ;
30903119
3091- const dw_tag_t type_tag = type_die.Tag ();
3092- // Resolve the type if both have the same tag or {class, struct} tags.
3093- const bool try_resolving_type =
3094- type_tag == tag ||
3095- (IsStructOrClassTag (type_tag) && IsStructOrClassTag (tag));
3096-
3097- if (!try_resolving_type) {
3120+ if (!die_matches (type_die)) {
30983121 if (log) {
30993122 GetObjectFile ()->GetModule ()->LogMessage (
31003123 log,
@@ -3122,27 +3145,6 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
31223145 if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
31233146 return true ;
31243147
3125- // With -gsimple-template-names, the DIE name may not contain the template
3126- // parameters. If the declaration has template parameters but doesn't
3127- // contain '<', check that the child template parameters match.
3128- if (template_params) {
3129- llvm::StringRef test_base_name =
3130- GetTypeForDIE (type_die)->GetBaseName ().GetStringRef ();
3131- auto i = test_base_name.find (' <' );
3132-
3133- // Full name from clang AST doesn't contain '<' so this type_die isn't
3134- // a template parameter, but we're expecting template parameters, so
3135- // bail.
3136- if (i == llvm::StringRef::npos)
3137- return true ;
3138-
3139- llvm::StringRef test_template_params =
3140- test_base_name.slice (i, test_base_name.size ());
3141- // Bail if template parameters don't match.
3142- if (test_template_params != template_params.GetStringRef ())
3143- return true ;
3144- }
3145-
31463148 type_sp = resolved_type->shared_from_this ();
31473149 return false ;
31483150 });
0 commit comments