Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm < %s -o - |
Eli Friedman | a04a153 | 2008-05-30 19:58:50 +0000 | [diff] [blame] | 2 | |
| 3 | // A nice and complicated initialization example with unions from Python |
| 4 | typedef int Py_ssize_t; |
| 5 | |
| 6 | typedef union _gc_head { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 7 | struct { |
| 8 | union _gc_head *gc_next; |
| 9 | union _gc_head *gc_prev; |
| 10 | Py_ssize_t gc_refs; |
| 11 | } gc; |
| 12 | long double dummy; /* force worst-case alignment */ |
Eli Friedman | a04a153 | 2008-05-30 19:58:50 +0000 | [diff] [blame] | 13 | } PyGC_Head; |
| 14 | |
| 15 | struct gc_generation { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 16 | PyGC_Head head; |
| 17 | int threshold; /* collection threshold */ |
| 18 | int count; /* count of allocations or collections of younger |
| 19 | generations */ |
Eli Friedman | a04a153 | 2008-05-30 19:58:50 +0000 | [diff] [blame] | 20 | }; |
| 21 | |
| 22 | #define NUM_GENERATIONS 3 |
| 23 | #define GEN_HEAD(n) (&generations[n].head) |
| 24 | |
| 25 | /* linked lists of container objects */ |
| 26 | struct gc_generation generations[NUM_GENERATIONS] = { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 27 | /* PyGC_Head, threshold, count */ |
| 28 | {{{GEN_HEAD(0), GEN_HEAD(0), 0}}, 700, 0}, |
| 29 | {{{GEN_HEAD(1), GEN_HEAD(1), 0}}, 10, 0}, |
| 30 | {{{GEN_HEAD(2), GEN_HEAD(2), 0}}, 10, 0}, |
Eli Friedman | a04a153 | 2008-05-30 19:58:50 +0000 | [diff] [blame] | 31 | }; |