|
1 | 1 | void CallByPointer(int* p); |
2 | 2 | void CallByReference(int& r); |
| 3 | +int *GetPointer(); |
| 4 | +int &GetReference(); |
| 5 | + |
| 6 | +int FetchFromPointer(int *no_p) { |
| 7 | + return *no_p; |
| 8 | +} |
| 9 | + |
| 10 | +int FetchFromReference(int &no_r) { |
| 11 | + return no_r; |
| 12 | +} |
| 13 | + |
| 14 | +int *ReturnPointer(int *no_p) { |
| 15 | + return no_p; |
| 16 | +} |
| 17 | + |
| 18 | +int &ReturnReference(int &no_r) { |
| 19 | + return no_r; |
| 20 | +} |
| 21 | + |
| 22 | +void CallByPointerParamEscape(int *no_p) { |
| 23 | + CallByPointer(no_p); |
| 24 | +} |
| 25 | + |
| 26 | +void CallByReferenceParamEscape(int &no_r) { |
| 27 | + CallByReference(no_r); |
| 28 | +} |
| 29 | + |
| 30 | +int *MaybeReturn(int *no_p, int *no_q, bool no_b) { |
| 31 | + if (no_b) { |
| 32 | + return no_p; |
| 33 | + } else { |
| 34 | + return no_q; |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +int &EscapeAndReturn(int &no_r) { |
| 39 | + CallByReference(no_r); |
| 40 | + return no_r; |
| 41 | +} |
3 | 42 |
|
4 | 43 | struct Point { |
5 | 44 | float x; |
@@ -95,4 +134,39 @@ void Escape() |
95 | 134 |
|
96 | 135 | int passByRef; |
97 | 136 | CallByReference(passByRef); |
| 137 | + |
| 138 | + int no_ssa_passByPtr; |
| 139 | + FetchFromPointer(&no_ssa_passByPtr); |
| 140 | + |
| 141 | + int no_ssa_passByRef; |
| 142 | + FetchFromReference(no_ssa_passByRef); |
| 143 | + |
| 144 | + int no_ssa_passByPtr_ret; |
| 145 | + FetchFromPointer(&no_ssa_passByPtr_ret); |
| 146 | + |
| 147 | + int no_ssa_passByRef_ret; |
| 148 | + FetchFromReference(no_ssa_passByRef_ret); |
| 149 | + |
| 150 | + int passByPtr2; |
| 151 | + CallByPointerParamEscape(&passByPtr2); |
| 152 | + |
| 153 | + int passByRef2; |
| 154 | + CallByReferenceParamEscape(passByRef2); |
| 155 | + |
| 156 | + int passByPtr3; |
| 157 | + CallByPointerParamEscape(ReturnPointer(&passByPtr3)); |
| 158 | + |
| 159 | + int passByRef3; |
| 160 | + CallByReferenceParamEscape(ReturnReference(passByRef3)); |
| 161 | + |
| 162 | + int passByPtr4; |
| 163 | + int passByPtr5; |
| 164 | + bool no_b2 = false; |
| 165 | + MaybeReturn(&passByPtr4, &passByPtr5, no_b2); |
| 166 | + |
| 167 | + int passByRef6; |
| 168 | + EscapeAndReturn(passByRef6); |
| 169 | + |
| 170 | + int no_ssa_passByRef7; |
| 171 | + ReturnReference(no_ssa_passByRef7); |
98 | 172 | } |
0 commit comments