Fix the field count in interface record layout (it was incorrectly
compensating for super classes). This was making the reported class
sizes for empty classes very, very wrong.
- Also, we now report the size info for an empty class like gcc (as
the offset of the start, not as 0, 0).
- Add a few more test cases we were mishandling before (padding bit
field at end of struct, for example).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70938 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index a9f13c9..a947fea 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -713,10 +713,6 @@
ASTRecordLayout *NewEntry = NULL;
if (ObjCInterfaceDecl *SD = D->getSuperClass()) {
- // FIXME: This increment of FieldCount is wrong, we don't actually
- // count the super class as a member (see the field index passed
- // to LayoutField below).
- FieldCount++;
const ASTRecordLayout &SL = getASTObjCInterfaceLayout(SD);
unsigned Alignment = SL.getAlignment();
uint64_t Size = SL.getSize();
@@ -729,8 +725,6 @@
ObjCLayouts[Key] = NewEntry = new ASTRecordLayout(Size, Alignment);
NewEntry->InitializeLayout(FieldCount);
- // Super class is at the beginning of the layout.
- NewEntry->SetFieldOffset(0, 0);
} else {
ObjCLayouts[Key] = NewEntry = new ASTRecordLayout();
NewEntry->InitializeLayout(FieldCount);
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp
index 1a1ef83..1f58389 100644
--- a/lib/CodeGen/CGObjCMac.cpp
+++ b/lib/CodeGen/CGObjCMac.cpp
@@ -4222,13 +4222,14 @@
const ASTRecordLayout &RL =
CGM.getContext().getASTObjCImplementationLayout(OID);
- if (!RL.getFieldCount()) {
- InstanceStart = InstanceSize = 0;
- return;
- }
-
- InstanceStart = RL.getFieldOffset(0) / 8;
+ // InstanceSize is really instance end.
InstanceSize = llvm::RoundUpToAlignment(RL.getNextOffset(), 8) / 8;
+
+ // If there are no fields, the start is the same as the end.
+ if (!RL.getFieldCount())
+ InstanceStart = InstanceSize;
+ else
+ InstanceStart = RL.getFieldOffset(0) / 8;
}
void CGObjCNonFragileABIMac::GenerateClass(const ObjCImplementationDecl *ID) {