]> granicus.if.org Git - clang/commitdiff
No need to add tail padding if the resulting LLVM struct type will have the same...
authorAnders Carlsson <andersca@mac.com>
Tue, 8 Dec 2009 01:24:23 +0000 (01:24 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 8 Dec 2009 01:24:23 +0000 (01:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90820 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGRecordLayoutBuilder.cpp
test/CodeGenCXX/class-layout.cpp

index 1a9bc3917092ff1e8d3d5c3c181f9568623d6e09..31784eda5a6be84f807c46f08e56c9ff9a6446d2 100644 (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);
 }
index 7663d2e541b2d792dd39ffc0ca74b9f4d44dd5e2..d4fc627082d253612a4365400725fa18a99887a3 100644 (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;