Changeset 200fcb3 for tests/raii/dtor-early-exit.c
- Timestamp:
- Dec 12, 2018, 9:16:12 AM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 5ebb1368
- Parents:
- 3d99498
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/raii/dtor-early-exit.c
r3d99498 r200fcb3 10 10 // Created On : Wed Aug 17 08:26:25 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Aug 11 07:58:39201813 // Update Count : 812 // Last Modified On : Tue Dec 11 22:05:24 2018 13 // Update Count : 9 14 14 // 15 15 … … 25 25 // don't want these called 26 26 void ?{}(A & a) { assert( false ); } 27 void ?{}(A & a, const char * name) { a.name = name; sout | "construct " | name | endl; a.x = (int*)malloc(); }27 void ?{}(A & a, const char * name) { a.name = name; sout | "construct " | name; a.x = (int*)malloc(); } 28 28 void ?{}(A & a, const char * name, int * ptr) { assert( false ); } 29 29 30 30 A ?=?(A & a, A b) { sout | "assign " | a.name | " " | b.name; return a; } 31 void ?{}(A & a, A b) { sout | "copy construct " | b.name | endl; a.x = (int*)malloc(); }32 void ^?{}(A & a) { sout | "destruct " | a.name | endl; free(a.x); }31 void ?{}(A & a, A b) { sout | "copy construct " | b.name; a.x = (int*)malloc(); } 32 void ^?{}(A & a) { sout | "destruct " | a.name; free(a.x); } 33 33 34 34 // test returns 35 35 void f(int i) { 36 sout | "f i=" | i | endl;36 sout | "f i=" | i; 37 37 A x = { "x" }; // construct x 38 38 { … … 55 55 void g() { 56 56 for (int i = 0; i < 10; i++) { 57 sout | "g for i=" | i | endl;57 sout | "g for i=" | i; 58 58 A x = { "x" }; 59 59 // construct x 60 60 // destruct x 61 61 } 62 sout | endl;62 sout | nl; 63 63 { 64 64 int i = 0; 65 65 while (i < 10) { 66 sout | "g while i=" | i | endl;66 sout | "g while i=" | i; 67 67 A x = { "x" }; 68 68 // construct x … … 71 71 } 72 72 } 73 sout | endl;73 sout; 74 74 for (int i = 0; i < 10; i++) { 75 75 switch(10) { … … 78 78 case 10: { 79 79 A y = { "y" }; 80 sout | "g switch i=" | i | endl;80 sout | "g switch i=" | i; 81 81 // construct y 82 82 break; // destruct y 83 83 } 84 84 default: { 85 sout | "g switch i=" | i | endl;85 sout | "g switch i=" | i; 86 86 A x = { "x" }; 87 87 // construct x … … 90 90 } 91 91 } 92 sout | endl;92 sout | nl; 93 93 for (int k = 0; k < 2; k++) { 94 sout | "g for k=" | k | endl;94 sout | "g for k=" | k; 95 95 L1: for (int i = 0; i < 10; i++) { 96 sout | "g for i=" | i | endl;96 sout | "g for i=" | i; 97 97 98 98 A x = { "x" }; 99 99 if (i == 2) { 100 sout | "continue L1" | endl;100 sout | "continue L1"; 101 101 continue; // destruct x 102 102 } else if (i == 3) { 103 sout | "break L1" | endl;103 sout | "break L1"; 104 104 break; // destruct x 105 105 } 106 106 107 107 L2: for (int j = 0; j < 10; j++) { 108 sout | "g for j=" | j | endl;108 sout | "g for j=" | j; 109 109 A y = { "y" }; 110 110 if (j == 0) { 111 sout | "continue L2" | endl;111 sout | "continue L2"; 112 112 continue; // destruct y - missing because object that needs to be destructed is not a part of this block, it's a part of the for's block 113 113 } else if (j == 1) { 114 sout | "break L2" | endl;114 sout | "break L2"; 115 115 break; // destruct y 116 116 } else if (i == 1) { 117 sout | "continue L1" | endl;117 sout | "continue L1"; 118 118 continue L1; // destruct x,y - note: continue takes you to destructors for block, so only generate destructor for y 119 119 } else if (k == 1) { 120 sout | "break L1" | endl;120 sout | "break L1"; 121 121 break L1; // destruct x,y 122 122 } … … 125 125 } 126 126 127 sout | endl;127 sout | nl; 128 128 L3: if( 3 ) { 129 129 A w = { "w" }; 130 130 if( 4 ) { 131 131 A v = { "v" }; 132 sout | "break L3" | endl;132 sout | "break L3"; 133 133 break L3; 134 134 } … … 144 144 // * if S_L-S_G is non-empty, error 145 145 // * emit destructors for all variables in S_G-S_L 146 sout | "h" | endl;146 sout | "h"; 147 147 { 148 148 L0: ; … … 152 152 A y = { "y" }; 153 153 // S_L1 = { y } 154 L1: sout | "L1" | endl;154 L1: sout | "L1"; 155 155 A x = { "x" }; 156 156 // S_L2 = { y, x } 157 L2: sout | "L2" | endl;157 L2: sout | "L2"; 158 158 if (i == 0) { 159 159 ++i; 160 sout | "goto L1" | endl;160 sout | "goto L1"; 161 161 // S_G = { y, x } 162 162 goto L1; // jump back, destruct b/c before x definition … … 165 165 } else if (i == 1) { 166 166 ++i; 167 sout | "goto L2" | endl;167 sout | "goto L2"; 168 168 // S_G = { y, x } 169 169 goto L2; // jump back, do not destruct … … 172 172 } else if (i == 2) { 173 173 ++i; 174 sout | "goto L3" | endl;174 sout | "goto L3"; 175 175 // S_G = { y, x } 176 176 goto L3; // jump ahead, do not destruct … … 180 180 ++i; 181 181 A z = { "z" }; 182 sout | "goto L3-2" | endl;182 sout | "goto L3-2"; 183 183 // S_G = { z, y, x } 184 184 goto L3; … … 187 187 } else { 188 188 ++i; 189 sout | "goto L4" | endl;189 sout | "goto L4"; 190 190 // S_G = { y, x } 191 191 goto L4; // jump ahead, destruct b/c left block x was defined in … … 194 194 } 195 195 // S_L3 = { y, x } 196 L3: sout | "L3" | endl;197 sout | "goto L2-2" | endl;196 L3: sout | "L3"; 197 sout | "goto L2-2"; 198 198 // S_G = { y, x } 199 199 goto L2; // jump back, do not destruct … … 202 202 } 203 203 // S_L4 = {} 204 L4: sout | "L4" | endl;204 L4: sout | "L4"; 205 205 if (i == 4) { 206 sout | "goto L0" | endl;206 sout | "goto L0"; 207 207 // S_G = {} 208 208 goto L0; … … 240 240 f(i); 241 241 } 242 sout | endl;242 sout | nl; 243 243 g(); 244 sout | endl;244 sout | nl; 245 245 h(); 246 246
Note: See TracChangeset
for help on using the changeset viewer.