blob: 91a66a3253f44bc8f0682713377ca4515369a72f [file] [log] [blame]
Anders Carlsson79474332009-07-18 20:20:21 +00001//=== ASTRecordLayoutBuilder.cpp - Helper class for building record layouts ==//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "RecordLayoutBuilder.h"
11
12#include "clang/AST/Attr.h"
13#include "clang/AST/Decl.h"
Anders Carlsson6d9f6f32009-07-19 00:18:47 +000014#include "clang/AST/DeclCXX.h"
Anders Carlsson4f516282009-07-18 20:50:59 +000015#include "clang/AST/DeclObjC.h"
Anders Carlsson79474332009-07-18 20:20:21 +000016#include "clang/AST/Expr.h"
17#include "clang/AST/RecordLayout.h"
18#include "clang/Basic/TargetInfo.h"
Mike Stumpd8fe7b22009-08-05 22:37:18 +000019#include <llvm/ADT/SmallSet.h>
Anders Carlsson79474332009-07-18 20:20:21 +000020#include <llvm/Support/MathExtras.h>
21
22using namespace clang;
23
24ASTRecordLayoutBuilder::ASTRecordLayoutBuilder(ASTContext &Ctx)
Anders Carlsson28a5fa22009-08-08 19:38:24 +000025 : Ctx(Ctx), Size(0), Alignment(8), Packed(false), MaxFieldAlignment(0),
26 NextOffset(0), IsUnion(false), NonVirtualSize(0), NonVirtualAlignment(8) {}
Anders Carlsson79474332009-07-18 20:20:21 +000027
Mike Stump25094802009-08-06 00:38:46 +000028/// LayoutVtable - Lay out the vtable and set PrimaryBase.
Mike Stump3dc7eb92009-07-30 00:22:38 +000029void ASTRecordLayoutBuilder::LayoutVtable(const CXXRecordDecl *RD) {
Mike Stumpaa08da72009-08-12 22:06:55 +000030 if (!RD->isDynamicClass()) {
Mike Stump25094802009-08-06 00:38:46 +000031 // There is no primary base in this case.
Mike Stumpc266c6d2009-08-07 19:00:50 +000032 setPrimaryBase(0, false);
Mike Stumpd8fe7b22009-08-05 22:37:18 +000033 return;
Mike Stump25094802009-08-06 00:38:46 +000034 }
Mike Stumpd8fe7b22009-08-05 22:37:18 +000035
36 SelectPrimaryBase(RD);
37 if (PrimaryBase == 0) {
38 int AS = 0;
39 UpdateAlignment(Ctx.Target.getPointerAlign(AS));
40 Size += Ctx.Target.getPointerWidth(AS);
41 NextOffset = Size;
42 }
Mike Stump3dc7eb92009-07-30 00:22:38 +000043}
44
Anders Carlsson6d9f6f32009-07-19 00:18:47 +000045void
46ASTRecordLayoutBuilder::LayoutNonVirtualBases(const CXXRecordDecl *RD) {
Anders Carlsson6d9f6f32009-07-19 00:18:47 +000047 for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
48 e = RD->bases_end(); i != e; ++i) {
49 if (!i->isVirtual()) {
50 const CXXRecordDecl *Base =
Ted Kremenekc23c7e62009-07-29 21:53:49 +000051 cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
Mike Stump25094802009-08-06 00:38:46 +000052 // Skip the PrimaryBase here, as it is laid down first.
53 if (Base != PrimaryBase)
Mike Stump6b2556f2009-08-06 13:41:24 +000054 LayoutBaseNonVirtually(Base);
Anders Carlsson6d9f6f32009-07-19 00:18:47 +000055 }
56 }
57}
58
Mike Stumpd8fe7b22009-08-05 22:37:18 +000059// Helper routines related to the abi definition from:
60// http://www.codesourcery.com/public/cxx-abi/abi.html
61//
62/// IsNearlyEmpty - Indicates when a class has a vtable pointer, but
63/// no other data.
64bool ASTRecordLayoutBuilder::IsNearlyEmpty(const CXXRecordDecl *RD) {
65 // FIXME: Audit the corners
66 if (!RD->isDynamicClass())
67 return false;
68 const ASTRecordLayout &BaseInfo = Ctx.getASTRecordLayout(RD);
69 if (BaseInfo.getNonVirtualSize() == Ctx.Target.getPointerWidth(0))
70 return true;
71 return false;
72}
73
74void ASTRecordLayoutBuilder::SelectPrimaryForBase(const CXXRecordDecl *RD,
75 llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary) {
Mike Stump78696a72009-08-11 04:03:59 +000076 const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
77 const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase();
78 const bool PrimaryBaseWasVirtual = Layout.getPrimaryBaseWasVirtual();
79 if (PrimaryBaseWasVirtual) {
80 IndirectPrimary.insert(PrimaryBase);
81 }
Mike Stumpd8fe7b22009-08-05 22:37:18 +000082 for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
83 e = RD->bases_end(); i != e; ++i) {
Mike Stump78696a72009-08-11 04:03:59 +000084 const CXXRecordDecl *Base =
85 cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
86 // Only bases with virtual bases participate in computing the
87 // indirect primary virtual base classes.
88 // FIXME: audit indirect virtual bases
89 if (Base->getNumVBases() == 0)
90 continue;
91 SelectPrimaryForBase(Base, IndirectPrimary);
Mike Stumpd8fe7b22009-08-05 22:37:18 +000092 }
93}
94
Mike Stump6f3793b2009-08-12 21:50:08 +000095void ASTRecordLayoutBuilder::SelectPrimaryVBase(const CXXRecordDecl *RD,
96 const CXXRecordDecl *&FirstPrimary,
97 llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary) {
98 for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
99 e = RD->bases_end(); i != e; ++i) {
100 const CXXRecordDecl *Base =
101 cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
102 if (!i->isVirtual()) {
103 SelectPrimaryVBase(Base, FirstPrimary, IndirectPrimary);
104 if (PrimaryBase)
105 return;
106 continue;
107 }
108 if (IsNearlyEmpty(Base)) {
109 if (FirstPrimary==0)
110 FirstPrimary = Base;
111 if (!IndirectPrimary.count(Base)) {
112 setPrimaryBase(Base, true);
113 return;
114 }
115 }
116 }
117}
118
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000119/// SelectPrimaryBase - Selects the primary base for the given class and
Mike Stump78696a72009-08-11 04:03:59 +0000120/// record that with setPrimaryBase.
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000121void ASTRecordLayoutBuilder::SelectPrimaryBase(const CXXRecordDecl *RD) {
122 // The primary base is the first non-virtual indirect or direct base class,
123 // if one exists.
124 for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
125 e = RD->bases_end(); i != e; ++i) {
126 if (!i->isVirtual()) {
127 const CXXRecordDecl *Base =
128 cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
129 if (Base->isDynamicClass()) {
Mike Stumpc266c6d2009-08-07 19:00:50 +0000130 setPrimaryBase(Base, false);
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000131 return;
132 }
133 }
134 }
135
Mike Stump6f3793b2009-08-12 21:50:08 +0000136 setPrimaryBase(0, false);
137
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000138 // Otherwise, it is the first nearly empty virtual base that is not an
Mike Stump78696a72009-08-11 04:03:59 +0000139 // indirect primary virtual base class, if one exists.
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000140
141 // If we have no virtual bases at this point, bail out as the searching below
142 // is expensive.
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000143 if (RD->getNumVBases() == 0) {
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000144 return;
145 }
146
Mike Stump78696a72009-08-11 04:03:59 +0000147 // First, we compute all the primary virtual bases for all of our direct and
148 // indirect bases, and record all their primary virtual base classes.
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000149 const CXXRecordDecl *FirstPrimary = 0;
150 llvm::SmallSet<const CXXRecordDecl*, 32> IndirectPrimary;
151 for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
152 e = RD->bases_end(); i != e; ++i) {
Mike Stump78696a72009-08-11 04:03:59 +0000153 const CXXRecordDecl *Base =
154 cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
155 SelectPrimaryForBase(Base, IndirectPrimary);
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000156 }
157
158 // Then we can search for the first nearly empty virtual base itself.
Mike Stump6f3793b2009-08-12 21:50:08 +0000159 SelectPrimaryVBase(RD, FirstPrimary, IndirectPrimary);
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000160
Mike Stumpc266c6d2009-08-07 19:00:50 +0000161 // Otherwise if is the first nearly empty virtual base, if one exists,
162 // otherwise there is no primary base class.
163 setPrimaryBase(FirstPrimary, true);
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000164 return;
165}
166
Mike Stump6b2556f2009-08-06 13:41:24 +0000167void ASTRecordLayoutBuilder::LayoutVirtualBase(const CXXRecordDecl *RD) {
168 LayoutBaseNonVirtually(RD);
169}
170
171void ASTRecordLayoutBuilder::LayoutVirtualBases(const CXXRecordDecl *RD) {
172 // FIXME: audit indirect virtual bases
173 for (CXXRecordDecl::base_class_const_iterator i = RD->vbases_begin(),
174 e = RD->vbases_end(); i != e; ++i) {
175 const CXXRecordDecl *Base =
176 cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
177 if (Base != PrimaryBase)
178 LayoutVirtualBase(Base);
179 }
180}
181
182void ASTRecordLayoutBuilder::LayoutBaseNonVirtually(const CXXRecordDecl *RD) {
Anders Carlsson6d9f6f32009-07-19 00:18:47 +0000183 const ASTRecordLayout &BaseInfo = Ctx.getASTRecordLayout(RD);
184 assert(BaseInfo.getDataSize() > 0 &&
185 "FIXME: Handle empty classes.");
186
Anders Carlssonfc8cfa82009-07-28 19:24:15 +0000187 unsigned BaseAlign = BaseInfo.getNonVirtualAlign();
188 uint64_t BaseSize = BaseInfo.getNonVirtualSize();
Anders Carlsson6d9f6f32009-07-19 00:18:47 +0000189
190 // Round up the current record size to the base's alignment boundary.
191 Size = (Size + (BaseAlign-1)) & ~(BaseAlign-1);
192
Anders Carlssonfc8cfa82009-07-28 19:24:15 +0000193 // Add base class offsets.
194 Bases.push_back(RD);
195 BaseOffsets.push_back(Size);
196
Anders Carlsson6d9f6f32009-07-19 00:18:47 +0000197 // Reserve space for this base.
198 Size += BaseSize;
199
200 // Remember the next available offset.
201 NextOffset = Size;
202
203 // Remember max struct/class alignment.
204 UpdateAlignment(BaseAlign);
205}
206
Anders Carlsson79474332009-07-18 20:20:21 +0000207void ASTRecordLayoutBuilder::Layout(const RecordDecl *D) {
208 IsUnion = D->isUnion();
Anders Carlsson68e0b682009-08-08 18:23:56 +0000209
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000210 Packed = D->hasAttr<PackedAttr>();
211
212 // The #pragma pack attribute specifies the maximum field alignment.
Anders Carlsson68e0b682009-08-08 18:23:56 +0000213 if (const PragmaPackAttr *PPA = D->getAttr<PragmaPackAttr>())
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000214 MaxFieldAlignment = PPA->getAlignment();
Anders Carlsson79474332009-07-18 20:20:21 +0000215
216 if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
217 UpdateAlignment(AA->getAlignment());
Anders Carlsson6d9f6f32009-07-19 00:18:47 +0000218
219 // If this is a C++ class, lay out the nonvirtual bases.
Mike Stump6b2556f2009-08-06 13:41:24 +0000220 const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D);
221 if (RD) {
Mike Stump3dc7eb92009-07-30 00:22:38 +0000222 LayoutVtable(RD);
Mike Stump25094802009-08-06 00:38:46 +0000223 // PrimaryBase goes first.
224 if (PrimaryBase)
Mike Stump6b2556f2009-08-06 13:41:24 +0000225 LayoutBaseNonVirtually(PrimaryBase);
Mike Stump3dc7eb92009-07-30 00:22:38 +0000226 LayoutNonVirtualBases(RD);
Mike Stump3dc7eb92009-07-30 00:22:38 +0000227 }
Anders Carlsson6d9f6f32009-07-19 00:18:47 +0000228
Anders Carlsson118ce162009-07-18 21:48:39 +0000229 LayoutFields(D);
Anders Carlsson79474332009-07-18 20:20:21 +0000230
Anders Carlssonfc8cfa82009-07-28 19:24:15 +0000231 NonVirtualSize = Size;
232 NonVirtualAlignment = Alignment;
Mike Stump3dc7eb92009-07-30 00:22:38 +0000233
Mike Stump6b2556f2009-08-06 13:41:24 +0000234 if (RD)
235 LayoutVirtualBases(RD);
236
Anders Carlsson79474332009-07-18 20:20:21 +0000237 // Finally, round the size of the total struct up to the alignment of the
238 // struct itself.
239 FinishLayout();
240}
241
Anders Carlsson4f516282009-07-18 20:50:59 +0000242void ASTRecordLayoutBuilder::Layout(const ObjCInterfaceDecl *D,
243 const ObjCImplementationDecl *Impl) {
244 if (ObjCInterfaceDecl *SD = D->getSuperClass()) {
245 const ASTRecordLayout &SL = Ctx.getASTObjCInterfaceLayout(SD);
246
247 UpdateAlignment(SL.getAlignment());
248
249 // We start laying out ivars not at the end of the superclass
250 // structure, but at the next byte following the last field.
Anders Carlsson27b50132009-07-18 21:26:44 +0000251 Size = llvm::RoundUpToAlignment(SL.getDataSize(), 8);
Anders Carlsson4f516282009-07-18 20:50:59 +0000252 NextOffset = Size;
253 }
254
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000255 Packed = D->hasAttr<PackedAttr>();
256
257 // The #pragma pack attribute specifies the maximum field alignment.
258 if (const PragmaPackAttr *PPA = D->getAttr<PragmaPackAttr>())
259 MaxFieldAlignment = PPA->getAlignment();
Anders Carlsson4f516282009-07-18 20:50:59 +0000260
261 if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
262 UpdateAlignment(AA->getAlignment());
263
264 // Layout each ivar sequentially.
265 llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
266 Ctx.ShallowCollectObjCIvars(D, Ivars, Impl);
267 for (unsigned i = 0, e = Ivars.size(); i != e; ++i)
268 LayoutField(Ivars[i]);
269
270 // Finally, round the size of the total struct up to the alignment of the
271 // struct itself.
272 FinishLayout();
273}
274
Anders Carlsson118ce162009-07-18 21:48:39 +0000275void ASTRecordLayoutBuilder::LayoutFields(const RecordDecl *D) {
276 // Layout each field, for now, just sequentially, respecting alignment. In
277 // the future, this will need to be tweakable by targets.
278 for (RecordDecl::field_iterator Field = D->field_begin(),
279 FieldEnd = D->field_end(); Field != FieldEnd; ++Field)
280 LayoutField(*Field);
281}
282
Anders Carlsson79474332009-07-18 20:20:21 +0000283void ASTRecordLayoutBuilder::LayoutField(const FieldDecl *D) {
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000284 bool FieldPacked = Packed;
Anders Carlsson79474332009-07-18 20:20:21 +0000285 uint64_t FieldOffset = IsUnion ? 0 : Size;
286 uint64_t FieldSize;
287 unsigned FieldAlign;
288
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000289 FieldPacked |= D->hasAttr<PackedAttr>();
Anders Carlsson79474332009-07-18 20:20:21 +0000290
291 if (const Expr *BitWidthExpr = D->getBitWidth()) {
292 // TODO: Need to check this algorithm on other targets!
293 // (tested on Linux-X86)
294 FieldSize = BitWidthExpr->EvaluateAsInt(Ctx).getZExtValue();
295
296 std::pair<uint64_t, unsigned> FieldInfo = Ctx.getTypeInfo(D->getType());
297 uint64_t TypeSize = FieldInfo.first;
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000298
Anders Carlsson79474332009-07-18 20:20:21 +0000299 FieldAlign = FieldInfo.second;
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000300
301 if (FieldPacked)
302 FieldAlign = 1;
Anders Carlsson79474332009-07-18 20:20:21 +0000303 if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
304 FieldAlign = std::max(FieldAlign, AA->getAlignment());
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000305 // The maximum field alignment overrides the aligned attribute.
306 if (MaxFieldAlignment)
307 FieldAlign = std::min(FieldAlign, MaxFieldAlignment);
308
Anders Carlsson79474332009-07-18 20:20:21 +0000309 // Check if we need to add padding to give the field the correct
310 // alignment.
311 if (FieldSize == 0 || (FieldOffset & (FieldAlign-1)) + FieldSize > TypeSize)
312 FieldOffset = (FieldOffset + (FieldAlign-1)) & ~(FieldAlign-1);
313
314 // Padding members don't affect overall alignment
315 if (!D->getIdentifier())
316 FieldAlign = 1;
317 } else {
318 if (D->getType()->isIncompleteArrayType()) {
319 // This is a flexible array member; we can't directly
320 // query getTypeInfo about these, so we figure it out here.
321 // Flexible array members don't have any size, but they
322 // have to be aligned appropriately for their element type.
323 FieldSize = 0;
324 const ArrayType* ATy = Ctx.getAsArrayType(D->getType());
325 FieldAlign = Ctx.getTypeAlign(ATy->getElementType());
Ted Kremenekc23c7e62009-07-29 21:53:49 +0000326 } else if (const ReferenceType *RT = D->getType()->getAs<ReferenceType>()) {
Anders Carlsson79474332009-07-18 20:20:21 +0000327 unsigned AS = RT->getPointeeType().getAddressSpace();
328 FieldSize = Ctx.Target.getPointerWidth(AS);
329 FieldAlign = Ctx.Target.getPointerAlign(AS);
330 } else {
331 std::pair<uint64_t, unsigned> FieldInfo = Ctx.getTypeInfo(D->getType());
332 FieldSize = FieldInfo.first;
333 FieldAlign = FieldInfo.second;
334 }
335
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000336 if (FieldPacked)
337 FieldAlign = 8;
Anders Carlsson79474332009-07-18 20:20:21 +0000338 if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
339 FieldAlign = std::max(FieldAlign, AA->getAlignment());
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000340 // The maximum field alignment overrides the aligned attribute.
341 if (MaxFieldAlignment)
342 FieldAlign = std::min(FieldAlign, MaxFieldAlignment);
Anders Carlsson79474332009-07-18 20:20:21 +0000343
344 // Round up the current record size to the field's alignment boundary.
345 FieldOffset = (FieldOffset + (FieldAlign-1)) & ~(FieldAlign-1);
346 }
347
348 // Place this field at the current location.
349 FieldOffsets.push_back(FieldOffset);
350
351 // Reserve space for this field.
352 if (IsUnion)
353 Size = std::max(Size, FieldSize);
354 else
355 Size = FieldOffset + FieldSize;
356
357 // Remember the next available offset.
358 NextOffset = Size;
359
360 // Remember max struct/class alignment.
361 UpdateAlignment(FieldAlign);
362}
363
364void ASTRecordLayoutBuilder::FinishLayout() {
365 // In C++, records cannot be of size 0.
366 if (Ctx.getLangOptions().CPlusPlus && Size == 0)
367 Size = 8;
368 // Finally, round the size of the record up to the alignment of the
369 // record itself.
370 Size = (Size + (Alignment-1)) & ~(Alignment-1);
371}
372
373void ASTRecordLayoutBuilder::UpdateAlignment(unsigned NewAlignment) {
374 if (NewAlignment <= Alignment)
375 return;
376
377 assert(llvm::isPowerOf2_32(NewAlignment && "Alignment not a power of 2"));
378
379 Alignment = NewAlignment;
380}
381
382const ASTRecordLayout *
383ASTRecordLayoutBuilder::ComputeLayout(ASTContext &Ctx,
384 const RecordDecl *D) {
385 ASTRecordLayoutBuilder Builder(Ctx);
386
387 Builder.Layout(D);
388
Anders Carlssonfc8cfa82009-07-28 19:24:15 +0000389 if (!isa<CXXRecordDecl>(D))
390 return new ASTRecordLayout(Builder.Size, Builder.Alignment, Builder.Size,
391 Builder.FieldOffsets.data(),
392 Builder.FieldOffsets.size());
Anders Carlsson6d9f6f32009-07-19 00:18:47 +0000393
Anders Carlssonfc8cfa82009-07-28 19:24:15 +0000394 // FIXME: This is not always correct. See the part about bitfields at
395 // http://www.codesourcery.com/public/cxx-abi/abi.html#POD for more info.
396 // FIXME: IsPODForThePurposeOfLayout should be stored in the record layout.
397 bool IsPODForThePurposeOfLayout = cast<CXXRecordDecl>(D)->isPOD();
398
399 assert(Builder.Bases.size() == Builder.BaseOffsets.size() &&
400 "Base offsets vector must be same size as bases vector!");
401
402 // FIXME: This should be done in FinalizeLayout.
Anders Carlsson6d9f6f32009-07-19 00:18:47 +0000403 uint64_t DataSize =
404 IsPODForThePurposeOfLayout ? Builder.Size : Builder.NextOffset;
Anders Carlssonfc8cfa82009-07-28 19:24:15 +0000405 uint64_t NonVirtualSize =
406 IsPODForThePurposeOfLayout ? DataSize : Builder.NonVirtualSize;
Anders Carlsson6d9f6f32009-07-19 00:18:47 +0000407
408 return new ASTRecordLayout(Builder.Size, Builder.Alignment, DataSize,
Anders Carlsson4f516282009-07-18 20:50:59 +0000409 Builder.FieldOffsets.data(),
Anders Carlssonfc8cfa82009-07-28 19:24:15 +0000410 Builder.FieldOffsets.size(),
411 NonVirtualSize,
412 Builder.NonVirtualAlignment,
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000413 Builder.PrimaryBase,
Mike Stumpc266c6d2009-08-07 19:00:50 +0000414 Builder.PrimaryBaseWasVirtual,
Anders Carlssonfc8cfa82009-07-28 19:24:15 +0000415 Builder.Bases.data(),
416 Builder.BaseOffsets.data(),
417 Builder.Bases.size());
Anders Carlsson4f516282009-07-18 20:50:59 +0000418}
419
420const ASTRecordLayout *
421ASTRecordLayoutBuilder::ComputeLayout(ASTContext &Ctx,
422 const ObjCInterfaceDecl *D,
423 const ObjCImplementationDecl *Impl) {
424 ASTRecordLayoutBuilder Builder(Ctx);
425
426 Builder.Layout(D, Impl);
427
428 return new ASTRecordLayout(Builder.Size, Builder.Alignment,
429 Builder.NextOffset,
Anders Carlsson79474332009-07-18 20:20:21 +0000430 Builder.FieldOffsets.data(),
431 Builder.FieldOffsets.size());
432}