Showing the changes to tests (2 of 2 files). Show all
Unified · Split
| @@ -0,0 +1,124 @@ | ||
| 1 | +#include <tcclib.h> | |
| 2 | + | |
| 3 | +void check2(char **hum); | |
| 4 | + | |
| 5 | +void check(int *j) | |
| 6 | +{ | |
| 7 | + char * __attribute__ ((cleanup(check2))) stop_that = "wololo"; | |
| 8 | + int chk = 0; | |
| 9 | + | |
| 10 | + { | |
| 11 | + char * __attribute__ ((cleanup(check2))) stop_that = "plop"; | |
| 12 | + | |
| 13 | + { | |
| 14 | + non_plopage: | |
| 15 | + printf("---- %d\n", chk); | |
| 16 | + } | |
| 17 | + if (!chk) { | |
| 18 | + chk = 1; | |
| 19 | + goto non_plopage; | |
| 20 | + } | |
| 21 | + } | |
| 22 | + | |
| 23 | + { | |
| 24 | + char * __attribute__ ((cleanup(check2))) stop_that = "tata !"; | |
| 25 | + | |
| 26 | + goto out; | |
| 27 | + stop_that = "titi"; | |
| 28 | + } | |
| 29 | + again: | |
| 30 | + chk = 2; | |
| 31 | + { | |
| 32 | + char * __attribute__ ((cleanup(check2))) cascade1 = "1"; | |
| 33 | + { | |
| 34 | + char * __attribute__ ((cleanup(check2))) cascade2 = "2"; | |
| 35 | + { | |
| 36 | + char * __attribute__ ((cleanup(check2))) cascade3 = "3"; | |
| 37 | + | |
| 38 | + goto out; | |
| 39 | + cascade3 = "nope"; | |
| 40 | + } | |
| 41 | + } | |
| 42 | + } | |
| 43 | + out: | |
| 44 | + if (chk != 2) | |
| 45 | + goto again; | |
| 46 | + { | |
| 47 | + { | |
| 48 | + char * __attribute__ ((cleanup(check2))) out = "last goto out"; | |
| 49 | + ++chk; | |
| 50 | + if (chk != 3) | |
| 51 | + goto out; | |
| 52 | + } | |
| 53 | + } | |
| 54 | + return; | |
| 55 | +} | |
| 56 | + | |
| 57 | +void check_oh_i(char *oh_i) | |
| 58 | +{ | |
| 59 | + printf("c: %c\n", *oh_i); | |
| 60 | +} | |
| 61 | + | |
| 62 | +void goto_hell(double *f) | |
| 63 | +{ | |
| 64 | + printf("oo: %f\n", *f); | |
| 65 | +} | |
| 66 | + | |
| 67 | +char *test() | |
| 68 | +{ | |
| 69 | + char *__attribute__ ((cleanup(check2))) str = "I don't think this should be print(but gcc got it wrong too)"; | |
| 70 | + | |
| 71 | + return str; | |
| 72 | +} | |
| 73 | + | |
| 74 | +void test_ret_subcall(char *that) | |
| 75 | +{ | |
| 76 | + printf("should be print before\n"); | |
| 77 | +} | |
| 78 | + | |
| 79 | +void test_ret() | |
| 80 | +{ | |
| 81 | + char *__attribute__ ((cleanup(check2))) that = "that"; | |
| 82 | + return test_ret_subcall(that); | |
| 83 | +} | |
| 84 | + | |
| 85 | +void test_ret2() | |
| 86 | +{ | |
| 87 | + char *__attribute__ ((cleanup(check2))) that = "-that"; | |
| 88 | + { | |
| 89 | + char *__attribute__ ((cleanup(check2))) that = "this should appear only once"; | |
| 90 | + } | |
| 91 | + { | |
| 92 | + char *__attribute__ ((cleanup(check2))) that = "-that2"; | |
| 93 | + return; | |
| 94 | + } | |
| 95 | +} | |
| 96 | + | |
| 97 | +int main() | |
| 98 | +{ | |
| 99 | + int i __attribute__ ((__cleanup__(check))) = 0, not_i; | |
| 100 | + int chk = 0; | |
| 101 | + | |
| 102 | + { | |
| 103 | + __attribute__ ((__cleanup__(check_oh_i))) char oh_i = 'o', o = 'a'; | |
| 104 | + } | |
| 105 | + | |
| 106 | + naaaaaaaa: | |
| 107 | + if (!chk) { | |
| 108 | + __attribute__ ((__cleanup__(check_oh_i))) char oh_i = 'f'; | |
| 109 | + double __attribute__ ((__cleanup__(goto_hell))) f = 2.6; | |
| 110 | + | |
| 111 | + chk = 1; | |
| 112 | + goto naaaaaaaa; | |
| 113 | + } | |
| 114 | + i = 105; | |
| 115 | + printf("because what if free was call inside cleanup function\n", test()); | |
| 116 | + test_ret(); | |
| 117 | + test_ret2(); | |
| 118 | + return i; | |
| 119 | +} | |
| 120 | + | |
| 121 | +void check2(char **hum) | |
| 122 | +{ | |
| 123 | + printf("str: %s\n", *hum); | |
| 124 | +} | |
| @@ -0,0 +1,20 @@ | ||
| 1 | +c: a | |
| 2 | +c: o | |
| 3 | +oo: 2.600000 | |
| 4 | +c: f | |
| 5 | +str: I don't think this should be print(but gcc got it wrong too) | |
| 6 | +because what if free was call inside cleanup function | |
| 7 | +should be print before | |
| 8 | +str: that | |
| 9 | +str: this should appear only once | |
| 10 | +str: -that2 | |
| 11 | +str: -that | |
| 12 | +---- 0 | |
| 13 | +---- 1 | |
| 14 | +str: plop | |
| 15 | +str: tata ! | |
| 16 | +str: 3 | |
| 17 | +str: 2 | |
| 18 | +str: 1 | |
| 19 | +str: last goto out | |
| 20 | +str: wololo | |