Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
[AST] Use unique_ptr for VTableLayout.
Browse files Browse the repository at this point in the history
Reviewers: timshen

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D25421

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283769 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Justin Lebar committed Oct 10, 2016
1 parent 7c4b8c0 commit 7b7c816
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
13 changes: 6 additions & 7 deletions include/clang/AST/VTableBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,9 @@ class ItaniumVTableContext : public VTableContextBase {
typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVTableIndicesTy;
MethodVTableIndicesTy MethodVTableIndices;

typedef llvm::DenseMap<const CXXRecordDecl *, const VTableLayout *>
VTableLayoutMapTy;
typedef llvm::DenseMap<const CXXRecordDecl *,
std::unique_ptr<const VTableLayout>>
VTableLayoutMapTy;
VTableLayoutMapTy VTableLayouts;

typedef std::pair<const CXXRecordDecl *,
Expand All @@ -341,11 +342,9 @@ class ItaniumVTableContext : public VTableContextBase {
return *VTableLayouts[RD];
}

VTableLayout *
createConstructionVTableLayout(const CXXRecordDecl *MostDerivedClass,
CharUnits MostDerivedClassOffset,
bool MostDerivedClassIsVirtual,
const CXXRecordDecl *LayoutClass);
std::unique_ptr<VTableLayout> createConstructionVTableLayout(
const CXXRecordDecl *MostDerivedClass, CharUnits MostDerivedClassOffset,
bool MostDerivedClassIsVirtual, const CXXRecordDecl *LayoutClass);

/// \brief Locate a virtual function in the vtable.
///
Expand Down
22 changes: 10 additions & 12 deletions lib/AST/VTableBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2234,9 +2234,7 @@ VTableLayout::~VTableLayout() { }
ItaniumVTableContext::ItaniumVTableContext(ASTContext &Context)
: VTableContextBase(/*MS=*/false) {}

ItaniumVTableContext::~ItaniumVTableContext() {
llvm::DeleteContainerSeconds(VTableLayouts);
}
ItaniumVTableContext::~ItaniumVTableContext() {}

uint64_t ItaniumVTableContext::getMethodVTableIndex(GlobalDecl GD) {
MethodVTableIndicesTy::iterator I = MethodVTableIndices.find(GD);
Expand Down Expand Up @@ -2280,21 +2278,20 @@ ItaniumVTableContext::getVirtualBaseOffsetOffset(const CXXRecordDecl *RD,
return I->second;
}

static VTableLayout *CreateVTableLayout(const ItaniumVTableBuilder &Builder) {
static std::unique_ptr<VTableLayout>
CreateVTableLayout(const ItaniumVTableBuilder &Builder) {
SmallVector<VTableLayout::VTableThunkTy, 1>
VTableThunks(Builder.vtable_thunks_begin(), Builder.vtable_thunks_end());

return new VTableLayout(Builder.getNumVTableComponents(),
Builder.vtable_component_begin(),
VTableThunks.size(),
VTableThunks.data(),
Builder.getAddressPoints(),
/*IsMicrosoftABI=*/false);
return llvm::make_unique<VTableLayout>(
Builder.getNumVTableComponents(), Builder.vtable_component_begin(),
VTableThunks.size(), VTableThunks.data(), Builder.getAddressPoints(),
/*IsMicrosoftABI=*/false);
}

void
ItaniumVTableContext::computeVTableRelatedInformation(const CXXRecordDecl *RD) {
const VTableLayout *&Entry = VTableLayouts[RD];
std::unique_ptr<const VTableLayout> &Entry = VTableLayouts[RD];

// Check if we've computed this information before.
if (Entry)
Expand Down Expand Up @@ -2330,7 +2327,8 @@ ItaniumVTableContext::computeVTableRelatedInformation(const CXXRecordDecl *RD) {
}
}

VTableLayout *ItaniumVTableContext::createConstructionVTableLayout(
std::unique_ptr<VTableLayout>
ItaniumVTableContext::createConstructionVTableLayout(
const CXXRecordDecl *MostDerivedClass, CharUnits MostDerivedClassOffset,
bool MostDerivedClassIsVirtual, const CXXRecordDecl *LayoutClass) {
ItaniumVTableBuilder Builder(*this, MostDerivedClass, MostDerivedClassOffset,
Expand Down

0 comments on commit 7b7c816

Please sign in to comment.