OSDN Git Service

Backported from mainline
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.c-torture / execute / 991014-1.c
1
2 typedef __SIZE_TYPE__ Size_t;
3
4 #if __SIZEOF_LONG__ < __SIZEOF_POINTER__
5 #define bufsize ((1LL << (8 * sizeof(Size_t) - 2))-256)
6 #else
7 #define bufsize ((1L << (8 * sizeof(Size_t) - 2))-256)
8 #endif
9
10 struct huge_struct
11 {
12   short buf[bufsize];
13   int a;
14   int b;
15   int c;
16   int d;
17 };
18
19 union huge_union
20 {
21   int a;
22   char buf[bufsize];
23 };
24
25 Size_t union_size()
26 {
27   return sizeof(union huge_union);
28 }
29
30 Size_t struct_size()
31 {
32   return sizeof(struct huge_struct);
33 }
34
35 Size_t struct_a_offset()
36 {
37   return (Size_t)(&((struct huge_struct *) 0)->a);
38 }
39
40 int main()
41 {
42   /* Check the exact sizeof value. bufsize is aligned on 256b. */
43   if (union_size() != sizeof(char) * bufsize)
44     abort();
45
46   if (struct_size() != sizeof(short) * bufsize + 4*sizeof(int))
47     abort();
48
49   if (struct_a_offset() < sizeof(short) * bufsize)
50     abort();  
51
52   return 0;
53 }
54