]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gcc.c-torture/execute/991014-1.c
991014-1.c: Use __SIZE_TYPE__ for size types.
[thirdparty/gcc.git] / gcc / testsuite / gcc.c-torture / execute / 991014-1.c
CommitLineData
b7fd6635 1
8d774623 2typedef __SIZE_TYPE__ Size_t;
b7fd6635 3
8d774623
OS
4#if __SIZEOF_LONG__ < __SIZEOF_POINTER__
5#define bufsize ((1LL << (8 * sizeof(Size_t) - 2))-256)
6#else
b7fd6635 7#define bufsize ((1L << (8 * sizeof(Size_t) - 2))-256)
8d774623 8#endif
b7fd6635
SC
9
10struct huge_struct
11{
12 short buf[bufsize];
13 int a;
14 int b;
15 int c;
16 int d;
17};
18
19union huge_union
20{
21 int a;
22 char buf[bufsize];
23};
24
8d774623 25Size_t union_size()
b7fd6635
SC
26{
27 return sizeof(union huge_union);
28}
29
8d774623 30Size_t struct_size()
b7fd6635
SC
31{
32 return sizeof(struct huge_struct);
33}
34
8d774623 35Size_t struct_a_offset()
b7fd6635 36{
8d774623 37 return (Size_t)(&((struct huge_struct *) 0)->a);
b7fd6635
SC
38}
39
40int 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