History

Add attribute cleanup test

matthias committed 7 years ago

Commit ff38d901 parent 0d91ba72 files · +144 −0Browse files

Showing the changes to tests (2 of 2 files). Show all

Unified · Split

2 files
  1. tests/tests2/101_cleanup.c +124 −0
  2. tests/tests2/101_cleanup.expect +20 −0
tests/tests2/101_cleanup.c+124−0
@@ -0,0 +1,124 @@
1#include <tcclib.h>
2
3void check2(char **hum);
4
5void 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
57void check_oh_i(char *oh_i)
58{
59 printf("c: %c\n", *oh_i);
60}
61
62void goto_hell(double *f)
63{
64 printf("oo: %f\n", *f);
65}
66
67char *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
74void test_ret_subcall(char *that)
75{
76 printf("should be print before\n");
77}
78
79void test_ret()
80{
81 char *__attribute__ ((cleanup(check2))) that = "that";
82 return test_ret_subcall(that);
83}
84
85void 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
97int 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
121void check2(char **hum)
122{
123 printf("str: %s\n", *hum);
124}
tests/tests2/101_cleanup.expect+20−0
@@ -0,0 +1,20 @@
1c: a
2c: o
3oo: 2.600000
4c: f
5str: I don't think this should be print(but gcc got it wrong too)
6because what if free was call inside cleanup function
7should be print before
8str: that
9str: this should appear only once
10str: -that2
11str: -that
12---- 0
13---- 1
14str: plop
15str: tata !
16str: 3
17str: 2
18str: 1
19str: last goto out
20str: wololo

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