Debian Codegraph @

gcc/testsuite/gcc.c-torture/execute/20051113-1.c

raw
1 extern void abort(void);
2 extern void *malloc(__SIZE_TYPE__);
3 extern void *memset(void *, int, __SIZE_TYPE__);
4 typedef struct
5 {
6 short a;
7 unsigned short b;
8 unsigned short c;
9 unsigned long long Count;
10 long long Count2;
11 } __attribute__((packed)) Struct1;
12
13 typedef struct
14 {
15 short a;
16 unsigned short b;
17 unsigned short c;
18 unsigned long long d;
19 long long e;
20 long long f;
21 } __attribute__((packed)) Struct2;
22
23 typedef union
24 {
25 Struct1 a;
26 Struct2 b;
27 } Union;
28
29 typedef struct
30 {
31 int Count;
32 Union List[0];
33 } __attribute__((packed)) Struct3;
34
35 unsigned long long Sum (Struct3 *instrs) __attribute__((noinline));
36 unsigned long long Sum (Struct3 *instrs)
37 {
38 unsigned long long count = 0;
39 int i;
40
41 for (i = 0; i < instrs->Count; i++) {
42 count += instrs->List[i].a.Count;
43 }
44 return count;
45 }
46 long long Sum2 (Struct3 *instrs) __attribute__((noinline));
47 long long Sum2 (Struct3 *instrs)
48 {
49 long long count = 0;
50 int i;
51
52 for (i = 0; i < instrs->Count; i++) {
53 count += instrs->List[i].a.Count2;
54 }
55 return count;
56 }
57 int main(void) {
58 Struct3 *p = malloc (sizeof (int) + 3 * sizeof(Union));
59 memset(p, 0, sizeof(int) + 3*sizeof(Union));
60 p->Count = 3;
61 p->List[0].a.Count = 555;
62 p->List[1].a.Count = 999;
63 p->List[2].a.Count = 0x101010101ULL;
64 p->List[0].a.Count2 = 555;
65 p->List[1].a.Count2 = 999;
66 p->List[2].a.Count2 = 0x101010101LL;
67 if (Sum(p) != 555 + 999 + 0x101010101ULL)
68 abort();
69 if (Sum2(p) != 555 + 999 + 0x101010101LL)
70 abort();
71 return 0;
72 }