@@ -223,7 +223,6 @@ TypeSP DWARFASTParserClang::ParseTypeFromClangModule(const SymbolContext &sc,
223
223
nullptr , LLDB_INVALID_UID, Type::eEncodingInvalid,
224
224
&pcm_type_sp->GetDeclaration (), type, Type::ResolveState::Forward,
225
225
TypePayloadClang (GetOwningClangModule (die)));
226
- dwarf->GetDIEToType ()[die.GetDIE ()] = type_sp.get ();
227
226
clang::TagDecl *tag_decl = TypeSystemClang::GetAsTagDecl (type);
228
227
if (tag_decl) {
229
228
LinkDeclContextToDIE (tag_decl, die);
@@ -458,90 +457,78 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
458
457
DW_TAG_value_to_name (die.Tag ()), die.Tag (), die.GetName ());
459
458
}
460
459
461
- Type *type_ptr = dwarf->GetDIEToType ().lookup (die.GetDIE ());
462
- if (type_ptr == DIE_IS_BEING_PARSED)
463
- return nullptr ;
464
- if (type_ptr)
465
- return type_ptr->shared_from_this ();
466
460
// Set a bit that lets us know that we are currently parsing this
467
- dwarf->GetDIEToType ()[die.GetDIE ()] = DIE_IS_BEING_PARSED;
461
+ if (auto [it, inserted] =
462
+ dwarf->GetDIEToType ().try_emplace (die.GetDIE (), DIE_IS_BEING_PARSED);
463
+ !inserted) {
464
+ if (it->getSecond () == nullptr || it->getSecond () == DIE_IS_BEING_PARSED)
465
+ return nullptr ;
466
+ return it->getSecond ()->shared_from_this ();
467
+ }
468
468
469
469
ParsedDWARFTypeAttributes attrs (die);
470
470
471
+ TypeSP type_sp;
471
472
if (DWARFDIE signature_die = attrs.signature .Reference ()) {
472
- if (TypeSP type_sp =
473
- ParseTypeFromDWARF (sc, signature_die, type_is_new_ptr)) {
474
- dwarf->GetDIEToType ()[die.GetDIE ()] = type_sp.get ();
473
+ type_sp = ParseTypeFromDWARF (sc, signature_die, type_is_new_ptr);
474
+ if (type_sp) {
475
475
if (clang::DeclContext *decl_ctx =
476
476
GetCachedClangDeclContextForDIE (signature_die))
477
477
LinkDeclContextToDIE (decl_ctx, die);
478
- return type_sp;
479
478
}
480
- return nullptr ;
481
- }
482
-
483
- if (type_is_new_ptr)
484
- *type_is_new_ptr = true ;
485
-
486
- const dw_tag_t tag = die.Tag ();
487
-
488
- TypeSP type_sp;
489
-
490
- switch (tag) {
491
- case DW_TAG_typedef:
492
- case DW_TAG_base_type:
493
- case DW_TAG_pointer_type:
494
- case DW_TAG_reference_type:
495
- case DW_TAG_rvalue_reference_type:
496
- case DW_TAG_const_type:
497
- case DW_TAG_restrict_type:
498
- case DW_TAG_volatile_type:
499
- case DW_TAG_LLVM_ptrauth_type:
500
- case DW_TAG_atomic_type:
501
- case DW_TAG_unspecified_type: {
502
- type_sp = ParseTypeModifier (sc, die, attrs);
503
- break ;
504
- }
505
-
506
- case DW_TAG_structure_type:
507
- case DW_TAG_union_type:
508
- case DW_TAG_class_type: {
509
- type_sp = ParseStructureLikeDIE (sc, die, attrs);
510
- break ;
511
- }
479
+ } else {
480
+ if (type_is_new_ptr)
481
+ *type_is_new_ptr = true ;
512
482
513
- case DW_TAG_enumeration_type: {
514
- type_sp = ParseEnum (sc, die, attrs);
515
- break ;
516
- }
483
+ const dw_tag_t tag = die.Tag ();
517
484
518
- case DW_TAG_inlined_subroutine:
519
- case DW_TAG_subprogram:
520
- case DW_TAG_subroutine_type: {
521
- type_sp = ParseSubroutine (die, attrs);
522
- break ;
523
- }
524
- case DW_TAG_array_type: {
525
- type_sp = ParseArrayType (die, attrs);
526
- break ;
527
- }
528
- case DW_TAG_ptr_to_member_type: {
529
- type_sp = ParsePointerToMemberType (die, attrs);
530
- break ;
485
+ switch (tag) {
486
+ case DW_TAG_typedef:
487
+ case DW_TAG_base_type:
488
+ case DW_TAG_pointer_type:
489
+ case DW_TAG_reference_type:
490
+ case DW_TAG_rvalue_reference_type:
491
+ case DW_TAG_const_type:
492
+ case DW_TAG_restrict_type:
493
+ case DW_TAG_volatile_type:
494
+ case DW_TAG_LLVM_ptrauth_type:
495
+ case DW_TAG_atomic_type:
496
+ case DW_TAG_unspecified_type:
497
+ type_sp = ParseTypeModifier (sc, die, attrs);
498
+ break ;
499
+ case DW_TAG_structure_type:
500
+ case DW_TAG_union_type:
501
+ case DW_TAG_class_type:
502
+ type_sp = ParseStructureLikeDIE (sc, die, attrs);
503
+ break ;
504
+ case DW_TAG_enumeration_type:
505
+ type_sp = ParseEnum (sc, die, attrs);
506
+ break ;
507
+ case DW_TAG_inlined_subroutine:
508
+ case DW_TAG_subprogram:
509
+ case DW_TAG_subroutine_type:
510
+ type_sp = ParseSubroutine (die, attrs);
511
+ break ;
512
+ case DW_TAG_array_type:
513
+ type_sp = ParseArrayType (die, attrs);
514
+ break ;
515
+ case DW_TAG_ptr_to_member_type:
516
+ type_sp = ParsePointerToMemberType (die, attrs);
517
+ break ;
518
+ default :
519
+ dwarf->GetObjectFile ()->GetModule ()->ReportError (
520
+ " [{0:x16}]: unhandled type tag {1:x4} ({2}), "
521
+ " please file a bug and "
522
+ " attach the file at the start of this error message" ,
523
+ die.GetOffset (), tag, DW_TAG_value_to_name (tag));
524
+ break ;
525
+ }
526
+ UpdateSymbolContextScopeForType (sc, die, type_sp);
531
527
}
532
- default :
533
- dwarf->GetObjectFile ()->GetModule ()->ReportError (
534
- " [{0:x16}]: unhandled type tag {1:x4} ({2}), "
535
- " please file a bug and "
536
- " attach the file at the start of this error message" ,
537
- die.GetOffset (), tag, DW_TAG_value_to_name (tag));
538
- break ;
528
+ if (type_sp) {
529
+ dwarf->GetDIEToType ()[die.GetDIE ()] = type_sp.get ();
539
530
}
540
-
541
- // TODO: We should consider making the switch above exhaustive to simplify
542
- // control flow in ParseTypeFromDWARF. Then, we could simply replace this
543
- // return statement with a call to llvm_unreachable.
544
- return UpdateSymbolContextScopeForType (sc, die, type_sp);
531
+ return type_sp;
545
532
}
546
533
547
534
static std::optional<uint32_t >
@@ -830,12 +817,9 @@ DWARFASTParserClang::ParseTypeModifier(const SymbolContext &sc,
830
817
}
831
818
}
832
819
833
- type_sp = dwarf->MakeType (die.GetID (), attrs.name , attrs.byte_size , nullptr ,
834
- attrs.type .Reference ().GetID (), encoding_data_type,
835
- &attrs.decl , clang_type, resolve_state, payload);
836
-
837
- dwarf->GetDIEToType ()[die.GetDIE ()] = type_sp.get ();
838
- return type_sp;
820
+ return dwarf->MakeType (die.GetID (), attrs.name , attrs.byte_size , nullptr ,
821
+ attrs.type .Reference ().GetID (), encoding_data_type,
822
+ &attrs.decl , clang_type, resolve_state, payload);
839
823
}
840
824
841
825
std::string
@@ -885,13 +869,10 @@ TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,
885
869
type_sp->GetID ());
886
870
}
887
871
888
- // We found a real definition for this type elsewhere so lets use
889
- // it and cache the fact that we found a complete type for this
890
- // die
891
- dwarf->GetDIEToType ()[die.GetDIE ()] = type_sp.get ();
892
- clang::DeclContext *defn_decl_ctx =
893
- GetCachedClangDeclContextForDIE (dwarf->GetDIE (type_sp->GetID ()));
894
- if (defn_decl_ctx)
872
+ // We found a real definition for this type elsewhere so must link its
873
+ // DeclContext to this die.
874
+ if (clang::DeclContext *defn_decl_ctx =
875
+ GetCachedClangDeclContextForDIE (dwarf->GetDIE (type_sp->GetID ())))
895
876
LinkDeclContextToDIE (defn_decl_ctx, die);
896
877
return type_sp;
897
878
}
@@ -1052,7 +1033,7 @@ std::pair<bool, TypeSP> DWARFASTParserClang::ParseCXXMethod(
1052
1033
// Unfortunately classes don't like having stuff added
1053
1034
// to them after their definitions are complete...
1054
1035
1055
- Type *type_ptr = dwarf->GetDIEToType ()[ die.GetDIE ()] ;
1036
+ Type *type_ptr = dwarf->GetDIEToType (). lookup ( die.GetDIE ()) ;
1056
1037
if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
1057
1038
return {true , type_ptr->shared_from_this ()};
1058
1039
}
@@ -1164,7 +1145,7 @@ std::pair<bool, TypeSP> DWARFASTParserClang::ParseCXXMethod(
1164
1145
// we need to modify the dwarf->GetDIEToType() so it
1165
1146
// doesn't think we are trying to parse this DIE
1166
1147
// anymore...
1167
- dwarf->GetDIEToType ()[ die.GetDIE ()] = NULL ;
1148
+ dwarf->GetDIEToType (). erase ( die.GetDIE ()) ;
1168
1149
1169
1150
// Now we get the full type to force our class type to
1170
1151
// complete itself using the clang::ExternalASTSource
@@ -1174,7 +1155,7 @@ std::pair<bool, TypeSP> DWARFASTParserClang::ParseCXXMethod(
1174
1155
1175
1156
// The type for this DIE should have been filled in the
1176
1157
// function call above.
1177
- Type *type_ptr = dwarf->GetDIEToType ()[ die.GetDIE ()] ;
1158
+ Type *type_ptr = dwarf->GetDIEToType (). lookup ( die.GetDIE ()) ;
1178
1159
if (type_ptr && type_ptr != DIE_IS_BEING_PARSED)
1179
1160
return {true , type_ptr->shared_from_this ()};
1180
1161
@@ -1576,7 +1557,6 @@ TypeSP DWARFASTParserClang::UpdateSymbolContextScopeForType(
1576
1557
if (!type_sp)
1577
1558
return type_sp;
1578
1559
1579
- SymbolFileDWARF *dwarf = die.GetDWARF ();
1580
1560
DWARFDIE sc_parent_die = SymbolFileDWARF::GetParentSymbolContextDIE (die);
1581
1561
dw_tag_t sc_parent_tag = sc_parent_die.Tag ();
1582
1562
@@ -1595,8 +1575,6 @@ TypeSP DWARFASTParserClang::UpdateSymbolContextScopeForType(
1595
1575
1596
1576
if (symbol_context_scope != nullptr )
1597
1577
type_sp->SetSymbolContextScope (symbol_context_scope);
1598
-
1599
- dwarf->GetDIEToType ()[die.GetDIE ()] = type_sp.get ();
1600
1578
return type_sp;
1601
1579
}
1602
1580
@@ -1691,7 +1669,6 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
1691
1669
*unique_ast_entry_up)) {
1692
1670
type_sp = unique_ast_entry_up->m_type_sp ;
1693
1671
if (type_sp) {
1694
- dwarf->GetDIEToType ()[die.GetDIE ()] = type_sp.get ();
1695
1672
LinkDeclContextToDIE (
1696
1673
GetCachedClangDeclContextForDIE (unique_ast_entry_up->m_die ), die);
1697
1674
return type_sp;
@@ -1763,11 +1740,6 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
1763
1740
DW_TAG_value_to_name (tag), tag, attrs.name .GetCString (),
1764
1741
type_sp->GetID ());
1765
1742
}
1766
-
1767
- // We found a real definition for this type elsewhere so lets use
1768
- // it and cache the fact that we found a complete type for this
1769
- // die
1770
- dwarf->GetDIEToType ()[die.GetDIE ()] = type_sp.get ();
1771
1743
return type_sp;
1772
1744
}
1773
1745
}
@@ -1823,12 +1795,10 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
1823
1795
type_sp->GetID ());
1824
1796
}
1825
1797
1826
- // We found a real definition for this type elsewhere so lets use
1827
- // it and cache the fact that we found a complete type for this die
1828
- dwarf->GetDIEToType ()[die.GetDIE ()] = type_sp.get ();
1829
- clang::DeclContext *defn_decl_ctx =
1830
- GetCachedClangDeclContextForDIE (dwarf->GetDIE (type_sp->GetID ()));
1831
- if (defn_decl_ctx)
1798
+ // We found a real definition for this type elsewhere so must link its
1799
+ // DeclContext to this die.
1800
+ if (clang::DeclContext *defn_decl_ctx =
1801
+ GetCachedClangDeclContextForDIE (dwarf->GetDIE (type_sp->GetID ())))
1832
1802
LinkDeclContextToDIE (defn_decl_ctx, die);
1833
1803
return type_sp;
1834
1804
}
@@ -3809,7 +3779,7 @@ bool DWARFASTParserClang::CopyUniqueClassMethodTypes(
3809
3779
if (dst_decl_ctx)
3810
3780
src_dwarf_ast_parser->LinkDeclContextToDIE (dst_decl_ctx, src);
3811
3781
3812
- if (Type *src_child_type = die_to_type[ src.GetDIE ()] )
3782
+ if (Type *src_child_type = die_to_type. lookup ( src.GetDIE ()) )
3813
3783
die_to_type[dst.GetDIE ()] = src_child_type;
3814
3784
};
3815
3785
0 commit comments