Some consistency changes to library & headers flags.
[splint-patched.git] / test / duffextensive.c
blob45e6be7d7d2e300d5e4cff42a384c1d51833da92
1 void copy0 (char *to, char* from, int count)
3 int n = (count+7)/8;
4 switch (count%8) do {
5 case 0: *to = *from++;
6 case 7: *to = *from++;
7 case 6: *to = *from++;
8 case 5: *to = *from++;
9 case 4: *to = *from++;
10 case 3: *to = *from++;
11 case 2: *to = *from++;
12 case 1: *to = *from++;
13 } while (--n>0);
16 void copy1 (char *to, char *from, int count)
18 int n = (count+7)/8;
19 switch (count%8) {
20 case 0: do {*to = *from++;
21 case 7: *to = *from++;
22 case 6: *to = *from++;
23 case 5: *to = *from++;
24 case 4: *to = *from++;
25 case 3: *to = *from++;
26 case 2: *to = *from++;
27 case 1: *to = *from++;
28 } while (--n>0);
32 void copy2 (char *to, char* from, int count)
34 int n = (count+7)/8;
35 switch (count%8) while (n-->0) {
36 case 0: *to = *from++;
37 case 7: *to = *from++;
38 case 6: *to = *from++;
39 case 5: *to = *from++;
40 case 4: *to = *from++;
41 case 3: *to = *from++;
42 case 2: *to = *from++;
43 case 1: *to = *from++;
47 void copy3 (char *to, char *from, int count)
49 int n = (count+7)/8;
50 switch (count%8) {
51 case 0: while (n-->0) {*to = *from++;
52 case 7: *to = *from++;
53 case 6: *to = *from++;
54 case 5: *to = *from++;
55 case 4: *to = *from++;
56 case 3: *to = *from++;
57 case 2: *to = *from++;
58 case 1: *to = *from++;
63 void copy4 (char *to, char* from, int count)
65 int n = (count+7)/8, i;
66 switch (count%8) for (i=0; i<n; i++) {
67 case 0: *to = *from++;
68 case 7: *to = *from++;
69 case 6: *to = *from++;
70 case 5: *to = *from++;
71 case 4: *to = *from++;
72 case 3: *to = *from++;
73 case 2: *to = *from++;
74 case 1: *to = *from++;
78 void copy5 (char *to, char *from, int count)
80 int n = (count+7)/8, i;
81 switch (count%8) {
82 case 0: for (i=0; i<n; i++) {*to = *from++;
83 case 7: *to = *from++;
84 case 6: *to = *from++;
85 case 5: *to = *from++;
86 case 4: *to = *from++;
87 case 3: *to = *from++;
88 case 2: *to = *from++;
89 case 1: *to = *from++;
94 /* The semantics of func{0,1,2} () are the same:
95 * if (foo%2 == 0), func(foo) returns 2;
96 * if (foo%2 == 1), func(foo) returns 13 -- the initialization of the loop
97 * is skipped, thus the loop behaves as if started from -11. */
99 int func0 (int foo)
101 int bar = 0, i = -11;
102 switch (foo%2)
104 case 0:
105 i=0;
106 for(;i<2;) {
107 case 1:
108 bar += 1;
109 i++;
112 return bar;
115 int func1 (int foo)
117 int bar = 0, i = -11;
118 switch (foo%2)
120 case 0:
121 i=0;
122 while(i<2) {
123 case 1:
124 bar += 1;
125 i++;
128 return bar;
131 int func2 (int foo)
133 int bar = 0, i = -11;
134 switch (foo%2)
136 case 0:
137 i=0;
138 do {
139 case 1:
140 bar += 1;
141 i++;
142 } while (i<2);
144 return bar;
148 main(void)
150 if (func0 (7) != func1 (11))
151 return 1;
152 if (func0 (4) != func2 (8))
153 return 1;
154 if (func1 (6) != func2 (2))
155 return 1;
157 return 0;
160 /* The following two routines aren't true Duff's device implementations, but,
161 * inspired by it, test the imbrication of switch with if/else block. */
162 int func3 (int x)
164 int i = 0;
165 switch(x%2) {
166 case 0:
167 i=x;
168 if (i<10) {
169 /*@fallthrough@*/
170 default:
171 i++;
175 return i;
178 int func4 (int x)
180 int i = 0;
181 switch(x%2) {
182 case 0:
183 if (i<10) {
184 i=x;
186 else {
187 /*@fallthrough@*/
188 default:
189 i++;
193 return i;