[llvm-commits] CVS: llvm-gcc/gcc/llvm-types.c
Chris Lattner
lattner at cs.uiuc.edu
Thu Nov 3 22:18:42 PST 2005
Changes in directory llvm-gcc/gcc:
llvm-types.c updated: 1.30 -> 1.31
---
Log message:
This ugly patch fixes the regressions compiling namd and gcc on X86, suitable
for the 1.6 release. This can be solved in a more elegant way in the future.
---
Diffs of the changes: (+39 -3)
llvm-types.c | 42 +++++++++++++++++++++++++++++++++++++++---
1 files changed, 39 insertions(+), 3 deletions(-)
Index: llvm-gcc/gcc/llvm-types.c
diff -u llvm-gcc/gcc/llvm-types.c:1.30 llvm-gcc/gcc/llvm-types.c:1.31
--- llvm-gcc/gcc/llvm-types.c:1.30 Sat Sep 24 15:55:31 2005
+++ llvm-gcc/gcc/llvm-types.c Fri Nov 4 00:18:30 2005
@@ -120,10 +120,11 @@
return PrimitiveAlignments[Ty->ID];
}
case ArrayTyID:
- //assert(Ty->x.Array.Alignment && "Array does not have alignment set!");
+ /*assert(Ty->x.Array.Alignment && "Array does not have alignment set!");*/
return Ty->x.Array.Alignment ? Ty->x.Array.Alignment : 4;
case StructTyID:
- //assert(Ty->x.Struct.Alignment && "Struct does not have alignment set!");
+ /*assert(Ty->x.Struct.Alignment && "Struct does not have alignment set!");
+ */
return Ty->x.Struct.Alignment ? Ty->x.Struct.Alignment : 4;
default:
fprintf(stderr, "ERROR: Type doesn't have size: ");
@@ -752,7 +753,12 @@
llvm_type *Ty = llvm_type_get_from_tree(TREE_TYPE(field));
/* Get the starting offset in the record... */
unsigned StartOffset = GetFieldOffset(field); /* In bits */
+#ifdef LLVM_TARGET_MAX_ALIGN_IS_POINTER_SIZE
unsigned ByteAlignment = llvm_type_get_alignment(Ty);
+#else
+ unsigned BitAlignment = GetFieldAlignmentInBits(field);
+ unsigned ByteAlignment = (BitAlignment+7)/8;
+#endif
if (!TypeIsRecursivelyIntegral(Ty)) { /* Not an integral field? */
unsigned OrigSize = *Size;
@@ -767,6 +773,7 @@
* to ensure that the LLVM conception of where this element lands is the
* same as what GCC thinks.
*/
+#ifdef LLVM_TARGET_MAX_ALIGN_IS_POINTER_SIZE
if (*Size < StartOffset/8) {
unsigned PadBytes = StartOffset/8 - OrigSize;
if (PadBytes == 1)
@@ -778,6 +785,17 @@
++*Idx;
*Size = OrigSize + PadBytes;
}
+#else
+ if (*Size < StartOffset/8)
+ /* Only fix things if it is because of this "magic padding" */
+ if (*Size + ByteAlignment == StartOffset/8) {
+ ElementTys[*Idx] = UByteTy; /* Random pad element */
+ ElementOffsets[*Idx] = *Size;
+ ElementAlignments[*Idx] = 1;
+ ++*Idx;
+ *Size = StartOffset/8;
+ }
+#endif
#if 0 /* FIXME: This assertion should be kept!!! */
assert(*Size == StartOffset/8 &&
@@ -796,10 +814,16 @@
unsigned FieldCByteAlignment = (FieldCBitAlignment+7)/8;
/* Is it attempting to align the current offset to some value? */
if (DeclSize == 0) {
+#ifdef LLVM_TARGET_MAX_ALIGN_IS_POINTER_SIZE
NumPads = FieldCByteAlignment - (*Size % FieldCByteAlignment);
if (NumPads == FieldCByteAlignment) NumPads = 0;
assert((*Size+NumPads) % FieldCByteAlignment == 0 &&
"Incorrect padding calc?");
+#else
+ NumPads = ByteAlignment - (*Size % ByteAlignment);
+ if (NumPads == ByteAlignment) NumPads = 0;
+ assert((*Size+NumPads) % ByteAlignment == 0 && "Incorrect padding calc?");
+#endif
#if DEBUG_STRUCT_LAYOUT
fprintf(stderr, "Anon field: align=%db pads = %d ",
FieldCByteAlignment, NumPads);
@@ -839,7 +863,8 @@
int HasSignedField;
unsigned StartByte;
- if (ElSizeInBits) ElSizeInBits = MAX(ElSizeInBits, FieldCBitAlignment);
+ if (ElSizeInBits)
+ ElSizeInBits = MAX(ElSizeInBits, FieldCBitAlignment);
HasSignedField = !TREE_UNSIGNED(TREE_TYPE(field));
@@ -906,6 +931,7 @@
* to ensure that the LLVM conception of where this element lands is the
* same as what GCC thinks.
*/
+#ifdef LLVM_TARGET_MAX_ALIGN_IS_POINTER_SIZE
if (((*Size + ByteAlignment - 1) & ~(ByteAlignment-1)) < StartOffset/8) {
unsigned PadBytes = StartOffset/8 - *Size;
if (PadBytes == 1)
@@ -917,6 +943,7 @@
++*Idx;
*Size = *Size + PadBytes;
}
+#endif
/* Check to see if there is "magic padding" that got inserted into the
* structure. This can happen, for example, when the C++ ABI declares that
@@ -1472,6 +1499,7 @@
* elements so that the LLVM code will have the right size for the
* structure.
*/
+#ifdef LLVM_TARGET_MAX_ALIGN_IS_POINTER_SIZE
if (TYPE_SIZE(type) && TREE_CODE(TYPE_SIZE(type)) == INTEGER_CST) {
unsigned GCCTypeSize = ((unsigned)TREE_INT_CST_LOW(TYPE_SIZE(type))+7)/8;
unsigned LLVMTypeSize, LLVMStructAlign = 1, i;
@@ -1506,6 +1534,14 @@
Size += PadBytes;
}
}
+#else
+ /* Empty C++ structures == { ubyte } in LLVM so that sizes are correct. */
+ if (Idx == 0 && (int)TREE_INT_CST_LOW(TYPE_SIZE(type)) == 8) {
+ StructElements[0] = UByteTy;
+ ElementOffsets[0] = 0;
+ ++Idx;
+ }
+#endif
/* End of the hack, set the real number of elements. */
Result->NumElements = Idx;
More information about the llvm-commits
mailing list