summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2010-04-20 16:22:16 +0000
committerAnders Carlsson <andersca@mac.com>2010-04-20 16:22:16 +0000
commit6a0227df49ca6dacb6b4899d882a9462b7231f48 (patch)
tree426f6417ccfffdde62eafd4f939e8f0dbdf4f6c7 /clang/lib/CodeGen
parent53cebd1ea62eee750ce825b1587058fe47136b9c (diff)
downloadbcm5719-llvm-6a0227df49ca6dacb6b4899d882a9462b7231f48.tar.gz
bcm5719-llvm-6a0227df49ca6dacb6b4899d882a9462b7231f48.zip
Fix a bug which triggered the assertion I added yesterday. Basically, when we initialize the vtable pointer for a virtual base, and there was another path from the most derived class to another base with the same class type, we would use the wrong base.
llvm-svn: 101911
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGClass.cpp41
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.h2
2 files changed, 30 insertions, 13 deletions
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index a21af413fd7..b2991ade436 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -1549,6 +1549,7 @@ CodeGenFunction::GetVirtualBaseClassOffset(llvm::Value *This,
void
CodeGenFunction::InitializeVTablePointer(BaseSubobject Base,
const CXXRecordDecl *NearestVBase,
+ uint64_t BaseOffsetFromNearestVBase,
llvm::Constant *VTable,
const CXXRecordDecl *VTableClass) {
const CXXRecordDecl *RD = Base.getBase();
@@ -1576,22 +1577,32 @@ CodeGenFunction::InitializeVTablePointer(BaseSubobject Base,
Builder.CreateConstInBoundsGEP2_64(VTable, 0, AddressPoint);
}
+ llvm::Value *VTableField = LoadCXXThis();
+
// Compute where to store the address point.
- llvm::Value *VTableField;
-
- if (CodeGenVTables::needsVTTParameter(CurGD) && NearestVBase) {
- // We need to use the virtual base offset offset because the virtual base
- // might have a different offset in the most derived class.
- VTableField = GetAddressOfBaseClass(LoadCXXThis(), VTableClass, RD,
- /*NullCheckValue=*/false);
- } else {
- const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(CGM.getLLVMContext());
+ uint64_t NonVirtualOffset = BaseOffsetFromNearestVBase;
- VTableField = Builder.CreateBitCast(LoadCXXThis(), Int8PtrTy);
- VTableField =
- Builder.CreateConstInBoundsGEP1_64(VTableField, Base.getBaseOffset() / 8);
+ llvm::Value *VirtualOffset = 0;
+ if (NearestVBase) {
+ if (!CodeGenVTables::needsVTTParameter(CurGD)) {
+ // Just get the vbase offset in the complete class.
+ const ASTRecordLayout &Layout =
+ getContext().getASTRecordLayout(VTableClass);
+
+ NonVirtualOffset += Layout.getVBaseClassOffset(NearestVBase);
+ } else {
+ // We need to use the virtual base offset offset because the virtual base
+ // might have a different offset in the most derived class.
+ VirtualOffset = GetVirtualBaseClassOffset(VTableField,
+ VTableClass, NearestVBase);
+ }
}
+ if (NonVirtualOffset || VirtualOffset)
+ VTableField =
+ ApplyNonVirtualAndVirtualOffset(*this, VTableField,
+ NonVirtualOffset, VirtualOffset);
+
// Finally, store the address point.
const llvm::Type *AddressPointPtrTy =
VTableAddressPoint->getType()->getPointerTo();
@@ -1602,6 +1613,7 @@ CodeGenFunction::InitializeVTablePointer(BaseSubobject Base,
void
CodeGenFunction::InitializeVTablePointers(BaseSubobject Base,
const CXXRecordDecl *NearestVBase,
+ uint64_t BaseOffsetFromNearestVBase,
bool BaseIsNonVirtualPrimaryBase,
llvm::Constant *VTable,
const CXXRecordDecl *VTableClass,
@@ -1610,7 +1622,8 @@ CodeGenFunction::InitializeVTablePointers(BaseSubobject Base,
// been set.
if (!BaseIsNonVirtualPrimaryBase) {
// Initialize the vtable pointer for this base.
- InitializeVTablePointer(Base, NearestVBase, VTable, VTableClass);
+ InitializeVTablePointer(Base, NearestVBase, BaseOffsetFromNearestVBase,
+ VTable, VTableClass);
}
const CXXRecordDecl *RD = Base.getBase();
@@ -1647,6 +1660,7 @@ CodeGenFunction::InitializeVTablePointers(BaseSubobject Base,
InitializeVTablePointers(BaseSubobject(BaseDecl, BaseOffset),
I->isVirtual() ? BaseDecl : NearestVBase,
+ I->isVirtual() ? 0 : BaseOffsetFromNearestVBase,
BaseDeclIsNonVirtualPrimaryBase,
VTable, VTableClass, VBases);
}
@@ -1663,6 +1677,7 @@ void CodeGenFunction::InitializeVTablePointers(const CXXRecordDecl *RD) {
// Initialize the vtable pointers for this class and all of its bases.
VisitedVirtualBasesSetTy VBases;
InitializeVTablePointers(BaseSubobject(RD, 0), /*NearestVBase=*/0,
+ /*BaseOffsetFromNearestVBase=*/0,
/*BaseIsNonVirtualPrimaryBase=*/false,
VTable, RD, VBases);
}
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index c43e0006e69..12e37e42d72 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -536,12 +536,14 @@ public:
///
void InitializeVTablePointer(BaseSubobject Base,
const CXXRecordDecl *NearestVBase,
+ uint64_t BaseOffsetFromNearestVBase,
llvm::Constant *VTable,
const CXXRecordDecl *VTableClass);
typedef llvm::SmallPtrSet<const CXXRecordDecl *, 4> VisitedVirtualBasesSetTy;
void InitializeVTablePointers(BaseSubobject Base,
const CXXRecordDecl *NearestVBase,
+ uint64_t BaseOffsetFromNearestVBase,
bool BaseIsNonVirtualPrimaryBase,
llvm::Constant *VTable,
const CXXRecordDecl *VTableClass,
OpenPOWER on IntegriCloud