History

add tests for cleanup loop

- Also fix some gcc warning

matthias committed 7 years ago

Commit cf3d2371 parent 14be3a12 files · +79 −2Browse files

Unified · Split

2 files
  1. tests/tests2/101_cleanup.c +45 −1
  2. tests/tests2/101_cleanup.expect +34 −1
tests/tests2/101_cleanup.c+45−1
@@ -149,10 +149,53 @@ int test3(void) { · 148 unmodified lines
149 return 0;149 return 0;
150}150}
151 151
152void cl(int *ip)
153{
154 printf("%d\n", *ip);
155}
156
157void loop_cleanups(void)
158{
159 __attribute__((cleanup(cl))) int l = 1000;
160
161 printf("-- loop 0 --\n");
162 for ( __attribute__((cleanup(cl))) int i = 0; i < 10; ++i) {
163 __attribute__((cleanup(cl))) int j = 100;
164 }
165
166 printf("-- loop 1 --\n");
167 for (__attribute__((cleanup(cl))) int i = 0; i < 10; ++i) {
168 __attribute__((cleanup(cl))) int j = 200;
169 continue;
170 }
171
172 printf("-- loop 2 --\n");
173 for (__attribute__((cleanup(cl))) int i = 0; i < 10; ++i) {
174 __attribute__((cleanup(cl))) int j = 300;
175 break;
176 }
177
178 printf("-- loop 3 --\n");
179 for (int i = 0; i < 2; ++i) {
180 __attribute__((cleanup(cl))) int j = 400;
181 switch (i) {
182 case 0:
183 continue;
184 default:
185 {
186 __attribute__((cleanup(cl))) int jj = 500;
187 break;
188 }
189 }
190 }
191 printf("after break\n");
192}
193
152int main()194int main()
153{195{
154 int i __attribute__ ((__cleanup__(check))) = 0, not_i;196 int i __attribute__ ((__cleanup__(check))) = 0, not_i;
155 int chk = 0;197 int chk = 0;
198 (void)not_i;
156 199
157 {200 {
158 __attribute__ ((__cleanup__(check_oh_i))) char oh_i = 'o', o = 'a';201 __attribute__ ((__cleanup__(check_oh_i))) char oh_i = 'o', o = 'a';
@@ -169,11 +212,12 @@ int main() · 10 unmodified lines
169 goto naaaaaaaa;212 goto naaaaaaaa;
170 }213 }
171 i = 105;214 i = 105;
172 printf("because what if free was call inside cleanup function\n", test());215 printf("because what if free was call inside cleanup function %s\n", test());
173 test_ret();216 test_ret();
174 test_ret2();217 test_ret2();
175 test2();218 test2();
176 test3();219 test3();
220 loop_cleanups();
177 return i;221 return i;
178}222}
179 223
tests/tests2/101_cleanup.expect+34−1
@@ -4,7 +4,7 @@ glob_i: 65536 · 3 unmodified lines
4oo: 2.6000004oo: 2.600000
5c: f5c: f
6str: I don't think this should be print(but gcc got it wrong too)6str: I don't think this should be print(but gcc got it wrong too)
7because what if free was call inside cleanup function7because what if free was call inside cleanup function I don't think this should be print(but gcc got it wrong too)
8should be print before8should be print before
9str: that9str: that
10str: this should appear only once10str: this should appear only once
@@ -15,6 +15,39 @@ str: one · 4 unmodified lines
15---- 115---- 1
16str: two16str: two
17str: three17str: three
18-- loop 0 --
19100
20100
21100
22100
23100
24100
25100
26100
27100
28100
2910
30-- loop 1 --
31200
32200
33200
34200
35200
36200
37200
38200
39200
40200
4110
42-- loop 2 --
43300
440
45-- loop 3 --
46400
47500
48400
49after break
501000
18---- 051---- 0
19---- 152---- 1
20str: plop53str: plop

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t