forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
192 lines (162 loc) · 2.24 KB
/
test.cpp
File metadata and controls
192 lines (162 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
void use(int x);
int puts(const char* str);
void test1(int a0, int b0, int c0) {
int a, b, c;
a = a0;
b = b0;
c = c0;
use(a);
use(b);
use(c);
a = b;
use(a);
use(b);
use(c);
if (a < 0) {
a = 1;
} else {
b = 1;
}
use(a);
use(b);
use(c);
int d = a; // `a` is both a use of `a` and a def of `d`
use(d);
int e = d++; // `d++` is both a def of `d` and a def of `e`
e = d++;
use(d);
use(e);
}
void assigns0(int& x);
void assigns1(int& x) {
x = 42;
}
void assigns2(int* x) {
int *y = x; *y = 42;
}
void assigns3(int* x) {
assigns0(*x);
}
void test2() {
int x = 0;
assigns0(x);
use(x);
}
void test3() {
int x = 0;
assigns1(x);
use(x);
}
void test4() {
int x = 0;
assigns2(&x);
use(x);
}
void test5() {
int x = 0;
assigns3(&x);
use(x);
}
void nonAssigns0(int& x) { }
void nonAssigns1(int* x) { }
void test6() {
int x = 0;
nonAssigns0(x);
use(x);
}
void test7() {
int x = 0;
nonAssigns1(&x);
use(x);
}
void test8() {
int x = 0;
for (int i = 0; i < 2; i++) {
use(x);
x = 3;
}
use(x);
}
void test9() {
int x = 0;
bool done = false;
while (!done) {
use(x);
x = 3;
done = true;
}
use(x);
}
void test10() {
int x = 0;
for (int i = 0; i < 2; i++) {
use(x);
x = 3;
}
use(x);
bool done = false;
while (!done) {
use(x);
x = 3;
done = true;
}
use(x);
}
void test11() {
int x = 0;
for (int i = 0; i < 2; i++) {
use(x);
x = 3;
bool done = false;
while (!done) {
use(x);
x = 3;
done = true;
}
use(x);
}
use(x);
}
void test12() {
int x = 0;
int* y = &x;
*y = 1;
use(x);
}
void test13() {
int x = 0;
int& y = x;
use(x);
y = 1;
use(x);
}
void test14(int x) {
use(x);
x = 42;
use(x);
}
void reads_const_ref(const int &x) {
use(x);
}
void reads_const_ptr(const int *x) {
use(*x);
}
void test15(int x) {
reads_const_ref(x);
reads_const_ptr(&x);
use(x);
}
struct S {
int x_;
struct Nested {
int *yptr_, z_;
static int static_y;
Nested(int *yptr, int z) : yptr_(yptr), z_(z) {}
Nested(int z) : yptr_(&static_y), z_(z) {}
} nested;
};
S f(int x, int z) {
static int y;
S s = { x, { &y, z } };
return s;
}