diff options
author | Anders Carlsson <andersca@mac.com> | 2009-07-27 14:55:54 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-07-27 14:55:54 +0000 |
commit | c1efe36ca75b4f4f82cdec464bab5693ed0d6058 (patch) | |
tree | 557a28dbe950b328487982995de18a21bcbcc1ca /lib/CodeGen/CGRecordLayoutBuilder.cpp | |
parent | 8dca3b3d09ff48b3ec528cd603f835f120c4d9ee (diff) |
Fix a tail padding bug in the record layout builder code. The bug was found by an existing test.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77189 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGRecordLayoutBuilder.cpp')
-rw-r--r-- | lib/CodeGen/CGRecordLayoutBuilder.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/CodeGen/CGRecordLayoutBuilder.cpp b/lib/CodeGen/CGRecordLayoutBuilder.cpp index 74051383f1..adbfd3f1c6 100644 --- a/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -88,6 +88,8 @@ void CGRecordLayoutBuilder::LayoutBitField(const FieldDecl *D, AppendBytes(NumBytesToAppend); + AlignmentAsLLVMStruct = std::max(AlignmentAsLLVMStruct, getTypeAlignment(Ty)); + BitsAvailableInLastField = getNextFieldOffsetInBytes() * 8 - (FieldOffset + FieldSize); } @@ -207,12 +209,22 @@ bool CGRecordLayoutBuilder::LayoutFields(const RecordDecl *D) { } // Append tail padding if necessary. - if (Layout.getSize() / 8 > getNextFieldOffsetInBytes()) - AppendPadding(getNextFieldOffsetInBytes(), AlignmentAsLLVMStruct); + AppendTailPadding(Layout.getSize()); return true; } +void CGRecordLayoutBuilder::AppendTailPadding(uint64_t RecordSize) { + assert(RecordSize % 8 == 0 && "Invalid record size!"); + + uint64_t RecordSizeInBytes = RecordSize / 8; + assert(getNextFieldOffsetInBytes() <= RecordSizeInBytes && "Size mismatch!"); + + unsigned NumPadBytes = RecordSizeInBytes - getNextFieldOffsetInBytes(); + AppendBytes(NumPadBytes); +} + + void CGRecordLayoutBuilder::AppendField(uint64_t FieldOffsetInBytes, const llvm::Type *FieldTy) { AlignmentAsLLVMStruct = std::max(AlignmentAsLLVMStruct, @@ -256,10 +268,8 @@ void CGRecordLayoutBuilder::AppendBytes(uint64_t NumBytes) { return; const llvm::Type *Ty = llvm::Type::Int8Ty; - if (NumBytes > 1) { - // FIXME: Use a VMContext. + if (NumBytes > 1) Ty = llvm::ArrayType::get(Ty, NumBytes); - } // Append the padding field AppendField(getNextFieldOffsetInBytes(), Ty); @@ -294,7 +304,6 @@ CGRecordLayoutBuilder::ComputeLayout(CodeGenTypes &Types, // FIXME: Once this works well enough, enable it. return 0; - // FIXME: Use a VMContext. const llvm::Type *Ty = llvm::StructType::get(Builder.FieldTypes, Builder.Packed); |