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