/// \brief The alignment of the non-virtual portion of the record layout
/// Only used for C++ layouts.
CharUnits NonVirtualAlignment;
- /// \brief The additional alignment imposed by the virtual bases.
- CharUnits VirtualAlignment;
/// \brief The primary base class (if one exists).
const CXXRecordDecl *PrimaryBase;
/// \brief The class we share our vb-pointer with.
HasExtendableVFPtr = false;
SharedVBPtrBase = 0;
PrimaryBase = 0;
- VirtualAlignment = CharUnits::One();
LeadsWithZeroSizedBase = false;
// If the record has a dynamic base class, attempt to choose a primary base
HasZeroSizedSubObject = true;
// Handle virtual bases.
if (i->isVirtual()) {
- VirtualAlignment = std::max(VirtualAlignment, getBaseAlignment(Layout));
HasVBPtr = true;
continue;
}
if (!HasVBPtr)
return;
- updateAlignment(VirtualAlignment);
+ for (CXXRecordDecl::base_class_const_iterator i = RD->vbases_begin(),
+ e = RD->vbases_end();
+ i != e; ++i) {
+ const CXXRecordDecl *BaseDecl =
+ cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
+ const ASTRecordLayout &Layout = Context.getASTRecordLayout(BaseDecl);
+ updateAlignment(getBaseAlignment(Layout));
+ }
PreviousBaseLayout = 0;
// Zero-sized v-bases obey the alignment attribute so apply it here. The
#pragma pack(pop)
+struct A1 { long long a; };
+#pragma pack(push, 1)
+struct B1 : virtual A1 { char a; };
+#pragma pack(pop)
+struct C1 : B1 {};
+// CHECK: *** Dumping AST Record Layout
+// CHECK: 0 | struct C1
+// CHECK: 0 | struct B1 (base)
+// CHECK: 0 | (B1 vbtable pointer)
+// CHECK: 4 | char a
+// CHECK: 8 | struct A1 (virtual base)
+// CHECK: 8 | long long a
+// CHECK: | [sizeof=16, align=8
+// CHECK: | nvsize=5, nvalign=1]
+// CHECK-X64: *** Dumping AST Record Layout
+// CHECK-X64: 0 | struct C1
+// CHECK-X64: 0 | struct B1 (base)
+// CHECK-X64: 0 | (B1 vbtable pointer)
+// CHECK-X64: 8 | char a
+// CHECK-X64: 16 | struct A1 (virtual base)
+// CHECK-X64: 16 | long long a
+// CHECK-X64: | [sizeof=24, align=8
+// CHECK-X64: | nvsize=9, nvalign=1]
+
int a[
sizeof(X)+
sizeof(Y)+
-sizeof(Z)];
+sizeof(Z)+
+sizeof(C1)];