blob: 8e09e9e65bbb8f3392af5ba7a7230dfafe639e12 [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 Stumpd8fe7b22009-08-05 22:37:18 +000030 // FIXME: audit indirect virtual bases
Mike Stump25094802009-08-06 00:38:46 +000031 if (!RD->isPolymorphic() && !RD->getNumVBases()) {
32 // There is no primary base in this case.
Mike Stumpc266c6d2009-08-07 19:00:50 +000033 setPrimaryBase(0, false);
Mike Stumpd8fe7b22009-08-05 22:37:18 +000034 return;
Mike Stump25094802009-08-06 00:38:46 +000035 }
Mike Stumpd8fe7b22009-08-05 22:37:18 +000036
37 SelectPrimaryBase(RD);
38 if (PrimaryBase == 0) {
39 int AS = 0;
40 UpdateAlignment(Ctx.Target.getPointerAlign(AS));
41 Size += Ctx.Target.getPointerWidth(AS);
42 NextOffset = Size;
43 }
Mike Stump3dc7eb92009-07-30 00:22:38 +000044}
45
Anders Carlsson6d9f6f32009-07-19 00:18:47 +000046void
47ASTRecordLayoutBuilder::LayoutNonVirtualBases(const CXXRecordDecl *RD) {
Anders Carlsson6d9f6f32009-07-19 00:18:47 +000048 for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
49 e = RD->bases_end(); i != e; ++i) {
50 if (!i->isVirtual()) {
51 const CXXRecordDecl *Base =
Ted Kremenekc23c7e62009-07-29 21:53:49 +000052 cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
Mike Stump25094802009-08-06 00:38:46 +000053 // Skip the PrimaryBase here, as it is laid down first.
54 if (Base != PrimaryBase)
Mike Stump6b2556f2009-08-06 13:41:24 +000055 LayoutBaseNonVirtually(Base);
Anders Carlsson6d9f6f32009-07-19 00:18:47 +000056 }
57 }
58}
59
Mike Stumpd8fe7b22009-08-05 22:37:18 +000060// Helper routines related to the abi definition from:
61// http://www.codesourcery.com/public/cxx-abi/abi.html
62//
63/// IsNearlyEmpty - Indicates when a class has a vtable pointer, but
64/// no other data.
65bool ASTRecordLayoutBuilder::IsNearlyEmpty(const CXXRecordDecl *RD) {
66 // FIXME: Audit the corners
67 if (!RD->isDynamicClass())
68 return false;
69 const ASTRecordLayout &BaseInfo = Ctx.getASTRecordLayout(RD);
70 if (BaseInfo.getNonVirtualSize() == Ctx.Target.getPointerWidth(0))
71 return true;
72 return false;
73}
74
75void ASTRecordLayoutBuilder::SelectPrimaryForBase(const CXXRecordDecl *RD,
76 llvm::SmallSet<const CXXRecordDecl*, 32> &IndirectPrimary) {
Mike Stump78696a72009-08-11 04:03:59 +000077 const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
78 const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase();
79 const bool PrimaryBaseWasVirtual = Layout.getPrimaryBaseWasVirtual();
80 if (PrimaryBaseWasVirtual) {
81 IndirectPrimary.insert(PrimaryBase);
82 }
Mike Stumpd8fe7b22009-08-05 22:37:18 +000083 for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
84 e = RD->bases_end(); i != e; ++i) {
Mike Stump78696a72009-08-11 04:03:59 +000085 const CXXRecordDecl *Base =
86 cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
87 // Only bases with virtual bases participate in computing the
88 // indirect primary virtual base classes.
89 // FIXME: audit indirect virtual bases
90 if (Base->getNumVBases() == 0)
91 continue;
92 SelectPrimaryForBase(Base, IndirectPrimary);
Mike Stumpd8fe7b22009-08-05 22:37:18 +000093 }
94}
95
96/// SelectPrimaryBase - Selects the primary base for the given class and
Mike Stump78696a72009-08-11 04:03:59 +000097/// record that with setPrimaryBase.
Mike Stumpd8fe7b22009-08-05 22:37:18 +000098void ASTRecordLayoutBuilder::SelectPrimaryBase(const CXXRecordDecl *RD) {
99 // The primary base is the first non-virtual indirect or direct base class,
100 // if one exists.
101 for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
102 e = RD->bases_end(); i != e; ++i) {
103 if (!i->isVirtual()) {
104 const CXXRecordDecl *Base =
105 cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
106 if (Base->isDynamicClass()) {
Mike Stumpc266c6d2009-08-07 19:00:50 +0000107 setPrimaryBase(Base, false);
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000108 return;
109 }
110 }
111 }
112
113 // Otherwise, it is the first nearly empty virtual base that is not an
Mike Stump78696a72009-08-11 04:03:59 +0000114 // indirect primary virtual base class, if one exists.
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000115
116 // If we have no virtual bases at this point, bail out as the searching below
117 // is expensive.
118 // FIXME: audit indirect virtual bases
119 if (RD->getNumVBases() == 0) {
Mike Stumpc266c6d2009-08-07 19:00:50 +0000120 setPrimaryBase(0, false);
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000121 return;
122 }
123
Mike Stump78696a72009-08-11 04:03:59 +0000124 // First, we compute all the primary virtual bases for all of our direct and
125 // indirect bases, and record all their primary virtual base classes.
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000126 const CXXRecordDecl *FirstPrimary = 0;
127 llvm::SmallSet<const CXXRecordDecl*, 32> IndirectPrimary;
128 for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
129 e = RD->bases_end(); i != e; ++i) {
Mike Stump78696a72009-08-11 04:03:59 +0000130 const CXXRecordDecl *Base =
131 cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
132 SelectPrimaryForBase(Base, IndirectPrimary);
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000133 }
134
135 // Then we can search for the first nearly empty virtual base itself.
Mike Stump78696a72009-08-11 04:03:59 +0000136 // FIXME: audit indirect virtual bases and order (backwards?)
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000137 for (CXXRecordDecl::base_class_const_iterator i = RD->vbases_begin(),
138 e = RD->vbases_end(); i != e; ++i) {
139 const CXXRecordDecl *Base =
140 cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
141 if (IsNearlyEmpty(Base)) {
142 if (FirstPrimary==0)
143 FirstPrimary = Base;
144 if (!IndirectPrimary.count(Base)) {
Mike Stumpc266c6d2009-08-07 19:00:50 +0000145 setPrimaryBase(Base, true);
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000146 return;
147 }
148 }
149 }
150
Mike Stumpc266c6d2009-08-07 19:00:50 +0000151 // Otherwise if is the first nearly empty virtual base, if one exists,
152 // otherwise there is no primary base class.
153 setPrimaryBase(FirstPrimary, true);
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000154 return;
155}
156
Mike Stump6b2556f2009-08-06 13:41:24 +0000157void ASTRecordLayoutBuilder::LayoutVirtualBase(const CXXRecordDecl *RD) {
158 LayoutBaseNonVirtually(RD);
159}
160
161void ASTRecordLayoutBuilder::LayoutVirtualBases(const CXXRecordDecl *RD) {
162 // FIXME: audit indirect virtual bases
163 for (CXXRecordDecl::base_class_const_iterator i = RD->vbases_begin(),
164 e = RD->vbases_end(); i != e; ++i) {
165 const CXXRecordDecl *Base =
166 cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
167 if (Base != PrimaryBase)
168 LayoutVirtualBase(Base);
169 }
170}
171
172void ASTRecordLayoutBuilder::LayoutBaseNonVirtually(const CXXRecordDecl *RD) {
Anders Carlsson6d9f6f32009-07-19 00:18:47 +0000173 const ASTRecordLayout &BaseInfo = Ctx.getASTRecordLayout(RD);
174 assert(BaseInfo.getDataSize() > 0 &&
175 "FIXME: Handle empty classes.");
176
Anders Carlssonfc8cfa82009-07-28 19:24:15 +0000177 unsigned BaseAlign = BaseInfo.getNonVirtualAlign();
178 uint64_t BaseSize = BaseInfo.getNonVirtualSize();
Anders Carlsson6d9f6f32009-07-19 00:18:47 +0000179
180 // Round up the current record size to the base's alignment boundary.
181 Size = (Size + (BaseAlign-1)) & ~(BaseAlign-1);
182
Anders Carlssonfc8cfa82009-07-28 19:24:15 +0000183 // Add base class offsets.
184 Bases.push_back(RD);
185 BaseOffsets.push_back(Size);
186
Anders Carlsson6d9f6f32009-07-19 00:18:47 +0000187 // Reserve space for this base.
188 Size += BaseSize;
189
190 // Remember the next available offset.
191 NextOffset = Size;
192
193 // Remember max struct/class alignment.
194 UpdateAlignment(BaseAlign);
195}
196
Anders Carlsson79474332009-07-18 20:20:21 +0000197void ASTRecordLayoutBuilder::Layout(const RecordDecl *D) {
198 IsUnion = D->isUnion();
Anders Carlsson68e0b682009-08-08 18:23:56 +0000199
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000200 Packed = D->hasAttr<PackedAttr>();
201
202 // The #pragma pack attribute specifies the maximum field alignment.
Anders Carlsson68e0b682009-08-08 18:23:56 +0000203 if (const PragmaPackAttr *PPA = D->getAttr<PragmaPackAttr>())
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000204 MaxFieldAlignment = PPA->getAlignment();
Anders Carlsson79474332009-07-18 20:20:21 +0000205
206 if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
207 UpdateAlignment(AA->getAlignment());
Anders Carlsson6d9f6f32009-07-19 00:18:47 +0000208
209 // If this is a C++ class, lay out the nonvirtual bases.
Mike Stump6b2556f2009-08-06 13:41:24 +0000210 const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D);
211 if (RD) {
Mike Stump3dc7eb92009-07-30 00:22:38 +0000212 LayoutVtable(RD);
Mike Stump25094802009-08-06 00:38:46 +0000213 // PrimaryBase goes first.
214 if (PrimaryBase)
Mike Stump6b2556f2009-08-06 13:41:24 +0000215 LayoutBaseNonVirtually(PrimaryBase);
Mike Stump3dc7eb92009-07-30 00:22:38 +0000216 LayoutNonVirtualBases(RD);
Mike Stump3dc7eb92009-07-30 00:22:38 +0000217 }
Anders Carlsson6d9f6f32009-07-19 00:18:47 +0000218
Anders Carlsson118ce162009-07-18 21:48:39 +0000219 LayoutFields(D);
Anders Carlsson79474332009-07-18 20:20:21 +0000220
Anders Carlssonfc8cfa82009-07-28 19:24:15 +0000221 NonVirtualSize = Size;
222 NonVirtualAlignment = Alignment;
Mike Stump3dc7eb92009-07-30 00:22:38 +0000223
Mike Stump6b2556f2009-08-06 13:41:24 +0000224 if (RD)
225 LayoutVirtualBases(RD);
226
Anders Carlsson79474332009-07-18 20:20:21 +0000227 // Finally, round the size of the total struct up to the alignment of the
228 // struct itself.
229 FinishLayout();
230}
231
Anders Carlsson4f516282009-07-18 20:50:59 +0000232void ASTRecordLayoutBuilder::Layout(const ObjCInterfaceDecl *D,
233 const ObjCImplementationDecl *Impl) {
234 if (ObjCInterfaceDecl *SD = D->getSuperClass()) {
235 const ASTRecordLayout &SL = Ctx.getASTObjCInterfaceLayout(SD);
236
237 UpdateAlignment(SL.getAlignment());
238
239 // We start laying out ivars not at the end of the superclass
240 // structure, but at the next byte following the last field.
Anders Carlsson27b50132009-07-18 21:26:44 +0000241 Size = llvm::RoundUpToAlignment(SL.getDataSize(), 8);
Anders Carlsson4f516282009-07-18 20:50:59 +0000242 NextOffset = Size;
243 }
244
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000245 Packed = D->hasAttr<PackedAttr>();
246
247 // The #pragma pack attribute specifies the maximum field alignment.
248 if (const PragmaPackAttr *PPA = D->getAttr<PragmaPackAttr>())
249 MaxFieldAlignment = PPA->getAlignment();
Anders Carlsson4f516282009-07-18 20:50:59 +0000250
251 if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
252 UpdateAlignment(AA->getAlignment());
253
254 // Layout each ivar sequentially.
255 llvm::SmallVector<ObjCIvarDecl*, 16> Ivars;
256 Ctx.ShallowCollectObjCIvars(D, Ivars, Impl);
257 for (unsigned i = 0, e = Ivars.size(); i != e; ++i)
258 LayoutField(Ivars[i]);
259
260 // Finally, round the size of the total struct up to the alignment of the
261 // struct itself.
262 FinishLayout();
263}
264
Anders Carlsson118ce162009-07-18 21:48:39 +0000265void ASTRecordLayoutBuilder::LayoutFields(const RecordDecl *D) {
266 // Layout each field, for now, just sequentially, respecting alignment. In
267 // the future, this will need to be tweakable by targets.
268 for (RecordDecl::field_iterator Field = D->field_begin(),
269 FieldEnd = D->field_end(); Field != FieldEnd; ++Field)
270 LayoutField(*Field);
271}
272
Anders Carlsson79474332009-07-18 20:20:21 +0000273void ASTRecordLayoutBuilder::LayoutField(const FieldDecl *D) {
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000274 bool FieldPacked = Packed;
Anders Carlsson79474332009-07-18 20:20:21 +0000275 uint64_t FieldOffset = IsUnion ? 0 : Size;
276 uint64_t FieldSize;
277 unsigned FieldAlign;
278
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000279 FieldPacked |= D->hasAttr<PackedAttr>();
Anders Carlsson79474332009-07-18 20:20:21 +0000280
281 if (const Expr *BitWidthExpr = D->getBitWidth()) {
282 // TODO: Need to check this algorithm on other targets!
283 // (tested on Linux-X86)
284 FieldSize = BitWidthExpr->EvaluateAsInt(Ctx).getZExtValue();
285
286 std::pair<uint64_t, unsigned> FieldInfo = Ctx.getTypeInfo(D->getType());
287 uint64_t TypeSize = FieldInfo.first;
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000288
Anders Carlsson79474332009-07-18 20:20:21 +0000289 FieldAlign = FieldInfo.second;
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000290
291 if (FieldPacked)
292 FieldAlign = 1;
Anders Carlsson79474332009-07-18 20:20:21 +0000293 if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
294 FieldAlign = std::max(FieldAlign, AA->getAlignment());
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000295 // The maximum field alignment overrides the aligned attribute.
296 if (MaxFieldAlignment)
297 FieldAlign = std::min(FieldAlign, MaxFieldAlignment);
298
Anders Carlsson79474332009-07-18 20:20:21 +0000299 // Check if we need to add padding to give the field the correct
300 // alignment.
301 if (FieldSize == 0 || (FieldOffset & (FieldAlign-1)) + FieldSize > TypeSize)
302 FieldOffset = (FieldOffset + (FieldAlign-1)) & ~(FieldAlign-1);
303
304 // Padding members don't affect overall alignment
305 if (!D->getIdentifier())
306 FieldAlign = 1;
307 } else {
308 if (D->getType()->isIncompleteArrayType()) {
309 // This is a flexible array member; we can't directly
310 // query getTypeInfo about these, so we figure it out here.
311 // Flexible array members don't have any size, but they
312 // have to be aligned appropriately for their element type.
313 FieldSize = 0;
314 const ArrayType* ATy = Ctx.getAsArrayType(D->getType());
315 FieldAlign = Ctx.getTypeAlign(ATy->getElementType());
Ted Kremenekc23c7e62009-07-29 21:53:49 +0000316 } else if (const ReferenceType *RT = D->getType()->getAs<ReferenceType>()) {
Anders Carlsson79474332009-07-18 20:20:21 +0000317 unsigned AS = RT->getPointeeType().getAddressSpace();
318 FieldSize = Ctx.Target.getPointerWidth(AS);
319 FieldAlign = Ctx.Target.getPointerAlign(AS);
320 } else {
321 std::pair<uint64_t, unsigned> FieldInfo = Ctx.getTypeInfo(D->getType());
322 FieldSize = FieldInfo.first;
323 FieldAlign = FieldInfo.second;
324 }
325
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000326 if (FieldPacked)
327 FieldAlign = 8;
Anders Carlsson79474332009-07-18 20:20:21 +0000328 if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
329 FieldAlign = std::max(FieldAlign, AA->getAlignment());
Anders Carlsson28a5fa22009-08-08 19:38:24 +0000330 // The maximum field alignment overrides the aligned attribute.
331 if (MaxFieldAlignment)
332 FieldAlign = std::min(FieldAlign, MaxFieldAlignment);
Anders Carlsson79474332009-07-18 20:20:21 +0000333
334 // Round up the current record size to the field's alignment boundary.
335 FieldOffset = (FieldOffset + (FieldAlign-1)) & ~(FieldAlign-1);
336 }
337
338 // Place this field at the current location.
339 FieldOffsets.push_back(FieldOffset);
340
341 // Reserve space for this field.
342 if (IsUnion)
343 Size = std::max(Size, FieldSize);
344 else
345 Size = FieldOffset + FieldSize;
346
347 // Remember the next available offset.
348 NextOffset = Size;
349
350 // Remember max struct/class alignment.
351 UpdateAlignment(FieldAlign);
352}
353
354void ASTRecordLayoutBuilder::FinishLayout() {
355 // In C++, records cannot be of size 0.
356 if (Ctx.getLangOptions().CPlusPlus && Size == 0)
357 Size = 8;
358 // Finally, round the size of the record up to the alignment of the
359 // record itself.
360 Size = (Size + (Alignment-1)) & ~(Alignment-1);
361}
362
363void ASTRecordLayoutBuilder::UpdateAlignment(unsigned NewAlignment) {
364 if (NewAlignment <= Alignment)
365 return;
366
367 assert(llvm::isPowerOf2_32(NewAlignment && "Alignment not a power of 2"));
368
369 Alignment = NewAlignment;
370}
371
372const ASTRecordLayout *
373ASTRecordLayoutBuilder::ComputeLayout(ASTContext &Ctx,
374 const RecordDecl *D) {
375 ASTRecordLayoutBuilder Builder(Ctx);
376
377 Builder.Layout(D);
378
Anders Carlssonfc8cfa82009-07-28 19:24:15 +0000379 if (!isa<CXXRecordDecl>(D))
380 return new ASTRecordLayout(Builder.Size, Builder.Alignment, Builder.Size,
381 Builder.FieldOffsets.data(),
382 Builder.FieldOffsets.size());
Anders Carlsson6d9f6f32009-07-19 00:18:47 +0000383
Anders Carlssonfc8cfa82009-07-28 19:24:15 +0000384 // FIXME: This is not always correct. See the part about bitfields at
385 // http://www.codesourcery.com/public/cxx-abi/abi.html#POD for more info.
386 // FIXME: IsPODForThePurposeOfLayout should be stored in the record layout.
387 bool IsPODForThePurposeOfLayout = cast<CXXRecordDecl>(D)->isPOD();
388
389 assert(Builder.Bases.size() == Builder.BaseOffsets.size() &&
390 "Base offsets vector must be same size as bases vector!");
391
392 // FIXME: This should be done in FinalizeLayout.
Anders Carlsson6d9f6f32009-07-19 00:18:47 +0000393 uint64_t DataSize =
394 IsPODForThePurposeOfLayout ? Builder.Size : Builder.NextOffset;
Anders Carlssonfc8cfa82009-07-28 19:24:15 +0000395 uint64_t NonVirtualSize =
396 IsPODForThePurposeOfLayout ? DataSize : Builder.NonVirtualSize;
Anders Carlsson6d9f6f32009-07-19 00:18:47 +0000397
398 return new ASTRecordLayout(Builder.Size, Builder.Alignment, DataSize,
Anders Carlsson4f516282009-07-18 20:50:59 +0000399 Builder.FieldOffsets.data(),
Anders Carlssonfc8cfa82009-07-28 19:24:15 +0000400 Builder.FieldOffsets.size(),
401 NonVirtualSize,
402 Builder.NonVirtualAlignment,
Mike Stumpd8fe7b22009-08-05 22:37:18 +0000403 Builder.PrimaryBase,
Mike Stumpc266c6d2009-08-07 19:00:50 +0000404 Builder.PrimaryBaseWasVirtual,
Anders Carlssonfc8cfa82009-07-28 19:24:15 +0000405 Builder.Bases.data(),
406 Builder.BaseOffsets.data(),
407 Builder.Bases.size());
Anders Carlsson4f516282009-07-18 20:50:59 +0000408}
409
410const ASTRecordLayout *
411ASTRecordLayoutBuilder::ComputeLayout(ASTContext &Ctx,
412 const ObjCInterfaceDecl *D,
413 const ObjCImplementationDecl *Impl) {
414 ASTRecordLayoutBuilder Builder(Ctx);
415
416 Builder.Layout(D, Impl);
417
418 return new ASTRecordLayout(Builder.Size, Builder.Alignment,
419 Builder.NextOffset,
Anders Carlsson79474332009-07-18 20:20:21 +0000420 Builder.FieldOffsets.data(),
421 Builder.FieldOffsets.size());
422}