Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd39698

Browse files
author
Robert Marsh
committed
C++: test changes for interproc escape analysis
1 parent f6828fa commit bd39698

3 files changed

Lines changed: 247 additions & 108 deletions

File tree

cpp/ql/test/library-tests/ir/escape/escape.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
11
void CallByPointer(int* p);
22
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+
}
342

443
struct Point {
544
float x;
@@ -95,4 +134,39 @@ void Escape()
95134

96135
int passByRef;
97136
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);
98172
}

0 commit comments

Comments
 (0)