[cfe-commits] r52035 - in /cfe/trunk: include/clang/AST/RecordLayout.h lib/AST/ASTContext.cpp
Devang Patel
dpatel at apple.com
Thu Jun 5 19:14:01 PDT 2008
Author: dpatel
Date: Thu Jun 5 21:14:01 2008
New Revision: 52035
URL: http://llvm.org/viewvc/llvm-project?rev=52035&view=rev
Log:
During interface layout, don't forget super class.
Modified:
cfe/trunk/include/clang/AST/RecordLayout.h
cfe/trunk/lib/AST/ASTContext.cpp
Modified: cfe/trunk/include/clang/AST/RecordLayout.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecordLayout.h?rev=52035&r1=52034&r2=52035&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecordLayout.h (original)
+++ cfe/trunk/include/clang/AST/RecordLayout.h Thu Jun 5 21:14:01 2008
@@ -30,16 +30,19 @@
class ASTRecordLayout {
uint64_t Size; // Size of record in bits.
unsigned Alignment; // Alignment of record in bits.
+ unsigned FieldCount; // Number of fields
uint64_t *FieldOffsets;
friend class ASTContext;
-
- ASTRecordLayout() : Size(0), Alignment(8) {}
+
+ ASTRecordLayout(uint64_t S = 0, unsigned A = 8)
+ : Size(S), Alignment(A), FieldCount(0) {}
~ASTRecordLayout() {
delete [] FieldOffsets;
}
/// Initialize record layout. N is the number of fields in this record.
void InitializeLayout(unsigned N) {
+ FieldCount = N;
FieldOffsets = new uint64_t[N];
}
@@ -50,6 +53,11 @@
Size = (Size + (Alignment-1)) & ~(Alignment-1);
}
+ void SetFieldOffset(unsigned FieldNo, uint64_t Offset) {
+ assert (FieldNo < FieldCount && "Invalid Field No");
+ FieldOffsets[FieldNo] = Offset;
+ }
+
void SetAlignment(unsigned A) { Alignment = A; }
/// LayoutField - Field layout.
@@ -65,6 +73,7 @@
uint64_t getSize() const { return Size; }
uint64_t getFieldOffset(unsigned FieldNo) const {
+ assert (FieldNo < FieldCount && "Invalid Field No");
return FieldOffsets[FieldNo];
}
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=52035&r1=52034&r2=52035&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu Jun 5 21:14:01 2008
@@ -405,10 +405,22 @@
// Allocate and assign into ASTRecordLayouts here. The "Entry" reference can
// be invalidated (dangle) if the ASTRecordLayouts hashtable is inserted into.
- ASTRecordLayout *NewEntry = new ASTRecordLayout();
+ ASTRecordLayout *NewEntry = NULL;
+ unsigned FieldCount = D->ivar_size();
+ if (ObjCInterfaceDecl *SD = D->getSuperClass()) {
+ FieldCount++;
+ const ASTRecordLayout &SL = getASTObjCInterfaceLayout(SD);
+ unsigned Alignment = SL.getAlignment();
+ uint64_t Size = SL.getSize();
+ NewEntry = new ASTRecordLayout(Size, Alignment);
+ NewEntry->InitializeLayout(FieldCount);
+ NewEntry->SetFieldOffset(0, 0); // Super class is at the beginning of the layout.
+ } else {
+ NewEntry = new ASTRecordLayout();
+ NewEntry->InitializeLayout(FieldCount);
+ }
Entry = NewEntry;
- NewEntry->InitializeLayout(D->ivar_size());
bool IsPacked = D->getAttr<PackedAttr>();
if (const AlignedAttr *AA = D->getAttr<AlignedAttr>())
More information about the cfe-commits
mailing list