Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
145 | halyavin | 1 | #include |
2 | #include |
||
3 | |||
4 | #define NB_ITS 1000000 |
||
5 | //#define NB_ITS 1 |
||
6 | #define TAB_SIZE 100 |
||
7 | |||
8 | int tab[TAB_SIZE]; |
||
9 | int ret_sum; |
||
10 | char tab3[256]; |
||
11 | |||
12 | int test1(void) |
||
13 | { |
||
14 | int i, sum = 0; |
||
15 | for(i=0;i |
||
16 | sum += tab[i]; |
||
17 | } |
||
18 | return sum; |
||
19 | } |
||
20 | |||
21 | /* error */ |
||
22 | int test2(void) |
||
23 | { |
||
24 | int i, sum = 0; |
||
25 | for(i=0;i |
||
26 | sum += tab[i]; |
||
27 | } |
||
28 | return sum; |
||
29 | } |
||
30 | |||
31 | /* actually, profiling test */ |
||
32 | int test3(void) |
||
33 | { |
||
34 | int sum; |
||
35 | int i, it; |
||
36 | |||
37 | sum = 0; |
||
38 | for(it=0;it |
||
39 | for(i=0;i |
||
40 | sum += tab[i]; |
||
41 | } |
||
42 | } |
||
43 | return sum; |
||
44 | } |
||
45 | |||
46 | /* ok */ |
||
47 | int test4(void) |
||
48 | { |
||
49 | int i, sum = 0; |
||
50 | int *tab4; |
||
51 | |||
52 | tab4 = malloc(20 * sizeof(int)); |
||
53 | for(i=0;i<20;i++) { |
||
54 | sum += tab4[i]; |
||
55 | } |
||
56 | free(tab4); |
||
57 | |||
58 | return sum; |
||
59 | } |
||
60 | |||
61 | /* error */ |
||
62 | int test5(void) |
||
63 | { |
||
64 | int i, sum = 0; |
||
65 | int *tab4; |
||
66 | |||
67 | tab4 = malloc(20 * sizeof(int)); |
||
68 | for(i=0;i<21;i++) { |
||
69 | sum += tab4[i]; |
||
70 | } |
||
71 | free(tab4); |
||
72 | |||
73 | return sum; |
||
74 | } |
||
75 | |||
76 | /* error */ |
||
77 | /* XXX: currently: bug */ |
||
78 | int test6(void) |
||
79 | { |
||
80 | int i, sum = 0; |
||
81 | int *tab4; |
||
82 | |||
83 | tab4 = malloc(20 * sizeof(int)); |
||
84 | free(tab4); |
||
85 | for(i=0;i<21;i++) { |
||
86 | sum += tab4[i]; |
||
87 | } |
||
88 | |||
89 | return sum; |
||
90 | } |
||
91 | |||
92 | /* error */ |
||
93 | int test7(void) |
||
94 | { |
||
95 | int i, sum = 0; |
||
96 | int *p; |
||
97 | |||
98 | for(i=0;i |
||
99 | p = &tab[i]; |
||
100 | if (i == TAB_SIZE) |
||
101 | printf("i=%d %x\n", i, p); |
||
102 | sum += *p; |
||
103 | } |
||
104 | return sum; |
||
105 | } |
||
106 | |||
107 | /* ok */ |
||
108 | int test8(void) |
||
109 | { |
||
110 | int i, sum = 0; |
||
111 | int tab[10]; |
||
112 | |||
113 | for(i=0;i<10;i++) { |
||
114 | sum += tab[i]; |
||
115 | } |
||
116 | return sum; |
||
117 | } |
||
118 | |||
119 | /* error */ |
||
120 | int test9(void) |
||
121 | { |
||
122 | int i, sum = 0; |
||
123 | char tab[10]; |
||
124 | |||
125 | for(i=0;i<11;i++) { |
||
126 | sum += tab[i]; |
||
127 | } |
||
128 | return sum; |
||
129 | } |
||
130 | |||
131 | /* ok */ |
||
132 | int test10(void) |
||
133 | { |
||
134 | char tab[10]; |
||
135 | char tab1[10]; |
||
136 | |||
137 | memset(tab, 0, 10); |
||
138 | memcpy(tab, tab1, 10); |
||
139 | memmove(tab, tab1, 10); |
||
140 | return 0; |
||
141 | } |
||
142 | |||
143 | /* error */ |
||
144 | int test11(void) |
||
145 | { |
||
146 | char tab[10]; |
||
147 | |||
148 | memset(tab, 0, 11); |
||
149 | return 0; |
||
150 | } |
||
151 | |||
152 | /* error */ |
||
153 | int test12(void) |
||
154 | { |
||
155 | void *ptr; |
||
156 | ptr = malloc(10); |
||
157 | free(ptr); |
||
158 | free(ptr); |
||
159 | return 0; |
||
160 | } |
||
161 | |||
162 | /* error */ |
||
163 | int test13(void) |
||
164 | { |
||
165 | char pad1 = 0; |
||
166 | char tab[10]; |
||
167 | char pad2 = 0; |
||
168 | memset(tab, 'a', sizeof(tab)); |
||
169 | return strlen(tab); |
||
170 | } |
||
171 | |||
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, |
||
187 | }; |
||
188 | |||
189 | int main(int argc, char **argv) |
||
190 | { |
||
191 | int index; |
||
192 | int (*ftest)(void); |
||
193 | |||
194 | if (argc < 2) { |
||
195 | printf("usage: boundtest n\n" |
||
196 | "test TCC bound checking system\n" |
||
197 | ); |
||
198 | exit(1); |
||
199 | } |
||
200 | |||
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(); |
||
207 | |||
208 | return 0; |
||
209 | } |
||
210 | |||
211 | /* |
||
212 | * without bound 0.77 s |
||
213 | * with bounds 4.73 |
||
214 | */>11;i++)>10;i++)>21;i++)>21;i++)>20;i++)> |