AppendBytes(NumBytesToAppend);
- AlignmentAsLLVMStruct = std::max(AlignmentAsLLVMStruct, getTypeAlignment(Ty));
-
BitsAvailableInLastField =
NextFieldOffsetInBytes * 8 - (FieldOffset + FieldSize);
}
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);
}
-// 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;