diff --git a/tests/tests2/101_cleanup.c b/tests/tests2/101_cleanup.c index 14ff3bd6..de5dca27 100644 --- a/tests/tests2/101_cleanup.c +++ b/tests/tests2/101_cleanup.c @@ -149,10 +149,53 @@ int test3(void) { return 0; } +void cl(int *ip) +{ + printf("%d\n", *ip); +} + +void loop_cleanups(void) +{ + __attribute__((cleanup(cl))) int l = 1000; + + printf("-- loop 0 --\n"); + for ( __attribute__((cleanup(cl))) int i = 0; i < 10; ++i) { + __attribute__((cleanup(cl))) int j = 100; + } + + printf("-- loop 1 --\n"); + for (__attribute__((cleanup(cl))) int i = 0; i < 10; ++i) { + __attribute__((cleanup(cl))) int j = 200; + continue; + } + + printf("-- loop 2 --\n"); + for (__attribute__((cleanup(cl))) int i = 0; i < 10; ++i) { + __attribute__((cleanup(cl))) int j = 300; + break; + } + + printf("-- loop 3 --\n"); + for (int i = 0; i < 2; ++i) { + __attribute__((cleanup(cl))) int j = 400; + switch (i) { + case 0: + continue; + default: + { + __attribute__((cleanup(cl))) int jj = 500; + break; + } + } + } + printf("after break\n"); +} + int main() { int i __attribute__ ((__cleanup__(check))) = 0, not_i; int chk = 0; + (void)not_i; { __attribute__ ((__cleanup__(check_oh_i))) char oh_i = 'o', o = 'a'; @@ -169,11 +212,12 @@ int main() goto naaaaaaaa; } i = 105; - printf("because what if free was call inside cleanup function\n", test()); + printf("because what if free was call inside cleanup function %s\n", test()); test_ret(); test_ret2(); test2(); test3(); + loop_cleanups(); return i; } diff --git a/tests/tests2/101_cleanup.expect b/tests/tests2/101_cleanup.expect index a5a76a8a..84960cd5 100644 --- a/tests/tests2/101_cleanup.expect +++ b/tests/tests2/101_cleanup.expect @@ -4,7 +4,7 @@ glob_i: 65536 oo: 2.600000 c: f str: I don't think this should be print(but gcc got it wrong too) -because what if free was call inside cleanup function +because what if free was call inside cleanup function I don't think this should be print(but gcc got it wrong too) should be print before str: that str: this should appear only once @@ -15,6 +15,39 @@ str: one ---- 1 str: two str: three +-- loop 0 -- +100 +100 +100 +100 +100 +100 +100 +100 +100 +100 +10 +-- loop 1 -- +200 +200 +200 +200 +200 +200 +200 +200 +200 +200 +10 +-- loop 2 -- +300 +0 +-- loop 3 -- +400 +500 +400 +after break +1000 ---- 0 ---- 1 str: plop