[cfe-commits] r78396 - in /cfe/trunk: include/clang/AST/RecordLayout.h lib/AST/RecordLayoutBuilder.cpp lib/AST/RecordLayoutBuilder.h lib/CodeGen/CGCXX.cpp test/CodeGenCXX/virt.cpp
Mike Stump
mrs at apple.com
Fri Aug 7 12:00:50 PDT 2009
Author: mrs
Date: Fri Aug 7 14:00:50 2009
New Revision: 78396
URL: http://llvm.org/viewvc/llvm-project?rev=78396&view=rev
Log:
Add ability to generate vcall offsets for primary virtual base.
Modified:
cfe/trunk/include/clang/AST/RecordLayout.h
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
cfe/trunk/lib/AST/RecordLayoutBuilder.h
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/test/CodeGenCXX/virt.cpp
Modified: cfe/trunk/include/clang/AST/RecordLayout.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecordLayout.h?rev=78396&r1=78395&r2=78396&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecordLayout.h (original)
+++ cfe/trunk/include/clang/AST/RecordLayout.h Fri Aug 7 14:00:50 2009
@@ -56,6 +56,8 @@
/// PrimaryBase - The primary base for our vtable.
const CXXRecordDecl *PrimaryBase;
+ /// PrimaryBase - Wether or not the primary base was a virtual base.
+ bool PrimaryBaseWasVirtual;
/// BaseOffsets - Contains a map from base classes to their offset.
/// FIXME: Does it make sense to store offsets for virtual base classes
@@ -86,8 +88,9 @@
ASTRecordLayout(uint64_t size, unsigned alignment, uint64_t datasize,
const uint64_t *fieldoffsets, unsigned fieldcount,
uint64_t nonvirtualsize, unsigned nonvirtualalign,
- const CXXRecordDecl *PB, const CXXRecordDecl **bases,
- const uint64_t *baseoffsets, unsigned basecount)
+ const CXXRecordDecl *PB, bool PBVirtual,
+ const CXXRecordDecl **bases, const uint64_t *baseoffsets,
+ unsigned basecount)
: Size(size), DataSize(datasize), FieldOffsets(0), Alignment(alignment),
FieldCount(fieldcount), CXXInfo(new CXXRecordLayoutInfo) {
if (FieldCount > 0) {
@@ -97,6 +100,7 @@
}
CXXInfo->PrimaryBase = PB;
+ CXXInfo->PrimaryBaseWasVirtual = PBVirtual;
CXXInfo->NonVirtualSize = nonvirtualsize;
CXXInfo->NonVirtualAlign = nonvirtualalign;
for (unsigned i = 0; i != basecount; ++i)
@@ -156,6 +160,12 @@
return CXXInfo->PrimaryBase;
}
+ /// getPrimaryBaseWasVirtual - Indicates if the primary base was virtual.
+ bool getPrimaryBaseWasVirtual() const {
+ assert(CXXInfo && "Record layout does not have C++ specific info!");
+
+ return CXXInfo->PrimaryBaseWasVirtual;
+ }
/// getBaseClassOffset - Get the offset, in bits, for the given base class.
uint64_t getBaseClassOffset(const CXXRecordDecl *Base) const {
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=78396&r1=78395&r2=78396&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Fri Aug 7 14:00:50 2009
@@ -30,7 +30,7 @@
// FIXME: audit indirect virtual bases
if (!RD->isPolymorphic() && !RD->getNumVBases()) {
// There is no primary base in this case.
- setPrimaryBase(0);
+ setPrimaryBase(0, false);
return;
}
@@ -103,7 +103,7 @@
const CXXRecordDecl *Base =
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
if (Base->isDynamicClass()) {
- setPrimaryBase(Base);
+ setPrimaryBase(Base, false);
return;
}
}
@@ -116,7 +116,7 @@
// is expensive.
// FIXME: audit indirect virtual bases
if (RD->getNumVBases() == 0) {
- setPrimaryBase(0);
+ setPrimaryBase(0, false);
return;
}
@@ -143,15 +143,15 @@
if (FirstPrimary==0)
FirstPrimary = Base;
if (!IndirectPrimary.count(Base)) {
- setPrimaryBase(Base);
+ setPrimaryBase(Base, true);
return;
}
}
}
- // Otherwise if is the first nearly empty base, if one exists, otherwise
- // there is no primary base class.
- setPrimaryBase(FirstPrimary);
+ // Otherwise if is the first nearly empty virtual base, if one exists,
+ // otherwise there is no primary base class.
+ setPrimaryBase(FirstPrimary, true);
return;
}
@@ -404,6 +404,7 @@
NonVirtualSize,
Builder.NonVirtualAlignment,
Builder.PrimaryBase,
+ Builder.PrimaryBaseWasVirtual,
Builder.Bases.data(),
Builder.BaseOffsets.data(),
Builder.Bases.size());
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.h?rev=78396&r1=78395&r2=78396&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.h (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.h Fri Aug 7 14:00:50 2009
@@ -37,6 +37,7 @@
uint64_t NonVirtualSize;
unsigned NonVirtualAlignment;
const CXXRecordDecl *PrimaryBase;
+ bool PrimaryBaseWasVirtual;
llvm::SmallVector<const CXXRecordDecl *, 4> Bases;
llvm::SmallVector<uint64_t, 4> BaseOffsets;
@@ -54,7 +55,10 @@
void SelectPrimaryBase(const CXXRecordDecl *RD);
void SelectPrimaryForBase(const CXXRecordDecl *RD,
llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary);
- void setPrimaryBase(const CXXRecordDecl *PB) { PrimaryBase = PB; }
+ void setPrimaryBase(const CXXRecordDecl *PB, bool Virtual) {
+ PrimaryBase = PB;
+ PrimaryBaseWasVirtual = Virtual;
+ }
bool IsNearlyEmpty(const CXXRecordDecl *RD);
void LayoutVtable(const CXXRecordDecl *RD);
void LayoutNonVirtualBases(const CXXRecordDecl *RD);
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=78396&r1=78395&r2=78396&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Fri Aug 7 14:00:50 2009
@@ -614,9 +614,11 @@
const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase();
+ const bool PrimaryBaseWasVirtual = Layout.getPrimaryBase();
// The primary base comes first.
- GenerateVtableForBase(PrimaryBase, RD, rtti, methods, true);
+ GenerateVtableForBase(PrimaryBase, RD, rtti, methods, true,
+ PrimaryBaseWasVirtual);
for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
e = RD->bases_end(); i != e; ++i) {
if (i->isVirtual())
Modified: cfe/trunk/test/CodeGenCXX/virt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virt.cpp?rev=78396&r1=78395&r2=78396&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/virt.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/virt.cpp Fri Aug 7 14:00:50 2009
@@ -121,10 +121,10 @@
// CHECK-LP32: .long __ZN1C4bee1Ev
// CHECK-LP32: .long __ZN1C4bee2Ev
-// CHECK-LP32: __ZTV1F:
-// CHECK-LP32 .space 4
+// CHECK-LP32:__ZTV1F:
+// CHECK-LP32: .space 4
// CHECK-LP32 .long 8
-// CHECK-LP32 .space 4
+// CHECK-LP32: .space 4
// CHECK-LP32: .space 4
// CHECK-LP32: .long __ZTI1F
// CHECK-LP32: .long __ZN1D3booEv
@@ -143,9 +143,9 @@
// CHECK-LP32: .long __ZN2D14bar5Ev
// CHECK-LP64: __ZTV1F:
-// CHECK-LP64 .space 8
+// CHECK-LP64: .space 8
// CHECK-LP64 .quad 16
-// CHECK-LP64 .space 8
+// CHECK-LP64: .space 8
// CHECK-LP64: .space 8
// CHECK-LP64: .quad __ZTI1F
// CHECK-LP64: .quad __ZN1D3booEv
More information about the cfe-commits
mailing list