2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.abi / aggregates.C
blob187c30b54d6ab664db95b36f193c340632a74194
1 // { dg-do run { target i?86-*-linux* i?86-*-freebsd* } }
2 // { dg-options "-malign-double" }
3 // Origin: Alex Samuel <samuel@codesourcery.com>
5 /* Test the data layout of C aggregates by checking aggregate size and
6    alignment and field offsets for compliance with the IA-64 ABI.  */
8 template<typename T>
9 inline unsigned
10 alignmentof ()
12   struct S
13   {
14     char start_;
15     T object_;
16   };
18   return (unsigned) & ((S *) 0)->object_;
21 /* Computes the alignment, in bytes, of TYPE.  */
23 #define alignof(type) (alignmentof<type> ())
25 /* Computes the offset of FIELD in AGGREGATE.  */
27 #define offsetof(aggregate, field) \
28   ((unsigned) (& ((aggregate*) 0)->field))
31 /* Structs S1, S2, S3, S4, and union U5 are taken from Intel, "IA-64
32    Software Conventions and Runtime Architecture Guide", version of
33    August 1999.  */
35 struct S1
37   char c;
40 struct S2
42   char c;
43   char d;
44   short s;
45   int n;
48 struct S3
50   char c;
51   short s;
54 struct S4
56   char c;
57   double d;
58   short s;
61 union U5
63   char c;
64   short s;
65   int j;
70 int
71 main ()
73   if (sizeof (struct S1)                !=  1)
74     return 1;
75   if (alignof (struct S1)               !=  1)
76     return 2;
77   if (offsetof (struct S1, c)           !=  0)
78     return 3;
79   
80   if (sizeof (struct S2)                !=  8)
81     return 4;
82   if (alignof (struct S2)               !=  4)
83     return 5;
84   if (offsetof (struct S2, c)           !=  0)
85     return 6;
86   if (offsetof (struct S2, d)           !=  1)
87     return 7;
88   if (offsetof (struct S2, s)           !=  2)
89     return 8;
90   if (offsetof (struct S2, n)           !=  4)
91     return 9;
92   
93   if (sizeof (struct S3)                !=  4)
94     return 10;
95   if (alignof (struct S3)               !=  2)
96     return 11;
97   if (offsetof (struct S3, c)           !=  0)
98     return 12;
99   if (offsetof (struct S3, s)           !=  2)
100     return 13;
101   
102   if (sizeof (struct S4)                != 24)
103     return 14;
104   if (alignof (struct S4)               !=  8)
105     return 15;
106   if (offsetof (struct S4, c)           !=  0)
107     return 16;
108   if (offsetof (struct S4, d)           !=  8)
109     return 17;
110   if (offsetof (struct S4, s)           != 16)
111     return 18;
112   
113   if (sizeof (union U5)                 !=  4)
114     return 19;
115   if (alignof (union U5)                !=  4)
116     return 20;
117   if (offsetof (union U5, c)            !=  0)
118     return 21;
119   if (offsetof (union U5, s)            !=  0)
120     return 22;
121   if (offsetof (union U5, j)            !=  0)
122     return 23;
123   
124   return 0;