[cfe-commits] r78069 - /cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
Anders Carlsson
andersca at mac.com
Tue Aug 4 09:29:16 PDT 2009
Author: andersca
Date: Tue Aug 4 11:29:15 2009
New Revision: 78069
URL: http://llvm.org/viewvc/llvm-project?rev=78069&view=rev
Log:
Simplify alignment handling in the record builder.
Modified:
cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=78069&r1=78068&r2=78069&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Tue Aug 4 11:29:15 2009
@@ -117,22 +117,28 @@
return true;
}
+ assert(FieldOffset % 8 == 0 && "FieldOffset is not on a byte boundary!");
+ uint64_t FieldOffsetInBytes = FieldOffset / 8;
+
const llvm::Type *Ty = Types.ConvertTypeForMemRecursive(D->getType());
+ unsigned TypeAlignment = getTypeAlignment(Ty);
- // Check if the field is aligned.
- if (const AlignedAttr *PA = D->getAttr<AlignedAttr>()) {
- unsigned FieldAlign = PA->getAlignment();
-
- if (!Packed && getTypeAlignment(Ty) > FieldAlign)
- return false;
+ // Round up the field offset to the alignment of the field type.
+ uint64_t AlignedNextFieldOffsetInBytes =
+ llvm::RoundUpToAlignment(NextFieldOffsetInBytes, TypeAlignment);
+
+ if (FieldOffsetInBytes < AlignedNextFieldOffsetInBytes) {
+ assert(!Packed && "Could not place field even with packed struct!");
+ return false;
}
-
- assert(FieldOffset % 8 == 0 && "FieldOffset is not on a byte boundary!");
- uint64_t FieldOffsetInBytes = FieldOffset / 8;
-
- // Append padding if necessary.
- AppendPadding(FieldOffsetInBytes, Ty);
+ if (AlignedNextFieldOffsetInBytes < FieldOffsetInBytes) {
+ // Even with alignment, the field offset is not at the right place,
+ // insert padding.
+ uint64_t PaddingInBytes = FieldOffsetInBytes - NextFieldOffsetInBytes;
+
+ AppendBytes(PaddingInBytes);
+ }
// Now append the field.
LLVMFields.push_back(LLVMFieldInfo(D, FieldTypes.size()));
More information about the cfe-commits
mailing list