Coverage Report

Created: 2020-09-19 12:23

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- CGRecordLayoutBuilder.cpp - CGRecordLayout builder  ----*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// Builder implementation for CGRecordLayout objects.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "CGRecordLayout.h"
14
#include "CGCXXABI.h"
15
#include "CodeGenTypes.h"
16
#include "clang/AST/ASTContext.h"
17
#include "clang/AST/Attr.h"
18
#include "clang/AST/CXXInheritance.h"
19
#include "clang/AST/DeclCXX.h"
20
#include "clang/AST/Expr.h"
21
#include "clang/AST/RecordLayout.h"
22
#include "clang/Basic/CodeGenOptions.h"
23
#include "llvm/IR/DataLayout.h"
24
#include "llvm/IR/DerivedTypes.h"
25
#include "llvm/IR/Type.h"
26
#include "llvm/Support/Debug.h"
27
#include "llvm/Support/MathExtras.h"
28
#include "llvm/Support/raw_ostream.h"
29
using namespace clang;
30
using namespace CodeGen;
31
32
namespace {
33
/// The CGRecordLowering is responsible for lowering an ASTRecordLayout to an
34
/// llvm::Type.  Some of the lowering is straightforward, some is not.  Here we
35
/// detail some of the complexities and weirdnesses here.
36
/// * LLVM does not have unions - Unions can, in theory be represented by any
37
///   llvm::Type with correct size.  We choose a field via a specific heuristic
38
///   and add padding if necessary.
39
/// * LLVM does not have bitfields - Bitfields are collected into contiguous
40
///   runs and allocated as a single storage type for the run.  ASTRecordLayout
41
///   contains enough information to determine where the runs break.  Microsoft
42
///   and Itanium follow different rules and use different codepaths.
43
/// * It is desired that, when possible, bitfields use the appropriate iN type
44
///   when lowered to llvm types.  For example unsigned x : 24 gets lowered to
45
///   i24.  This isn't always possible because i24 has storage size of 32 bit
46
///   and if it is possible to use that extra byte of padding we must use
47
///   [i8 x 3] instead of i24.  The function clipTailPadding does this.
48
///   C++ examples that require clipping:
49
///   struct { int a : 24; char b; }; // a must be clipped, b goes at offset 3
50
///   struct A { int a : 24; }; // a must be clipped because a struct like B
51
//    could exist: struct B : A { char b; }; // b goes at offset 3
52
/// * Clang ignores 0 sized bitfields and 0 sized bases but *not* zero sized
53
///   fields.  The existing asserts suggest that LLVM assumes that *every* field
54
///   has an underlying storage type.  Therefore empty structures containing
55
///   zero sized subobjects such as empty records or zero sized arrays still get
56
///   a zero sized (empty struct) storage type.
57
/// * Clang reads the complete type rather than the base type when generating
58
///   code to access fields.  Bitfields in tail position with tail padding may
59
///   be clipped in the base class but not the complete class (we may discover
60
///   that the tail padding is not used in the complete class.) However,
61
///   because LLVM reads from the complete type it can generate incorrect code
62
///   if we do not clip the tail padding off of the bitfield in the complete
63
///   layout.  This introduces a somewhat awkward extra unnecessary clip stage.
64
///   The location of the clip is stored internally as a sentinel of type
65
///   SCISSOR.  If LLVM were updated to read base types (which it probably
66
///   should because locations of things such as VBases are bogus in the llvm
67
///   type anyway) then we could eliminate the SCISSOR.
68
/// * Itanium allows nearly empty primary virtual bases.  These bases don't get
69
///   get their own storage because they're laid out as part of another base
70
///   or at the beginning of the structure.  Determining if a VBase actually
71
///   gets storage awkwardly involves a walk of all bases.
72
/// * VFPtrs and VBPtrs do *not* make a record NotZeroInitializable.
73
struct CGRecordLowering {
74
  // MemberInfo is a helper structure that contains information about a record
75
  // member.  In additional to the standard member types, there exists a
76
  // sentinel member type that ensures correct rounding.
77
  struct MemberInfo {
78
    CharUnits Offset;
79
    enum InfoKind { VFPtr, VBPtr, Field, Base, VBase, Scissor } Kind;
80
    llvm::Type *Data;
81
    union {
82
      const FieldDecl *FD;
83
      const CXXRecordDecl *RD;
84
    };
85
    MemberInfo(CharUnits Offset, InfoKind Kind, llvm::Type *Data,
86
               const FieldDecl *FD = nullptr)
87
272k
      : Offset(Offset), Kind(Kind), Data(Data), FD(FD) {}
88
    MemberInfo(CharUnits Offset, InfoKind Kind, llvm::Type *Data,
89
               const CXXRecordDecl *RD)
90
60.5k
      : Offset(Offset), Kind(Kind), Data(Data), RD(RD) {}
91
    // MemberInfos are sorted so we define a < operator.
92
183k
    bool operator <(const MemberInfo& a) const { return Offset < a.Offset; }
93
  };
94
  // The constructor.
95
  CGRecordLowering(CodeGenTypes &Types, const RecordDecl *D, bool Packed);
96
  // Short helper routines.
97
  /// Constructs a MemberInfo instance from an offset and llvm::Type *.
98
87.6k
  MemberInfo StorageInfo(CharUnits Offset, llvm::Type *Data) {
99
87.6k
    return MemberInfo(Offset, MemberInfo::Field, Data);
100
87.6k
  }
101
102
  /// The Microsoft bitfield layout rule allocates discrete storage
103
  /// units of the field's formal type and only combines adjacent
104
  /// fields of the same formal type.  We want to emit a layout with
105
  /// these discrete storage units instead of combining them into a
106
  /// continuous run.
107
1.80k
  bool isDiscreteBitFieldABI() {
108
1.80k
    return Context.getTargetInfo().getCXXABI().isMicrosoft() ||
109
1.79k
           D->isMsStruct(Context);
110
1.80k
  }
111
112
  /// The Itanium base layout rule allows virtual bases to overlap
113
  /// other bases, which complicates layout in specific ways.
114
  ///
115
  /// Note specifically that the ms_struct attribute doesn't change this.
116
50.9k
  bool isOverlappingVBaseABI() {
117
50.9k
    return !Context.getTargetInfo().getCXXABI().isMicrosoft();
118
50.9k
  }
119
120
  /// Wraps llvm::Type::getIntNTy with some implicit arguments.
121
168k
  llvm::Type *getIntNType(uint64_t NumBits) {
122
168k
    return llvm::Type::getIntNTy(Types.getLLVMContext(),
123
168k
                                 (unsigned)llvm::alignTo(NumBits, 8));
124
168k
  }
125
  /// Gets an llvm type of size NumBytes and alignment 1.
126
17.6k
  llvm::Type *getByteArrayType(CharUnits NumBytes) {
127
17.6k
    assert(!NumBytes.isZero() && "Empty byte arrays aren't allowed.");
128
17.6k
    llvm::Type *Type = llvm::Type::getInt8Ty(Types.getLLVMContext());
129
14.9k
    return NumBytes == CharUnits::One() ? Type :
130
2.65k
        (llvm::Type *)llvm::ArrayType::get(Type, NumBytes.getQuantity());
131
17.6k
  }
132
  /// Gets the storage type for a field decl and handles storage
133
  /// for itanium bitfields that are smaller than their declared type.
134
178k
  llvm::Type *getStorageType(const FieldDecl *FD) {
135
178k
    llvm::Type *Type = Types.ConvertTypeForMem(FD->getType());
136
178k
    if (!FD->isBitField()) 
return Type178k
;
137
86
    if (isDiscreteBitFieldABI()) 
return Type10
;
138
76
    return getIntNType(std::min(FD->getBitWidthValue(Context),
139
76
                             (unsigned)Context.toBits(getSize(Type))));
140
76
  }
141
  /// Gets the llvm Basesubobject type from a CXXRecordDecl.
142
10.5k
  llvm::Type *getStorageType(const CXXRecordDecl *RD) {
143
10.5k
    return Types.getCGRecordLayout(RD).getBaseSubobjectLLVMType();
144
10.5k
  }
145
182k
  CharUnits bitsToCharUnits(uint64_t BitOffset) {
146
182k
    return Context.toCharUnitsFromBits(BitOffset);
147
182k
  }
148
605k
  CharUnits getSize(llvm::Type *Type) {
149
605k
    return CharUnits::fromQuantity(DataLayout.getTypeAllocSize(Type));
150
605k
  }
151
928k
  CharUnits getAlignment(llvm::Type *Type) {
152
928k
    return CharUnits::fromQuantity(DataLayout.getABITypeAlignment(Type));
153
928k
  }
154
182k
  bool isZeroInitializable(const FieldDecl *FD) {
155
182k
    return Types.isZeroInitializable(FD->getType());
156
182k
  }
157
10.7k
  bool isZeroInitializable(const RecordDecl *RD) {
158
10.7k
    return Types.isZeroInitializable(RD);
159
10.7k
  }
160
23.6k
  void appendPaddingBytes(CharUnits Size) {
161
23.6k
    if (!Size.isZero())
162
14.9k
      FieldTypes.push_back(getByteArrayType(Size));
163
23.6k
  }
164
186k
  uint64_t getFieldBitOffset(const FieldDecl *FD) {
165
186k
    return Layout.getFieldOffset(FD->getFieldIndex());
166
186k
  }
167
  // Layout routines.
168
  void setBitFieldInfo(const FieldDecl *FD, CharUnits StartOffset,
169
                       llvm::Type *StorageType);
170
  /// Lowers an ASTRecordLayout to a llvm type.
171
  void lower(bool NonVirtualBaseType);
172
  void lowerUnion();
173
  void accumulateFields();
174
  void accumulateBitFields(RecordDecl::field_iterator Field,
175
                        RecordDecl::field_iterator FieldEnd);
176
  void accumulateBases();
177
  void accumulateVPtrs();
178
  void accumulateVBases();
179
  /// Recursively searches all of the bases to find out if a vbase is
180
  /// not the primary vbase of some base class.
181
  bool hasOwnStorage(const CXXRecordDecl *Decl, const CXXRecordDecl *Query);
182
  void calculateZeroInit();
183
  /// Lowers bitfield storage types to I8 arrays for bitfields with tail
184
  /// padding that is or can potentially be used.
185
  void clipTailPadding();
186
  /// Determines if we need a packed llvm struct.
187
  void determinePacked(bool NVBaseType);
188
  /// Inserts padding everywhere it's needed.
189
  void insertPadding();
190
  /// Fills out the structures that are ultimately consumed.
191
  void fillOutputFields();
192
  // Input memoization fields.
193
  CodeGenTypes &Types;
194
  const ASTContext &Context;
195
  const RecordDecl *D;
196
  const CXXRecordDecl *RD;
197
  const ASTRecordLayout &Layout;
198
  const llvm::DataLayout &DataLayout;
199
  // Helpful intermediate data-structures.
200
  std::vector<MemberInfo> Members;
201
  // Output fields, consumed by CodeGenTypes::ComputeRecordLayout.
202
  SmallVector<llvm::Type *, 16> FieldTypes;
203
  llvm::DenseMap<const FieldDecl *, unsigned> Fields;
204
  llvm::DenseMap<const FieldDecl *, CGBitFieldInfo> BitFields;
205
  llvm::DenseMap<const CXXRecordDecl *, unsigned> NonVirtualBases;
206
  llvm::DenseMap<const CXXRecordDecl *, unsigned> VirtualBases;
207
  bool IsZeroInitializable : 1;
208
  bool IsZeroInitializableAsBase : 1;
209
  bool Packed : 1;
210
private:
211
  CGRecordLowering(const CGRecordLowering &) = delete;
212
  void operator =(const CGRecordLowering &) = delete;
213
};
214
} // namespace {
215
216
CGRecordLowering::CGRecordLowering(CodeGenTypes &Types, const RecordDecl *D,
217
                                   bool Packed)
218
    : Types(Types), Context(Types.getContext()), D(D),
219
      RD(dyn_cast<CXXRecordDecl>(D)),
220
      Layout(Types.getContext().getASTRecordLayout(D)),
221
      DataLayout(Types.getDataLayout()), IsZeroInitializable(true),
222
107k
      IsZeroInitializableAsBase(true), Packed(Packed) {}
223
224
void CGRecordLowering::setBitFieldInfo(
225
6.37k
    const FieldDecl *FD, CharUnits StartOffset, llvm::Type *StorageType) {
226
6.37k
  CGBitFieldInfo &Info = BitFields[FD->getCanonicalDecl()];
227
6.37k
  Info.IsSigned = FD->getType()->isSignedIntegerOrEnumerationType();
228
6.37k
  Info.Offset = (unsigned)(getFieldBitOffset(FD) - Context.toBits(StartOffset));
229
6.37k
  Info.Size = FD->getBitWidthValue(Context);
230
6.37k
  Info.StorageSize = (unsigned)DataLayout.getTypeAllocSizeInBits(StorageType);
231
6.37k
  Info.StorageOffset = StartOffset;
232
6.37k
  if (Info.Size > Info.StorageSize)
233
9
    Info.Size = Info.StorageSize;
234
  // Reverse the bit offsets for big endian machines. Because we represent
235
  // a bitfield as a single large integer load, we can imagine the bits
236
  // counting from the most-significant-bit instead of the
237
  // least-significant-bit.
238
6.37k
  if (DataLayout.isBigEndian())
239
209
    Info.Offset = Info.StorageSize - (Info.Offset + Info.Size);
240
6.37k
}
241
242
107k
void CGRecordLowering::lower(bool NVBaseType) {
243
  // The lowering process implemented in this function takes a variety of
244
  // carefully ordered phases.
245
  // 1) Store all members (fields and bases) in a list and sort them by offset.
246
  // 2) Add a 1-byte capstone member at the Size of the structure.
247
  // 3) Clip bitfield storages members if their tail padding is or might be
248
  //    used by another field or base.  The clipping process uses the capstone
249
  //    by treating it as another object that occurs after the record.
250
  // 4) Determine if the llvm-struct requires packing.  It's important that this
251
  //    phase occur after clipping, because clipping changes the llvm type.
252
  //    This phase reads the offset of the capstone when determining packedness
253
  //    and updates the alignment of the capstone to be equal of the alignment
254
  //    of the record after doing so.
255
  // 5) Insert padding everywhere it is needed.  This phase requires 'Packed' to
256
  //    have been computed and needs to know the alignment of the record in
257
  //    order to understand if explicit tail padding is needed.
258
  // 6) Remove the capstone, we don't need it anymore.
259
  // 7) Determine if this record can be zero-initialized.  This phase could have
260
  //    been placed anywhere after phase 1.
261
  // 8) Format the complete list of members in a way that can be consumed by
262
  //    CodeGenTypes::ComputeRecordLayout.
263
99.5k
  CharUnits Size = NVBaseType ? 
Layout.getNonVirtualSize()7.55k
: Layout.getSize();
264
107k
  if (D->isUnion())
265
2.43k
    return lowerUnion();
266
104k
  accumulateFields();
267
  // RD implies C++.
268
104k
  if (RD) {
269
73.2k
    accumulateVPtrs();
270
73.2k
    accumulateBases();
271
73.2k
    if (Members.empty())
272
21.2k
      return appendPaddingBytes(Size);
273
52.0k
    if (!NVBaseType)
274
49.7k
      accumulateVBases();
275
52.0k
  }
276
83.4k
  llvm::stable_sort(Members);
277
83.4k
  Members.push_back(StorageInfo(Size, getIntNType(8)));
278
83.4k
  clipTailPadding();
279
83.4k
  determinePacked(NVBaseType);
280
83.4k
  insertPadding();
281
83.4k
  Members.pop_back();
282
83.4k
  calculateZeroInit();
283
83.4k
  fillOutputFields();
284
83.4k
}
285
286
2.43k
void CGRecordLowering::lowerUnion() {
287
2.43k
  CharUnits LayoutSize = Layout.getSize();
288
2.43k
  llvm::Type *StorageType = nullptr;
289
2.43k
  bool SeenNamedMember = false;
290
  // Iterate through the fields setting bitFieldInfo and the Fields array. Also
291
  // locate the "most appropriate" storage type.  The heuristic for finding the
292
  // storage type isn't necessary, the first (non-0-length-bitfield) field's
293
  // type would work fine and be simpler but would be different than what we've
294
  // been doing and cause lit tests to change.
295
4.93k
  for (const auto *Field : D->fields()) {
296
4.93k
    if (Field->isBitField()) {
297
47
      if (Field->isZeroLengthBitField(Context))
298
4
        continue;
299
43
      llvm::Type *FieldType = getStorageType(Field);
300
43
      if (LayoutSize < getSize(FieldType))
301
1
        FieldType = getByteArrayType(LayoutSize);
302
43
      setBitFieldInfo(Field, CharUnits::Zero(), FieldType);
303
43
    }
304
4.93k
    Fields[Field->getCanonicalDecl()] = 0;
305
4.93k
    llvm::Type *FieldType = getStorageType(Field);
306
    // Compute zero-initializable status.
307
    // This union might not be zero initialized: it may contain a pointer to
308
    // data member which might have some exotic initialization sequence.
309
    // If this is the case, then we aught not to try and come up with a "better"
310
    // type, it might not be very easy to come up with a Constant which
311
    // correctly initializes it.
312
4.93k
    if (!SeenNamedMember) {
313
2.75k
      SeenNamedMember = Field->getIdentifier();
314
2.75k
      if (!SeenNamedMember)
315
719
        if (const auto *FieldRD = Field->getType()->getAsRecordDecl())
316
23
          SeenNamedMember = FieldRD->findFirstNamedDataMember();
317
2.75k
      if (SeenNamedMember && 
!isZeroInitializable(Field)2.05k
) {
318
5
        IsZeroInitializable = IsZeroInitializableAsBase = false;
319
5
        StorageType = FieldType;
320
5
      }
321
2.75k
    }
322
    // Because our union isn't zero initializable, we won't be getting a better
323
    // storage type.
324
4.93k
    if (!IsZeroInitializable)
325
7
      continue;
326
    // Conditionally update our storage type if we've got a new "better" one.
327
4.92k
    if (!StorageType ||
328
2.53k
        getAlignment(FieldType) >  getAlignment(StorageType) ||
329
1.48k
        (getAlignment(FieldType) == getAlignment(StorageType) &&
330
1.10k
        getSize(FieldType) > getSize(StorageType)))
331
3.53k
      StorageType = FieldType;
332
4.92k
  }
333
  // If we have no storage type just pad to the appropriate size and return.
334
2.43k
  if (!StorageType)
335
38
    return appendPaddingBytes(LayoutSize);
336
  // If our storage size was bigger than our required size (can happen in the
337
  // case of packed bitfields on Itanium) then just use an I8 array.
338
2.39k
  if (LayoutSize < getSize(StorageType))
339
1
    StorageType = getByteArrayType(LayoutSize);
340
2.39k
  FieldTypes.push_back(StorageType);
341
2.39k
  appendPaddingBytes(LayoutSize - getSize(StorageType));
342
  // Set packed if we need it.
343
2.39k
  if (LayoutSize % getAlignment(StorageType))
344
4
    Packed = true;
345
2.39k
}
346
347
104k
void CGRecordLowering::accumulateFields() {
348
104k
  for (RecordDecl::field_iterator Field = D->field_begin(),
349
104k
                                  FieldEnd = D->field_end();
350
280k
    Field != FieldEnd;) {
351
175k
    if (Field->isBitField()) {
352
1.72k
      RecordDecl::field_iterator Start = Field;
353
      // Iterate to gather the list of bitfields.
354
6.57k
      for (++Field; Field != FieldEnd && 
Field->isBitField()5.46k
;
++Field4.85k
)
;4.85k
355
1.72k
      accumulateBitFields(Start, Field);
356
174k
    } else if (!Field->isZeroSize(Context)) {
357
173k
      Members.push_back(MemberInfo(
358
173k
          bitsToCharUnits(getFieldBitOffset(*Field)), MemberInfo::Field,
359
173k
          getStorageType(*Field), *Field));
360
173k
      ++Field;
361
32
    } else {
362
32
      ++Field;
363
32
    }
364
175k
  }
365
104k
}
366
367
void
368
CGRecordLowering::accumulateBitFields(RecordDecl::field_iterator Field,
369
1.72k
                                      RecordDecl::field_iterator FieldEnd) {
370
  // Run stores the first element of the current run of bitfields.  FieldEnd is
371
  // used as a special value to note that we don't have a current run.  A
372
  // bitfield run is a contiguous collection of bitfields that can be stored in
373
  // the same storage block.  Zero-sized bitfields and bitfields that would
374
  // cross an alignment boundary break a run and start a new one.
375
1.72k
  RecordDecl::field_iterator Run = FieldEnd;
376
  // Tail is the offset of the first bit off the end of the current run.  It's
377
  // used to determine if the ASTRecordLayout is treating these two bitfields as
378
  // contiguous.  StartBitOffset is offset of the beginning of the Run.
379
1.72k
  uint64_t StartBitOffset, Tail = 0;
380
1.72k
  if (isDiscreteBitFieldABI()) {
381
318
    for (; Field != FieldEnd; 
++Field222
) {
382
222
      uint64_t BitOffset = getFieldBitOffset(*Field);
383
      // Zero-width bitfields end runs.
384
222
      if (Field->isZeroLengthBitField(Context)) {
385
105
        Run = FieldEnd;
386
105
        continue;
387
105
      }
388
117
      llvm::Type *Type =
389
117
          Types.ConvertTypeForMem(Field->getType(), /*ForBitFields=*/true);
390
      // If we don't have a run yet, or don't live within the previous run's
391
      // allocated storage then we allocate some storage and start a new run.
392
117
      if (Run == FieldEnd || 
BitOffset >= Tail62
) {
393
84
        Run = Field;
394
84
        StartBitOffset = BitOffset;
395
84
        Tail = StartBitOffset + DataLayout.getTypeAllocSizeInBits(Type);
396
        // Add the storage member to the record.  This must be added to the
397
        // record before the bitfield members so that it gets laid out before
398
        // the bitfields it contains get laid out.
399
84
        Members.push_back(StorageInfo(bitsToCharUnits(StartBitOffset), Type));
400
84
      }
401
      // Bitfields get the offset of their storage but come afterward and remain
402
      // there after a stable sort.
403
117
      Members.push_back(MemberInfo(bitsToCharUnits(StartBitOffset),
404
117
                                   MemberInfo::Field, nullptr, *Field));
405
117
    }
406
96
    return;
407
96
  }
408
1.62k
409
  // Check if OffsetInRecord (the size in bits of the current run) is better
410
  // as a single field run. When OffsetInRecord has legal integer width, and
411
  // its bitfield offset is naturally aligned, it is better to make the
412
  // bitfield a separate storage component so as it can be accessed directly
413
  // with lower cost.
414
1.62k
  auto IsBetterAsSingleFieldRun = [&](uint64_t OffsetInRecord,
415
6.28k
                                      uint64_t StartBitOffset) {
416
6.28k
    if (!Types.getCodeGenOpts().FineGrainedBitfieldAccesses)
417
6.25k
      return false;
418
35
    if (OffsetInRecord < 8 || 
!llvm::isPowerOf2_64(OffsetInRecord)30
||
419
12
        !DataLayout.fitsInLegalInteger(OffsetInRecord))
420
23
      return false;
421
    // Make sure StartBitOffset is natually aligned if it is treated as an
422
    // IType integer.
423
12
     if (StartBitOffset %
424
12
            Context.toBits(getAlignment(getIntNType(OffsetInRecord))) !=
425
12
        0)
426
0
      return false;
427
12
    return true;
428
12
  };
429
1.62k
430
  // The start field is better as a single field run.
431
1.62k
  bool StartFieldAsSingleRun = false;
432
9.57k
  for (;;) {
433
    // Check to see if we need to start a new run.
434
9.57k
    if (Run == FieldEnd) {
435
      // If we're out of fields, return.
436
3.36k
      if (Field == FieldEnd)
437
1.62k
        break;
438
      // Any non-zero-length bitfield can start a new run.
439
1.73k
      if (!Field->isZeroLengthBitField(Context)) {
440
1.59k
        Run = Field;
441
1.59k
        StartBitOffset = getFieldBitOffset(*Field);
442
1.59k
        Tail = StartBitOffset + Field->getBitWidthValue(Context);
443
1.59k
        StartFieldAsSingleRun = IsBetterAsSingleFieldRun(Tail - StartBitOffset,
444
1.59k
                                                         StartBitOffset);
445
1.59k
      }
446
1.73k
      ++Field;
447
1.73k
      continue;
448
1.73k
    }
449
6.21k
450
    // If the start field of a new run is better as a single run, or
451
    // if current field (or consecutive fields) is better as a single run, or
452
    // if current field has zero width bitfield and either
453
    // UseZeroLengthBitfieldAlignment or UseBitFieldTypeAlignment is set to
454
    // true, or
455
    // if the offset of current field is inconsistent with the offset of
456
    // previous field plus its offset,
457
    // skip the block below and go ahead to emit the storage.
458
    // Otherwise, try to add bitfields to the run.
459
6.21k
    if (!StartFieldAsSingleRun && 
Field != FieldEnd6.20k
&&
460
4.69k
        !IsBetterAsSingleFieldRun(Tail - StartBitOffset, StartBitOffset) &&
461
4.68k
        (!Field->isZeroLengthBitField(Context) ||
462
28
         (!Context.getTargetInfo().useZeroLengthBitfieldAlignment() &&
463
23
          !Context.getTargetInfo().useBitFieldTypeAlignment())) &&
464
4.65k
        Tail == getFieldBitOffset(*Field)) {
465
4.61k
      Tail += Field->getBitWidthValue(Context);
466
4.61k
      ++Field;
467
4.61k
      continue;
468
4.61k
    }
469
1.59k
470
    // We've hit a break-point in the run and need to emit a storage field.
471
1.59k
    llvm::Type *Type = getIntNType(Tail - StartBitOffset);
472
    // Add the storage member to the record and set the bitfield info for all of
473
    // the bitfields in the run.  Bitfields get the offset of their storage but
474
    // come afterward and remain there after a stable sort.
475
1.59k
    Members.push_back(StorageInfo(bitsToCharUnits(StartBitOffset), Type));
476
7.80k
    for (; Run != Field; 
++Run6.21k
)
477
6.21k
      Members.push_back(MemberInfo(bitsToCharUnits(StartBitOffset),
478
6.21k
                                   MemberInfo::Field, nullptr, *Run));
479
1.59k
    Run = FieldEnd;
480
1.59k
    StartFieldAsSingleRun = false;
481
1.59k
  }
482
1.62k
}
483
484
73.2k
void CGRecordLowering::accumulateBases() {
485
  // If we've got a primary virtual base, we need to add it with the bases.
486
73.2k
  if (Layout.isPrimaryBaseVirtual()) {
487
171
    const CXXRecordDecl *BaseDecl = Layout.getPrimaryBase();
488
171
    Members.push_back(MemberInfo(CharUnits::Zero(), MemberInfo::Base,
489
171
                                 getStorageType(BaseDecl), BaseDecl));
490
171
  }
491
  // Accumulate the non-virtual bases.
492
19.1k
  for (const auto &Base : RD->bases()) {
493
19.1k
    if (Base.isVirtual())
494
1.52k
      continue;
495
17.5k
496
    // Bases can be zero-sized even if not technically empty if they
497
    // contain only a trailing array member.
498
17.5k
    const CXXRecordDecl *BaseDecl = Base.getType()->getAsCXXRecordDecl();
499
17.5k
    if (!BaseDecl->isEmpty() &&
500
10.4k
        !Context.getASTRecordLayout(BaseDecl).getNonVirtualSize().isZero())
501
9.41k
      Members.push_back(MemberInfo(Layout.getBaseClassOffset(BaseDecl),
502
9.41k
          MemberInfo::Base, getStorageType(BaseDecl), BaseDecl));
503
17.5k
  }
504
73.2k
}
505
506
73.2k
void CGRecordLowering::accumulateVPtrs() {
507
73.2k
  if (Layout.hasOwnVFPtr())
508
3.81k
    Members.push_back(MemberInfo(CharUnits::Zero(), MemberInfo::VFPtr,
509
3.81k
        llvm::FunctionType::get(getIntNType(32), /*isVarArg=*/true)->
510
3.81k
            getPointerTo()->getPointerTo()));
511
73.2k
  if (Layout.hasOwnVBPtr())
512
603
    Members.push_back(MemberInfo(Layout.getVBPtrOffset(), MemberInfo::VBPtr,
513
603
        llvm::Type::getInt32PtrTy(Types.getLLVMContext())));
514
73.2k
}
515
516
49.7k
void CGRecordLowering::accumulateVBases() {
517
49.7k
  CharUnits ScissorOffset = Layout.getNonVirtualSize();
518
  // In the itanium ABI, it's possible to place a vbase at a dsize that is
519
  // smaller than the nvsize.  Here we check to see if such a base is placed
520
  // before the nvsize and set the scissor offset to that, instead of the
521
  // nvsize.
522
49.7k
  if (isOverlappingVBaseABI())
523
47.8k
    for (const auto &Base : RD->vbases()) {
524
682
      const CXXRecordDecl *BaseDecl = Base.getType()->getAsCXXRecordDecl();
525
682
      if (BaseDecl->isEmpty())
526
86
        continue;
527
      // If the vbase is a primary virtual base of some base, then it doesn't
528
      // get its own storage location but instead lives inside of that base.
529
596
      if (Context.isNearlyEmpty(BaseDecl) && 
!hasOwnStorage(RD, BaseDecl)249
)
530
223
        continue;
531
373
      ScissorOffset = std::min(ScissorOffset,
532
373
                               Layout.getVBaseClassOffset(BaseDecl));
533
373
    }
534
49.7k
  Members.push_back(MemberInfo(ScissorOffset, MemberInfo::Scissor, nullptr,
535
49.7k
                               RD));
536
1.33k
  for (const auto &Base : RD->vbases()) {
537
1.33k
    const CXXRecordDecl *BaseDecl = Base.getType()->getAsCXXRecordDecl();
538
1.33k
    if (BaseDecl->isEmpty())
539
153
      continue;
540
1.18k
    CharUnits Offset = Layout.getVBaseClassOffset(BaseDecl);
541
    // If the vbase is a primary virtual base of some base, then it doesn't
542
    // get its own storage location but instead lives inside of that base.
543
1.18k
    if (isOverlappingVBaseABI() &&
544
596
        Context.isNearlyEmpty(BaseDecl) &&
545
249
        !hasOwnStorage(RD, BaseDecl)) {
546
223
      Members.push_back(MemberInfo(Offset, MemberInfo::VBase, nullptr,
547
223
                                   BaseDecl));
548
223
      continue;
549
223
    }
550
    // If we've got a vtordisp, add it as a storage type.
551
958
    if (Layout.getVBaseOffsetsMap().find(BaseDecl)->second.hasVtorDisp())
552
89
      Members.push_back(StorageInfo(Offset - CharUnits::fromQuantity(4),
553
89
                                    getIntNType(32)));
554
958
    Members.push_back(MemberInfo(Offset, MemberInfo::VBase,
555
958
                                 getStorageType(BaseDecl), BaseDecl));
556
958
  }
557
49.7k
}
558
559
bool CGRecordLowering::hasOwnStorage(const CXXRecordDecl *Decl,
560
972
                                     const CXXRecordDecl *Query) {
561
972
  const ASTRecordLayout &DeclLayout = Context.getASTRecordLayout(Decl);
562
972
  if (DeclLayout.isPrimaryBaseVirtual() && 
DeclLayout.getPrimaryBase() == Query580
)
563
446
    return false;
564
526
  for (const auto &Base : Decl->bases())
565
474
    if (!hasOwnStorage(Base.getType()->getAsCXXRecordDecl(), Query))
566
188
      return false;
567
338
  return true;
568
526
}
569
570
83.4k
void CGRecordLowering::calculateZeroInit() {
571
83.4k
  for (std::vector<MemberInfo>::const_iterator Member = Members.begin(),
572
83.4k
                                               MemberEnd = Members.end();
573
332k
       IsZeroInitializableAsBase && 
Member != MemberEnd332k
;
++Member249k
) {
574
249k
    if (Member->Kind == MemberInfo::Field) {
575
184k
      if (!Member->FD || 
isZeroInitializable(Member->FD)180k
)
576
184k
        continue;
577
64
      IsZeroInitializable = IsZeroInitializableAsBase = false;
578
64.8k
    } else if (Member->Kind == MemberInfo::Base ||
579
55.2k
               Member->Kind == MemberInfo::VBase) {
580
10.7k
      if (isZeroInitializable(Member->RD))
581
10.7k
        continue;
582
15
      IsZeroInitializable = false;
583
15
      if (Member->Kind == MemberInfo::Base)
584
13
        IsZeroInitializableAsBase = false;
585
15
    }
586
249k
  }
587
83.4k
}
588
589
83.4k
void CGRecordLowering::clipTailPadding() {
590
83.4k
  std::vector<MemberInfo>::iterator Prior = Members.begin();
591
83.4k
  CharUnits Tail = getSize(Prior->Data);
592
83.4k
  for (std::vector<MemberInfo>::iterator Member = Prior + 1,
593
83.4k
                                         MemberEnd = Members.end();
594
330k
       Member != MemberEnd; 
++Member246k
) {
595
    // Only members with data and the scissor can cut into tail padding.
596
246k
    if (!Member->Data && 
Member->Kind != MemberInfo::Scissor56.2k
)
597
6.55k
      continue;
598
240k
    if (Member->Offset < Tail) {
599
182
      assert(Prior->Kind == MemberInfo::Field &&
600
182
             "Only storage fields have tail padding!");
601
182
      if (!Prior->FD || 
Prior->FD->isBitField()12
)
602
170
        Prior->Data = getByteArrayType(bitsToCharUnits(llvm::alignTo(
603
170
            cast<llvm::IntegerType>(Prior->Data)->getIntegerBitWidth(), 8)));
604
12
      else {
605
12
        assert(Prior->FD->hasAttr<NoUniqueAddressAttr>() &&
606
12
               "should not have reused this field's tail padding");
607
12
        Prior->Data = getByteArrayType(
608
12
            Context.getTypeInfoDataSizeInChars(Prior->FD->getType()).first);
609
12
      }
610
182
    }
611
240k
    if (Member->Data)
612
190k
      Prior = Member;
613
240k
    Tail = Prior->Offset + getSize(Prior->Data);
614
240k
  }
615
83.4k
}
616
617
83.4k
void CGRecordLowering::determinePacked(bool NVBaseType) {
618
83.4k
  if (Packed)
619
1.20k
    return;
620
82.2k
  CharUnits Alignment = CharUnits::One();
621
82.2k
  CharUnits NVAlignment = CharUnits::One();
622
82.2k
  CharUnits NVSize =
623
82.2k
      !NVBaseType && 
RD81.1k
?
Layout.getNonVirtualSize()49.7k
:
CharUnits::Zero()32.4k
;
624
82.2k
  for (std::vector<MemberInfo>::const_iterator Member = Members.begin(),
625
82.2k
                                               MemberEnd = Members.end();
626
408k
       Member != MemberEnd; 
++Member326k
) {
627
326k
    if (!Member->Data)
628
56.2k
      continue;
629
    // If any member falls at an offset that it not a multiple of its alignment,
630
    // then the entire record must be packed.
631
269k
    if (Member->Offset % getAlignment(Member->Data))
632
128
      Packed = true;
633
269k
    if (Member->Offset < NVSize)
634
117k
      NVAlignment = std::max(NVAlignment, getAlignment(Member->Data));
635
269k
    Alignment = std::max(Alignment, getAlignment(Member->Data));
636
269k
  }
637
  // If the size of the record (the capstone's offset) is not a multiple of the
638
  // record's alignment, it must be packed.
639
82.2k
  if (Members.back().Offset % Alignment)
640
1.50k
    Packed = true;
641
  // If the non-virtual sub-object is not a multiple of the non-virtual
642
  // sub-object's alignment, it must be packed.  We cannot have a packed
643
  // non-virtual sub-object and an unpacked complete object or vise versa.
644
82.2k
  if (NVSize % NVAlignment)
645
2.62k
    Packed = true;
646
  // Update the alignment of the sentinel.
647
82.2k
  if (!Packed)
648
79.5k
    Members.back().Data = getIntNType(Context.toBits(Alignment));
649
82.2k
}
650
651
83.4k
void CGRecordLowering::insertPadding() {
652
83.4k
  std::vector<std::pair<CharUnits, CharUnits> > Padding;
653
83.4k
  CharUnits Size = CharUnits::Zero();
654
83.4k
  for (std::vector<MemberInfo>::const_iterator Member = Members.begin(),
655
83.4k
                                               MemberEnd = Members.end();
656
413k
       Member != MemberEnd; 
++Member330k
) {
657
330k
    if (!Member->Data)
658
56.2k
      continue;
659
274k
    CharUnits Offset = Member->Offset;
660
274k
    assert(Offset >= Size);
661
    // Insert padding if we need to.
662
274k
    if (Offset !=
663
260k
        Size.alignTo(Packed ? 
CharUnits::One()13.2k
: getAlignment(Member->Data)))
664
2.48k
      Padding.push_back(std::make_pair(Size, Offset - Size));
665
274k
    Size = Offset + getSize(Member->Data);
666
274k
  }
667
83.4k
  if (Padding.empty())
668
81.1k
    return;
669
  // Add the padding to the Members list and sort it.
670
2.27k
  for (std::vector<std::pair<CharUnits, CharUnits> >::const_iterator
671
2.27k
        Pad = Padding.begin(), PadEnd = Padding.end();
672
4.76k
        Pad != PadEnd; 
++Pad2.48k
)
673
2.48k
    Members.push_back(StorageInfo(Pad->first, getByteArrayType(Pad->second)));
674
2.27k
  llvm::stable_sort(Members);
675
2.27k
}
676
677
83.4k
void CGRecordLowering::fillOutputFields() {
678
83.4k
  for (std::vector<MemberInfo>::const_iterator Member = Members.begin(),
679
83.4k
                                               MemberEnd = Members.end();
680
332k
       Member != MemberEnd; 
++Member249k
) {
681
249k
    if (Member->Data)
682
193k
      FieldTypes.push_back(Member->Data);
683
249k
    if (Member->Kind == MemberInfo::Field) {
684
184k
      if (Member->FD)
685
180k
        Fields[Member->FD->getCanonicalDecl()] = FieldTypes.size() - 1;
686
      // A field without storage must be a bitfield.
687
184k
      if (!Member->Data)
688
6.32k
        setBitFieldInfo(Member->FD, Member->Offset, FieldTypes.back());
689
64.9k
    } else if (Member->Kind == MemberInfo::Base)
690
9.58k
      NonVirtualBases[Member->RD] = FieldTypes.size() - 1;
691
55.3k
    else if (Member->Kind == MemberInfo::VBase)
692
1.18k
      VirtualBases[Member->RD] = FieldTypes.size() - 1;
693
249k
  }
694
83.4k
}
695
696
CGBitFieldInfo CGBitFieldInfo::MakeInfo(CodeGenTypes &Types,
697
                                        const FieldDecl *FD,
698
                                        uint64_t Offset, uint64_t Size,
699
                                        uint64_t StorageSize,
700
130
                                        CharUnits StorageOffset) {
701
  // This function is vestigial from CGRecordLayoutBuilder days but is still
702
  // used in GCObjCRuntime.cpp.  That usage has a "fixme" attached to it that
703
  // when addressed will allow for the removal of this function.
704
130
  llvm::Type *Ty = Types.ConvertTypeForMem(FD->getType());
705
130
  CharUnits TypeSizeInBytes =
706
130
    CharUnits::fromQuantity(Types.getDataLayout().getTypeAllocSize(Ty));
707
130
  uint64_t TypeSizeInBits = Types.getContext().toBits(TypeSizeInBytes);
708
130
709
130
  bool IsSigned = FD->getType()->isSignedIntegerOrEnumerationType();
710
130
711
130
  if (Size > TypeSizeInBits) {
712
    // We have a wide bit-field. The extra bits are only used for padding, so
713
    // if we have a bitfield of type T, with size N:
714
    //
715
    // T t : N;
716
    //
717
    // We can just assume that it's:
718
    //
719
    // T t : sizeof(T);
720
    //
721
0
    Size = TypeSizeInBits;
722
0
  }
723
130
724
  // Reverse the bit offsets for big endian machines. Because we represent
725
  // a bitfield as a single large integer load, we can imagine the bits
726
  // counting from the most-significant-bit instead of the
727
  // least-significant-bit.
728
130
  if (Types.getDataLayout().isBigEndian()) {
729
0
    Offset = StorageSize - (Offset + Size);
730
0
  }
731
130
732
130
  return CGBitFieldInfo(Offset, Size, IsSigned, StorageSize, StorageOffset);
733
130
}
734
735
std::unique_ptr<CGRecordLayout>
736
99.5k
CodeGenTypes::ComputeRecordLayout(const RecordDecl *D, llvm::StructType *Ty) {
737
99.5k
  CGRecordLowering Builder(*this, D, /*Packed=*/false);
738
99.5k
739
99.5k
  Builder.lower(/*NonVirtualBaseType=*/false);
740
99.5k
741
  // If we're in C++, compute the base subobject type.
742
99.5k
  llvm::StructType *BaseTy = nullptr;
743
99.5k
  if (isa<CXXRecordDecl>(D) && 
!D->isUnion()67.6k
&&
!D->hasAttr<FinalAttr>()65.6k
) {
744
65.6k
    BaseTy = Ty;
745
65.6k
    if (Builder.Layout.getNonVirtualSize() != Builder.Layout.getSize()) {
746
7.55k
      CGRecordLowering BaseBuilder(*this, D, /*Packed=*/Builder.Packed);
747
7.55k
      BaseBuilder.lower(/*NonVirtualBaseType=*/true);
748
7.55k
      BaseTy = llvm::StructType::create(
749
7.55k
          getLLVMContext(), BaseBuilder.FieldTypes, "", BaseBuilder.Packed);
750
7.55k
      addRecordTypeName(D, BaseTy, ".base");
751
      // BaseTy and Ty must agree on their packedness for getLLVMFieldNo to work
752
      // on both of them with the same index.
753
7.55k
      assert(Builder.Packed == BaseBuilder.Packed &&
754
7.55k
             "Non-virtual and complete types must agree on packedness");
755
7.55k
    }
756
65.6k
  }
757
99.5k
758
  // Fill in the struct *after* computing the base type.  Filling in the body
759
  // signifies that the type is no longer opaque and record layout is complete,
760
  // but we may need to recursively layout D while laying D out as a base type.
761
99.5k
  Ty->setBody(Builder.FieldTypes, Builder.Packed);
762
99.5k
763
99.5k
  auto RL = std::make_unique<CGRecordLayout>(
764
99.5k
      Ty, BaseTy, (bool)Builder.IsZeroInitializable,
765
99.5k
      (bool)Builder.IsZeroInitializableAsBase);
766
99.5k
767
99.5k
  RL->NonVirtualBases.swap(Builder.NonVirtualBases);
768
99.5k
  RL->CompleteObjectVirtualBases.swap(Builder.VirtualBases);
769
99.5k
770
  // Add all the field numbers.
771
99.5k
  RL->FieldInfo.swap(Builder.Fields);
772
99.5k
773
  // Add bitfield info.
774
99.5k
  RL->BitFields.swap(Builder.BitFields);
775
99.5k
776
  // Dump the layout, if requested.
777
99.5k
  if (getContext().getLangOpts().DumpRecordLayouts) {
778
50
    llvm::outs() << "\n*** Dumping IRgen Record Layout\n";
779
50
    llvm::outs() << "Record: ";
780
50
    D->dump(llvm::outs());
781
50
    llvm::outs() << "\nLayout: ";
782
50
    RL->print(llvm::outs());
783
50
  }
784
99.5k
785
99.5k
#ifndef NDEBUG
786
  // Verify that the computed LLVM struct size matches the AST layout size.
787
99.5k
  const ASTRecordLayout &Layout = getContext().getASTRecordLayout(D);
788
99.5k
789
99.5k
  uint64_t TypeSizeInBits = getContext().toBits(Layout.getSize());
790
99.5k
  assert(TypeSizeInBits == getDataLayout().getTypeAllocSizeInBits(Ty) &&
791
99.5k
         "Type size mismatch!");
792
99.5k
793
99.5k
  if (BaseTy) {
794
65.6k
    CharUnits NonVirtualSize  = Layout.getNonVirtualSize();
795
65.6k
796
65.6k
    uint64_t AlignedNonVirtualTypeSizeInBits =
797
65.6k
      getContext().toBits(NonVirtualSize);
798
65.6k
799
65.6k
    assert(AlignedNonVirtualTypeSizeInBits ==
800
65.6k
           getDataLayout().getTypeAllocSizeInBits(BaseTy) &&
801
65.6k
           "Type size mismatch!");
802
65.6k
  }
803
99.5k
804
  // Verify that the LLVM and AST field offsets agree.
805
99.5k
  llvm::StructType *ST = RL->getLLVMType();
806
99.5k
  const llvm::StructLayout *SL = getDataLayout().getStructLayout(ST);
807
99.5k
808
99.5k
  const ASTRecordLayout &AST_RL = getContext().getASTRecordLayout(D);
809
99.5k
  RecordDecl::field_iterator it = D->field_begin();
810
282k
  for (unsigned i = 0, e = AST_RL.getFieldCount(); i != e; 
++i, ++it182k
) {
811
182k
    const FieldDecl *FD = *it;
812
182k
813
    // Ignore zero-sized fields.
814
182k
    if (FD->isZeroSize(getContext()))
815
277
      continue;
816
182k
817
    // For non-bit-fields, just check that the LLVM struct offset matches the
818
    // AST offset.
819
182k
    if (!FD->isBitField()) {
820
175k
      unsigned FieldNo = RL->getLLVMFieldNo(FD);
821
175k
      assert(AST_RL.getFieldOffset(i) == SL->getElementOffsetInBits(FieldNo) &&
822
175k
             "Invalid field offset!");
823
175k
      continue;
824
175k
    }
825
6.25k
826
    // Ignore unnamed bit-fields.
827
6.25k
    if (!FD->getDeclName())
828
493
      continue;
829
5.76k
830
5.76k
    const CGBitFieldInfo &Info = RL->getBitFieldInfo(FD);
831
5.76k
    llvm::Type *ElementTy = ST->getTypeAtIndex(RL->getLLVMFieldNo(FD));
832
5.76k
833
    // Unions have overlapping elements dictating their layout, but for
834
    // non-unions we can verify that this section of the layout is the exact
835
    // expected size.
836
5.76k
    if (D->isUnion()) {
837
      // For unions we verify that the start is zero and the size
838
      // is in-bounds. However, on BE systems, the offset may be non-zero, but
839
      // the size + offset should match the storage size in that case as it
840
      // "starts" at the back.
841
25
      if (getDataLayout().isBigEndian())
842
25
        assert(static_cast<unsigned>(Info.Offset + Info.Size) ==
843
25
               Info.StorageSize &&
844
25
               "Big endian union bitfield does not end at the back");
845
25
      else
846
25
        assert(Info.Offset == 0 &&
847
25
               "Little endian union bitfield with a non-zero offset");
848
25
      assert(Info.StorageSize <= SL->getSizeInBits() &&
849
25
             "Union not large enough for bitfield storage");
850
5.74k
    } else {
851
5.74k
      assert(Info.StorageSize ==
852
5.74k
             getDataLayout().getTypeAllocSizeInBits(ElementTy) &&
853
5.74k
             "Storage size does not match the element type size");
854
5.74k
    }
855
5.76k
    assert(Info.Size > 0 && "Empty bitfield!");
856
5.76k
    assert(static_cast<unsigned>(Info.Offset) + Info.Size <= Info.StorageSize &&
857
5.76k
           "Bitfield outside of its allocated storage");
858
5.76k
  }
859
99.5k
#endif
860
99.5k
861
99.5k
  return RL;
862
99.5k
}
863
864
50
void CGRecordLayout::print(raw_ostream &OS) const {
865
50
  OS << "<CGRecordLayout\n";
866
50
  OS << "  LLVMType:" << *CompleteObjectType << "\n";
867
50
  if (BaseSubobjectType)
868
31
    OS << "  NonVirtualBaseLLVMType:" << *BaseSubobjectType << "\n";
869
50
  OS << "  IsZeroInitializable:" << IsZeroInitializable << "\n";
870
50
  OS << "  BitFields:[\n";
871
50
872
  // Print bit-field infos in declaration order.
873
50
  std::vector<std::pair<unsigned, const CGBitFieldInfo*> > BFIs;
874
50
  for (llvm::DenseMap<const FieldDecl*, CGBitFieldInfo>::const_iterator
875
50
         it = BitFields.begin(), ie = BitFields.end();
876
82
       it != ie; 
++it32
) {
877
32
    const RecordDecl *RD = it->first->getParent();
878
32
    unsigned Index = 0;
879
32
    for (RecordDecl::field_iterator
880
81
           it2 = RD->field_begin(); *it2 != it->first; 
++it249
)
881
49
      ++Index;
882
32
    BFIs.push_back(std::make_pair(Index, &it->second));
883
32
  }
884
50
  llvm::array_pod_sort(BFIs.begin(), BFIs.end());
885
82
  for (unsigned i = 0, e = BFIs.size(); i != e; 
++i32
) {
886
32
    OS.indent(4);
887
32
    BFIs[i].second->print(OS);
888
32
    OS << "\n";
889
32
  }
890
50
891
50
  OS << "]>\n";
892
50
}
893
894
0
LLVM_DUMP_METHOD void CGRecordLayout::dump() const {
895
0
  print(llvm::errs());
896
0
}
897
898
32
void CGBitFieldInfo::print(raw_ostream &OS) const {
899
32
  OS << "<CGBitFieldInfo"
900
32
     << " Offset:" << Offset
901
32
     << " Size:" << Size
902
32
     << " IsSigned:" << IsSigned
903
32
     << " StorageSize:" << StorageSize
904
32
     << " StorageOffset:" << StorageOffset.getQuantity() << ">";
905
32
}
906
907
0
LLVM_DUMP_METHOD void CGBitFieldInfo::dump() const {
908
0
  print(llvm::errs());
909
0
}