No need to add tail padding if the resulting LLVM struct type will have the same size as the final record size.

llvm-svn: 90820
This commit is contained in:
Anders Carlsson 2009-12-08 01:24:23 +00:00
parent dd2b2f8cba
commit 220bf4fc5a
2 changed files with 14 additions and 4 deletions

View File

@ -88,8 +88,6 @@ void CGRecordLayoutBuilder::LayoutBitField(const FieldDecl *D,
AppendBytes(NumBytesToAppend);
AlignmentAsLLVMStruct = std::max(AlignmentAsLLVMStruct, getTypeAlignment(Ty));
BitsAvailableInLastField =
NextFieldOffsetInBytes * 8 - (FieldOffset + FieldSize);
}
@ -247,6 +245,14 @@ void CGRecordLayoutBuilder::AppendTailPadding(uint64_t RecordSize) {
uint64_t RecordSizeInBytes = RecordSize / 8;
assert(NextFieldOffsetInBytes <= RecordSizeInBytes && "Size mismatch!");
uint64_t AlignedNextFieldOffset =
llvm::RoundUpToAlignment(NextFieldOffsetInBytes, AlignmentAsLLVMStruct);
if (AlignedNextFieldOffset == RecordSizeInBytes) {
// We don't need any padding.
return;
}
unsigned NumPadBytes = RecordSizeInBytes - NextFieldOffsetInBytes;
AppendBytes(NumPadBytes);
}

View File

@ -1,5 +1,9 @@
// RUN: clang-cc %s -emit-llvm -o %t
// RUN: clang-cc %s -emit-llvm -o - | FileCheck %s
// An extra byte shoudl be allocated for an empty class.
// RUN: grep '%.truct.A = type { i8 }' %t
// CHECK: %struct.A = type { i8 }
struct A { } a;
// No need to add tail padding here.
// CHECK: %struct.B = type { i8*, i32 }
struct B { void *a; int b; } b;