Skip to content

Commit 2ebdbc5

Browse files
committed
[lldb][ClangASTImporter] Assert that we never overwrite a record layout
1 parent d78f7bf commit 2ebdbc5

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,6 @@ bool ClangASTImporter::LayoutRecordType(
767767
field_offsets.swap(pos->second.field_offsets);
768768
base_offsets.swap(pos->second.base_offsets);
769769
vbase_offsets.swap(pos->second.vbase_offsets);
770-
m_record_decl_to_layout_map.erase(pos);
771770
return true;
772771
}
773772

@@ -789,9 +788,15 @@ bool ClangASTImporter::LayoutRecordType(
789788

790789
void ClangASTImporter::SetRecordLayout(clang::RecordDecl *decl,
791790
const LayoutInfo &layout) {
791+
assert(!HasRecordLayout(decl) && "Trying to overwrite layout?");
792792
m_record_decl_to_layout_map.insert(std::make_pair(decl, layout));
793793
}
794794

795+
bool ClangASTImporter::HasRecordLayout(const RecordDecl *decl) const {
796+
decl = llvm::cast<RecordDecl>(decl->getFirstDecl());
797+
return m_record_decl_to_layout_map.count(decl) > 0;
798+
}
799+
795800
bool ClangASTImporter::CompleteTagDecl(clang::TagDecl *decl) {
796801
DeclOrigin decl_origin = GetDeclOrigin(decl);
797802

lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class ClangASTImporter {
119119
/// \param layout The layout for the record.
120120
void SetRecordLayout(clang::RecordDecl *decl, const LayoutInfo &layout);
121121

122+
bool HasRecordLayout(const clang::RecordDecl *decl) const;
123+
122124
bool LayoutRecordType(
123125
const clang::RecordDecl *record_decl, uint64_t &bit_size,
124126
uint64_t &alignment,

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,8 +2276,9 @@ bool DWARFASTParserClang::CompleteRecordType(const DWARFDIE &die,
22762276
TypeSystemClang::BuildIndirectFields(clang_type);
22772277
TypeSystemClang::CompleteTagDeclarationDefinition(clang_type);
22782278

2279-
if (!layout_info.field_offsets.empty() || !layout_info.base_offsets.empty() ||
2280-
!layout_info.vbase_offsets.empty()) {
2279+
clang::CXXRecordDecl *record_decl =
2280+
m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType());
2281+
if (record_decl && !GetClangASTImporter().HasRecordLayout(record_decl)) {
22812282
if (type)
22822283
layout_info.bit_size = type->GetByteSize(nullptr).value_or(0) * 8;
22832284
if (layout_info.bit_size == 0)
@@ -2287,10 +2288,7 @@ bool DWARFASTParserClang::CompleteRecordType(const DWARFDIE &die,
22872288
layout_info.alignment =
22882289
die.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_alignment, 0) * 8;
22892290

2290-
clang::CXXRecordDecl *record_decl =
2291-
m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType());
2292-
if (record_decl)
2293-
GetClangASTImporter().SetRecordLayout(record_decl, layout_info);
2291+
GetClangASTImporter().SetRecordLayout(record_decl, layout_info);
22942292
}
22952293
// Now parse all contained types inside of the class. We make forward
22962294
// declarations to all classes, but we need the CXXRecordDecl to have decls

0 commit comments

Comments
 (0)