struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / bug-3166.c
blob732a8a72c8a31ce4532eafb0b1d138065edab269
1 /*
2 bug-3166.c
3 */
5 #include <testfwk.h>
7 #define NDEBUG
8 #include <assert.h>
9 #include <stddef.h>
11 #if !defined(__SDCC_pdk13) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) && !(defined(__SDCC_mcs51) && (defined(__SDCC_MODEL_SMALL) || defined(__SDCC_MODEL_MEDIUM))) // Lack of memory
13 enum { RULES_MAX = 4 };
15 typedef int* rule_seq;
16 typedef rule_seq* rule_alts;
18 int rule_seq_lists[] = { 3, 1, 3, -1,
19 2, -1,
20 2, 1, -1 };
21 rule_seq rule_alts_lists[] = { &rule_seq_lists[0], NULL,
22 &rule_seq_lists[4], &rule_seq_lists[6], NULL };
23 rule_alts rule[RULES_MAX] = { &rule_alts_lists[0],
24 &rule_alts_lists[2],
25 NULL,
26 NULL };
27 char rule_terminal[RULES_MAX] = { 0, 0, 'a', 'b' };
29 enum { GOOD_POOL_MAX = 64,
30 BAD_STACK_MAX = 16 };
32 struct good {
33 rule_seq seq;
34 struct good* prev;
35 } good_pool[GOOD_POOL_MAX+1]; /* +1 to avoid incorrect SDCC warning */
37 struct bad {
38 rule_alts alts;
39 char* old_pos;
40 struct good* old_good;
41 } bad_stack[BAD_STACK_MAX+1]; /* +1 to avoid incorrect SDCC warning */
43 int match(char* pos_arg)
45 static char* pos;
46 static struct bad* bad_sp;
47 #ifdef AVOID_SCCZ80_BUG
48 #define static
49 #endif
50 static struct good* good_alloc;
51 static struct good* good;
52 static struct good* rgood;
53 static rule_alts alts;
54 #ifdef AVOID_SDCC_BUG
55 rule_seq seq;
56 #else
57 static rule_seq seq; /* this line breaks SDCC */
58 #endif
59 #ifdef AVOID_SCCZ80_BUG
60 #undef static
61 #endif
62 static char* rpos;
63 static int ruleno;
64 pos = pos_arg;
65 bad_sp = bad_stack;
66 good_alloc = good_pool;
67 good = NULL;
68 rgood = NULL;
69 alts = NULL;
70 seq = NULL;
71 rpos = NULL;
72 ruleno = 0;
74 while (1) {
75 assert(bad_sp < &bad_stack[BAD_STACK_MAX]);
76 assert(good_alloc < &good_pool[GOOD_POOL_MAX]);
77 assert(ruleno >= 0 && ruleno < RULES_MAX);
78 alts = rule[ruleno];
79 if (alts) {
80 rgood = good;
81 rpos = pos;
82 goto first_alt;
84 assert(rule_terminal[ruleno]);
85 if (*pos != rule_terminal[ruleno])
86 goto failure;
87 ++pos;
88 success:
89 if (!good) {
90 if (*pos != '\0')
91 goto failure;
92 return 1;
94 seq = good->seq;
95 good = good->prev;
96 ruleno = *seq++;
97 if (*seq >= 0) {
98 struct good* ngood = good_alloc++;
99 ngood->seq = seq;
100 ngood->prev = good;
101 good = ngood;
103 continue;
104 failure:
105 if (bad_sp == bad_stack) {
106 return 0;
108 --bad_sp;
109 alts = bad_sp->alts;
110 rgood = bad_sp->old_good;
111 rpos = bad_sp->old_pos;
112 first_alt:
113 good = good_alloc++;
114 good->seq = *alts++;
115 good->prev = rgood;
116 pos = rpos;
117 if (*alts) {
118 bad_sp->alts = alts;
119 bad_sp->old_good = rgood;
120 bad_sp->old_pos = pos;
121 ++bad_sp;
123 goto success;
126 #endif
128 void
129 testBug(void)
131 #if !defined(__SDCC_pdk13) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) && !(defined(__SDCC_mcs51) && (defined(__SDCC_MODEL_SMALL) || defined(__SDCC_MODEL_MEDIUM))) // Lack of memory
132 ASSERT (match("baaab"));
133 #endif