diff options
| author | Devang Patel <dpatel@apple.com> | 2008-06-06 02:14:01 +0000 |
|---|---|---|
| committer | Devang Patel <dpatel@apple.com> | 2008-06-06 02:14:01 +0000 |
| commit | 8f5645cd518a31e7de9401543a4a75057bb1947e (patch) | |
| tree | 8bebbd659e4769682dbac82255735f3c01787791 | |
| parent | e1f10511ba77d6b6d98aa680505ffb844bd42b37 (diff) | |
| download | bcm5719-llvm-8f5645cd518a31e7de9401543a4a75057bb1947e.tar.gz bcm5719-llvm-8f5645cd518a31e7de9401543a4a75057bb1947e.zip | |
During interface layout, don't forget super class.
llvm-svn: 52035
| -rw-r--r-- | clang/include/clang/AST/RecordLayout.h | 13 | ||||
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 16 |
2 files changed, 25 insertions, 4 deletions
diff --git a/clang/include/clang/AST/RecordLayout.h b/clang/include/clang/AST/RecordLayout.h index 82880abfcf5..1b72017cd3e 100644 --- a/clang/include/clang/AST/RecordLayout.h +++ b/clang/include/clang/AST/RecordLayout.h @@ -30,16 +30,19 @@ namespace clang { 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 @@ class ASTRecordLayout { 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 @@ public: uint64_t getSize() const { return Size; } uint64_t getFieldOffset(unsigned FieldNo) const { + assert (FieldNo < FieldCount && "Invalid Field No"); return FieldOffsets[FieldNo]; } diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 4a1fb39bb60..d8e2c06fc03 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -405,10 +405,22 @@ ASTContext::getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) { // 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>()) |

