@@ -3072,14 +3072,43 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
3072
3072
3073
3073
// See comments below about -gsimple-template-names for why we attempt to
3074
3074
// 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
+ : " " );
3080
3085
}
3086
+ const bool any_template_params = llvm::any_of (
3087
+ template_params, [](llvm::StringRef p) { return !p.empty (); });
3081
3088
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
+ };
3083
3112
m_index->GetFullyQualifiedType (die_dwarf_decl_ctx, [&](DWARFDIE type_die) {
3084
3113
// Make sure type_die's language matches the type system we are
3085
3114
// looking for. We don't want to find a "Foo" type from Java if we
@@ -3088,13 +3117,7 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
3088
3117
!type_system->SupportsLanguage (GetLanguage (*type_die.GetCU ())))
3089
3118
return true ;
3090
3119
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)) {
3098
3121
if (log ) {
3099
3122
GetObjectFile ()->GetModule ()->LogMessage (
3100
3123
log ,
@@ -3122,27 +3145,6 @@ SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
3122
3145
if (!resolved_type || resolved_type == DIE_IS_BEING_PARSED)
3123
3146
return true ;
3124
3147
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
-
3146
3148
type_sp = resolved_type->shared_from_this ();
3147
3149
return false ;
3148
3150
});
0 commit comments