added alloca
[tinycc.git] / boundtest.c
blob9bc982803dfa45b6464034e6b58779e80eae5bb3
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 (*table_test[])(void) = {
173 test1,
174 test1,
175 test2,
176 test3,
177 test4,
178 test5,
179 test6,
180 test7,
181 test8,
182 test9,
183 test10,
184 test11,
185 test12,
186 test13,
189 int main(int argc, char **argv)
191 int index;
192 int (*ftest)(void);
194 if (argc < 2) {
195 printf("usage: boundtest n\n"
196 "test TCC bound checking system\n"
198 exit(1);
201 index = 0;
202 if (argc >= 2)
203 index = atoi(argv[1]);
204 /* well, we also use bounds on this ! */
205 ftest = table_test[index];
206 ftest();
208 return 0;
212 * without bound 0.77 s
213 * with bounds 4.73