small change to previous whitespace-only commit
[tinycc/miki.git] / tests / boundtest.c
blobc2b29532029d5facf9e51f8b6d82c8c10030e233
1 #include <stdlib.h>
2 #include <stdio.h>
4 #define NB_ITS 1000000
5 //#define NB_ITS 1
6 #define TAB_SIZE 100
8 int tab[TAB_SIZE];
9 int ret_sum;
10 char tab3[256];
12 int test1(void)
14 int i, sum = 0;
15 for(i=0;i<TAB_SIZE;i++) {
16 sum += tab[i];
18 return sum;
21 /* error */
22 int test2(void)
24 int i, sum = 0;
25 for(i=0;i<TAB_SIZE + 1;i++) {
26 sum += tab[i];
28 return sum;
31 /* actually, profiling test */
32 int test3(void)
34 int sum;
35 int i, it;
37 sum = 0;
38 for(it=0;it<NB_ITS;it++) {
39 for(i=0;i<TAB_SIZE;i++) {
40 sum += tab[i];
43 return sum;
46 /* ok */
47 int test4(void)
49 int i, sum = 0;
50 int *tab4;
52 tab4 = malloc(20 * sizeof(int));
53 for(i=0;i<20;i++) {
54 sum += tab4[i];
56 free(tab4);
58 return sum;
61 /* error */
62 int test5(void)
64 int i, sum = 0;
65 int *tab4;
67 tab4 = malloc(20 * sizeof(int));
68 for(i=0;i<21;i++) {
69 sum += tab4[i];
71 free(tab4);
73 return sum;
76 /* error */
77 /* XXX: currently: bug */
78 int test6(void)
80 int i, sum = 0;
81 int *tab4;
83 tab4 = malloc(20 * sizeof(int));
84 free(tab4);
85 for(i=0;i<21;i++) {
86 sum += tab4[i];
89 return sum;
92 /* error */
93 int test7(void)
95 int i, sum = 0;
96 int *p;
98 for(i=0;i<TAB_SIZE + 1;i++) {
99 p = &tab[i];
100 if (i == TAB_SIZE)
101 printf("i=%d %x\n", i, p);
102 sum += *p;
104 return sum;
107 /* ok */
108 int test8(void)
110 int i, sum = 0;
111 int tab[10];
113 for(i=0;i<10;i++) {
114 sum += tab[i];
116 return sum;
119 /* error */
120 int test9(void)
122 int i, sum = 0;
123 char tab[10];
125 for(i=0;i<11;i++) {
126 sum += tab[i];
128 return sum;
131 /* ok */
132 int test10(void)
134 char tab[10];
135 char tab1[10];
137 memset(tab, 0, 10);
138 memcpy(tab, tab1, 10);
139 memmove(tab, tab1, 10);
140 return 0;
143 /* error */
144 int test11(void)
146 char tab[10];
148 memset(tab, 0, 11);
149 return 0;
152 /* error */
153 int test12(void)
155 void *ptr;
156 ptr = malloc(10);
157 free(ptr);
158 free(ptr);
159 return 0;
162 /* error */
163 int test13(void)
165 char pad1 = 0;
166 char tab[10];
167 char pad2 = 0;
168 memset(tab, 'a', sizeof(tab));
169 return strlen(tab);
172 int test14(void)
174 char *p = alloca(TAB_SIZE);
175 memset(p, 'a', TAB_SIZE);
176 p[TAB_SIZE-1] = 0;
177 return strlen(p);
180 /* error */
181 int test15(void)
183 char *p = alloca(TAB_SIZE-1);
184 memset(p, 'a', TAB_SIZE);
185 p[TAB_SIZE-1] = 0;
186 return strlen(p);
189 int (*table_test[])(void) = {
190 test1,
191 test1,
192 test2,
193 test3,
194 test4,
195 test5,
196 test6,
197 test7,
198 test8,
199 test9,
200 test10,
201 test11,
202 test12,
203 test13,
204 test14,
205 test15,
208 int main(int argc, char **argv)
210 int index;
211 int (*ftest)(void);
213 if (argc < 2) {
214 printf("usage: boundtest n\n"
215 "test TCC bound checking system\n"
217 exit(1);
220 index = 0;
221 if (argc >= 2)
222 index = atoi(argv[1]);
223 /* well, we also use bounds on this ! */
224 ftest = table_test[index];
225 ftest();
227 return 0;
231 * without bound 0.77 s
232 * with bounds 4.73