[cfe-commits] r77189 - in /cfe/trunk/lib/CodeGen: CGRecordLayoutBuilder.cpp CGRecordLayoutBuilder.h
Anders Carlsson
andersca at mac.com
Mon Jul 27 07:56:13 PDT 2009
Author: andersca
Date: Mon Jul 27 09:55:54 2009
New Revision: 77189
URL: http://llvm.org/viewvc/llvm-project?rev=77189&view=rev
Log:
Fix a tail padding bug in the record layout builder code. The bug was found by an existing test.
Modified:
cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.h
Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=77189&r1=77188&r2=77189&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Mon Jul 27 09:55:54 2009
@@ -88,6 +88,8 @@
AppendBytes(NumBytesToAppend);
+ AlignmentAsLLVMStruct = std::max(AlignmentAsLLVMStruct, getTypeAlignment(Ty));
+
BitsAvailableInLastField =
getNextFieldOffsetInBytes() * 8 - (FieldOffset + FieldSize);
}
@@ -207,12 +209,22 @@
}
// Append tail padding if necessary.
- if (Layout.getSize() / 8 > getNextFieldOffsetInBytes())
- AppendPadding(getNextFieldOffsetInBytes(), AlignmentAsLLVMStruct);
+ AppendTailPadding(Layout.getSize());
return true;
}
+void CGRecordLayoutBuilder::AppendTailPadding(uint64_t RecordSize) {
+ assert(RecordSize % 8 == 0 && "Invalid record size!");
+
+ uint64_t RecordSizeInBytes = RecordSize / 8;
+ assert(getNextFieldOffsetInBytes() <= RecordSizeInBytes && "Size mismatch!");
+
+ unsigned NumPadBytes = RecordSizeInBytes - getNextFieldOffsetInBytes();
+ AppendBytes(NumPadBytes);
+}
+
+
void CGRecordLayoutBuilder::AppendField(uint64_t FieldOffsetInBytes,
const llvm::Type *FieldTy) {
AlignmentAsLLVMStruct = std::max(AlignmentAsLLVMStruct,
@@ -256,10 +268,8 @@
return;
const llvm::Type *Ty = llvm::Type::Int8Ty;
- if (NumBytes > 1) {
- // FIXME: Use a VMContext.
+ if (NumBytes > 1)
Ty = llvm::ArrayType::get(Ty, NumBytes);
- }
// Append the padding field
AppendField(getNextFieldOffsetInBytes(), Ty);
@@ -294,7 +304,6 @@
// FIXME: Once this works well enough, enable it.
return 0;
- // FIXME: Use a VMContext.
const llvm::Type *Ty = llvm::StructType::get(Builder.FieldTypes,
Builder.Packed);
Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.h?rev=77189&r1=77188&r2=77189&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.h (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.h Mon Jul 27 09:55:54 2009
@@ -111,6 +111,10 @@
/// AppendBytes - Append a given number of bytes to the record.
void AppendBytes(uint64_t NumBytes);
+ /// AppendTailPadding - Append enough tail padding so that the type will have
+ /// the passed size.
+ void AppendTailPadding(uint64_t RecordSize);
+
/// getNextFieldOffsetInBytes - returns where the next field offset is.
uint64_t getNextFieldOffsetInBytes() const;
More information about the cfe-commits
mailing list