[cfe-commits] r77556 - in /cfe/trunk: lib/AST/RecordLayoutBuilder.cpp lib/AST/RecordLayoutBuilder.h lib/CodeGen/CodeGenTypes.cpp test/CodeGenCXX/virt.cpp
Mike Stump
mrs at apple.com
Wed Jul 29 17:22:38 PDT 2009
Author: mrs
Date: Wed Jul 29 19:22:38 2009
New Revision: 77556
URL: http://llvm.org/viewvc/llvm-project?rev=77556&view=rev
Log:
Add ability to layout the vtable pointer in trivial cases. I noticed
that we would silently do bad things with virtual bases in the layout
code, so, we just turn them off. When people do better things with
them, we can turn them back on.
Added:
cfe/trunk/test/CodeGenCXX/virt.cpp
Modified:
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
cfe/trunk/lib/AST/RecordLayoutBuilder.h
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=77556&r1=77555&r2=77556&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Wed Jul 29 19:22:38 2009
@@ -24,11 +24,19 @@
: Ctx(Ctx), Size(0), Alignment(8), StructPacking(0), NextOffset(0),
IsUnion(false), NonVirtualSize(0), NonVirtualAlignment(8) {}
+void ASTRecordLayoutBuilder::LayoutVtable(const CXXRecordDecl *RD) {
+ if (RD->isPolymorphic())
+ {
+ assert (RD->getNumBases() == 0 && "no polymorphic inheritance yet");
+ int AS = 0;
+ UpdateAlignment(Ctx.Target.getPointerAlign(AS));
+ Size += Ctx.Target.getPointerWidth(AS);
+ NextOffset = Size;
+ }
+}
+
void
ASTRecordLayoutBuilder::LayoutNonVirtualBases(const CXXRecordDecl *RD) {
- assert(!RD->isPolymorphic() &&
- "FIXME: We don't support polymorphic classes yet!");
-
for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
e = RD->bases_end(); i != e; ++i) {
if (!i->isVirtual()) {
@@ -74,14 +82,20 @@
UpdateAlignment(AA->getAlignment());
// If this is a C++ class, lay out the nonvirtual bases.
- if (Ctx.getLangOptions().CPlusPlus)
- LayoutNonVirtualBases(cast<CXXRecordDecl>(D));
+ if (Ctx.getLangOptions().CPlusPlus) {
+ const CXXRecordDecl *RD = cast<CXXRecordDecl>(D);
+ LayoutVtable(RD);
+ LayoutNonVirtualBases(RD);
+
+ assert (RD->getNumVBases() == 0
+ && "FIXME: We don't support virtual bases yet!");
+ }
LayoutFields(D);
NonVirtualSize = Size;
NonVirtualAlignment = Alignment;
-
+
// Finally, round the size of the total struct up to the alignment of the
// struct itself.
FinishLayout();
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.h?rev=77556&r1=77555&r2=77556&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.h (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.h Wed Jul 29 19:22:38 2009
@@ -48,6 +48,7 @@
void LayoutFields(const RecordDecl *D);
void LayoutField(const FieldDecl *D);
+ void LayoutVtable(const CXXRecordDecl *RD);
void LayoutNonVirtualBases(const CXXRecordDecl *RD);
void LayoutNonVirtualBase(const CXXRecordDecl *RD);
Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=77556&r1=77555&r2=77556&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Wed Jul 29 19:22:38 2009
@@ -381,8 +381,6 @@
// FIXME. This may have to move to a better place.
if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(TD)) {
- assert(!RD->isPolymorphic() &&
- "FIXME: We don't support polymorphic classes yet!");
for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
e = RD->bases_end(); i != e; ++i) {
if (!i->isVirtual()) {
Added: cfe/trunk/test/CodeGenCXX/virt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/virt.cpp?rev=77556&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/virt.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/virt.cpp Wed Jul 29 19:22:38 2009
@@ -0,0 +1,8 @@
+// RUN: clang-cc %s -emit-llvm -o - -std=c++0x
+
+class A {
+public:
+ virtual void foo();
+};
+
+static_assert (sizeof (A) == (sizeof(void *)), "vtable pointer layout");
More information about the cfe-commits
mailing list