This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] C++ ABI fix - bitfield layout on IA-32 (take 2)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: rth at redhat dot com, jh at suse dot cz
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 5 Aug 2002 15:58:04 +0200
- Subject: [PATCH] C++ ABI fix - bitfield layout on IA-32 (take 2)
- References: <20020805133754.D20867@sunsite.ms.mff.cuni.cz>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Mon, Aug 05, 2002 at 01:37:54PM +0200, Jakub Jelinek wrote:
> Unfortunately, the testcase still fails on the __alignof__ (x) != 4
> check (regression from 3.0.x and earlier) - this was apparently broken
> on gcc HEAD already in Nov 2001. Back into debugger.
Which is of course silly thing to test, because that doesn't
matter for binary compatibility. Lots of __alignof__ for toplevel objects
changed between gcc versions. What matters if its __alignof__ when
embedded in some other structure is correct.
> Concerning __m64, I haven't seen anything done, but don't have icc
> to verify. The thread which talks about this is
> http://gcc.gnu.org/ml/gcc-patches/2002-06/msg01427.html
This still applies. Any ideas? Should we
just use __attribute__((aligned(8))) for __m64 type?
Below is updated patch with a couple of new tests.
I've run consistency.vlad on this compiler and it gave identical output to
an older 3.2 branch compiler, bootstrap and normal
regression testing pending, ok to commit if they succeed?
2002-08-05 Jakub Jelinek <jakub@redhat.com>
* config/i386/i386.c (x86_field_alignment): Don't check
TARGET_ALIGN_DOUBLE for the second time.
Apply min for all MODE_INT and MODE_CLASS_INT modes.
* g++.dg/abi/bitfield3.C: New test.
--- gcc/config/i386/i386.c.jj 2002-07-27 01:31:05.000000000 +0200
+++ gcc/config/i386/i386.c 2002-08-05 13:31:53.000000000 +0200
@@ -12644,10 +12644,9 @@ x86_field_alignment (field, computed)
return computed;
mode = TYPE_MODE (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
? get_inner_array_type (field) : TREE_TYPE (field));
- if ((mode == DFmode || mode == DCmode
- || mode == DImode || mode == CDImode)
- && !TARGET_ALIGN_DOUBLE)
+ if (mode == DFmode || mode == DCmode
+ || GET_MODE_CLASS (mode) == MODE_INT
+ || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
return MIN (32, computed);
return computed;
}
-
--- gcc/testsuite/g++.dg/abi/bitfield3.C.jj 2002-08-05 13:47:02.000000000 +0200
+++ gcc/testsuite/g++.dg/abi/bitfield3.C 2002-08-05 15:59:57.000000000 +0200
@@ -0,0 +1,80 @@
+// Test for oversized bitfield alignment in structs on IA-32
+// { dg-do run { i?86-*-* } }
+// { dg-options "-O2" }
+
+struct A
+{
+ char a;
+ int b : 224; // { dg-warning "exceeds its type" "" }
+ char c;
+} a, a4[4];
+
+struct B
+{
+ char d;
+ A e;
+ char f;
+} b;
+
+struct C
+{
+ char g;
+ long long h : 64;
+ char i;
+} c, c4[4];
+
+struct D
+{
+ char j;
+ C k;
+ char l;
+} d;
+
+struct E
+{
+ char m;
+ long long n : 160; // { dg-warning "exceeds its type" "" }
+ char o;
+} e, e4[4];
+
+struct F
+{
+ char p;
+ E q;
+ char r;
+} f;
+
+int main (void)
+{
+ if (&a.c - &a.a != 32)
+ return 1;
+ if (sizeof (a) != 36)
+ return 2;
+ if (sizeof (a4) != 4 * 36)
+ return 3;
+ if (sizeof (b) != 2 * 4 + 36)
+ return 4;
+ if (__alignof__ (b.e) != 4)
+ return 5;
+ if (&c.i - &c.g != 16)
+ return 6;
+ if (sizeof (c) != 24)
+ return 7;
+ if (sizeof (c4) != 4 * 24)
+ return 8;
+ if (sizeof (d) != 2 * 8 + 24)
+ return 9;
+ if (__alignof__ (d.k) != 8)
+ return 10;
+ if (&e.o - &e.m != 28)
+ return 11;
+ if (sizeof (e) != 32)
+ return 12;
+ if (sizeof (e4) != 4 * 32)
+ return 13;
+ if (sizeof (f) != 2 * 8 + 32)
+ return 14;
+ if (__alignof__ (f.q) != 8)
+ return 15;
+ return 0;
+}
Jakub