diff options
author | Anders Carlsson <andersca@mac.com> | 2009-12-08 01:24:23 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-12-08 01:24:23 +0000 |
commit | c2456824a106455bae5d738fe65d80b14a6804c4 (patch) | |
tree | 9419fa1ff060b354f41482616da6382ca6e3b951 | |
parent | b455f0e74be0144ab9738ef574d07bd661959525 (diff) |
No need to add tail padding if the resulting LLVM struct type will have the same size as the final record size.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90820 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGRecordLayoutBuilder.cpp | 10 | ||||
-rw-r--r-- | test/CodeGenCXX/class-layout.cpp | 8 |
2 files changed, 14 insertions, 4 deletions
diff --git a/lib/CodeGen/CGRecordLayoutBuilder.cpp b/lib/CodeGen/CGRecordLayoutBuilder.cpp index 1a9bc39170..31784eda5a 100644 --- a/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -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); } diff --git a/test/CodeGenCXX/class-layout.cpp b/test/CodeGenCXX/class-layout.cpp index 7663d2e541..d4fc627082 100644 --- a/test/CodeGenCXX/class-layout.cpp +++ b/test/CodeGenCXX/class-layout.cpp @@ -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; |