diff options
| author | Mike Stump <mrs@apple.com> | 2009-07-30 00:22:38 +0000 |
|---|---|---|
| committer | Mike Stump <mrs@apple.com> | 2009-07-30 00:22:38 +0000 |
| commit | 3dc7eb94403c9de3c5ec2cc0ffd9c4b7f57ba5fb (patch) | |
| tree | 7a35d514fee4bc3d18759ba9d45f15bfea8b0a38 /clang/lib/AST/RecordLayoutBuilder.cpp | |
| parent | 13ddd8514f8a852ac6fbb008e1e0ef4f61cc6270 (diff) | |
| download | bcm5719-llvm-3dc7eb94403c9de3c5ec2cc0ffd9c4b7f57ba5fb.tar.gz bcm5719-llvm-3dc7eb94403c9de3c5ec2cc0ffd9c4b7f57ba5fb.zip | |
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.
llvm-svn: 77556
Diffstat (limited to 'clang/lib/AST/RecordLayoutBuilder.cpp')
| -rw-r--r-- | clang/lib/AST/RecordLayoutBuilder.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp b/clang/lib/AST/RecordLayoutBuilder.cpp index e3581d88d24..a60a72b74fa 100644 --- a/clang/lib/AST/RecordLayoutBuilder.cpp +++ b/clang/lib/AST/RecordLayoutBuilder.cpp @@ -24,11 +24,19 @@ ASTRecordLayoutBuilder::ASTRecordLayoutBuilder(ASTContext &Ctx) : 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 @@ void ASTRecordLayoutBuilder::Layout(const RecordDecl *D) { 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(); |

