Skip to content

Commit 9b2019d

Browse files
committed
C++: Accept test changes.
1 parent 499ab08 commit 9b2019d

File tree

13 files changed

+110
-52
lines changed

13 files changed

+110
-52
lines changed

cpp/ql/test/include/iterator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace std {
6565
};
6666

6767
template<class Container>
68-
constexpr back_insert_iterator<Container> back_inserter(Container& x) {
68+
constexpr back_insert_iterator<Container> back_inserter(Container& x) { // $ ir-def=*x
6969
return back_insert_iterator<Container>(x);
7070
}
7171

@@ -89,7 +89,7 @@ namespace std {
8989
constexpr front_insert_iterator operator++(int);
9090
};
9191
template<class Container>
92-
constexpr front_insert_iterator<Container> front_inserter(Container& x) {
92+
constexpr front_insert_iterator<Container> front_inserter(Container& x) { // $ ir-def=*x
9393
return front_insert_iterator<Container>(x);
9494
}
9595
}

cpp/ql/test/library-tests/dataflow/dataflow-tests/BarrierGuard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void bg_stackstruct(XY s1, XY s2) {
5656
}
5757
}
5858

59-
void bg_structptr(XY *p1, XY *p2) { // $ ast-def=p1 ast-def=p2
59+
void bg_structptr(XY *p1, XY *p2) { // $ ast-def=p1 ast-def=p2 ir-def=*p1 ir-def=*p2
6060
p1->x = source();
6161
if (guarded(p1->x)) {
6262
sink(p1->x); // $ SPURIOUS: ast

cpp/ql/test/library-tests/dataflow/dataflow-tests/clang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct twoIntFields {
88
int getFirst() { return m1; }
99
};
1010

11-
void following_pointers( // $ ast-def=sourceStruct1_ptr
11+
void following_pointers( // $ ast-def=sourceStruct1_ptr ir-def=*cleanArray1 ir-def=*sourceArray1 ir-def=*sourceStruct1_ptr
1212
int sourceArray1[],
1313
int cleanArray1[],
1414
twoIntFields sourceStruct1,

cpp/ql/test/library-tests/dataflow/dataflow-tests/dispatch.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct Bottom : Middle {
2525
void notSink(int x) override { }
2626
};
2727

28-
void VirtualDispatch(Bottom *bottomPtr, Bottom &bottomRef) { // $ ast-def=bottomPtr ast-def=bottomRef
28+
void VirtualDispatch(Bottom *bottomPtr, Bottom &bottomRef) { // $ ast-def=bottomPtr ast-def=bottomRef ir-def=*bottomPtr ir-def=*bottomRef
2929
Top *topPtr = bottomPtr, &topRef = bottomRef;
3030

3131
sink(topPtr->isSource1()); // $ ir MISSING: ast
@@ -65,11 +65,11 @@ Top *allocateBottom() {
6565
return new Bottom();
6666
}
6767

68-
void callSinkByPointer(Top *top) { // $ ast-def=top
68+
void callSinkByPointer(Top *top) { // $ ast-def=top ir-def=*top
6969
top->isSink(source()); // leads to MISSING from ast
7070
}
7171

72-
void callSinkByReference(Top &top) { // $ ast-def=top
72+
void callSinkByReference(Top &top) { // $ ast-def=top ir-def=*top
7373
top.isSink(source()); // leads to MISSING from ast
7474
}
7575

@@ -81,11 +81,11 @@ void globalVirtualDispatch() {
8181
x->isSink(source()); // $ MISSING: ast,ir
8282
}
8383

84-
Top *identity(Top *top) { // $ ast-def=top
84+
Top *identity(Top *top) { // $ ast-def=top ir-def=*top
8585
return top;
8686
}
8787

88-
void callIdentityFunctions(Top *top, Bottom *bottom) { // $ ast-def=bottom ast-def=top
88+
void callIdentityFunctions(Top *top, Bottom *bottom) { // $ ast-def=bottom ast-def=top ir-def=*bottom ir-def=*top
8989
identity(bottom)->isSink(source()); // $ MISSING: ast,ir
9090
identity(top)->isSink(source()); // no flow
9191
}
@@ -120,7 +120,7 @@ namespace virtual_inheritance {
120120
struct Bottom : Middle {
121121
};
122122

123-
void VirtualDispatch(Bottom *bottomPtr, Bottom &bottomRef) { // $ ast-def=bottomPtr ast-def=bottomRef
123+
void VirtualDispatch(Bottom *bottomPtr, Bottom &bottomRef) { // $ ast-def=bottomPtr ast-def=bottomRef ir-def=*bottomPtr ir-def=*bottomRef
124124
// Because the inheritance from `Top` is virtual, the following casts go
125125
// directly from `Bottom` to `Top`, skipping `Middle`. That means we don't
126126
// get flow from a `Middle` value to the call qualifier.

cpp/ql/test/library-tests/dataflow/dataflow-tests/example.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ typedef struct
1212
char isTrue;
1313
} MyBool;
1414

15-
void myTest_with_local_flow(MyBool *b, int pos) // $ ast-def=b
15+
void myTest_with_local_flow(MyBool *b, int pos) // $ ast-def=b ir-def=*b
1616
{
1717
MyCoords coords = {0};
1818

cpp/ql/test/library-tests/dataflow/dataflow-tests/flowOut.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void source_ref(int *toTaint) { // $ ir-def=*toTaint ast-def=toTaint
77
void source_ref(char *toTaint) { // $ ir-def=*toTaint ast-def=toTaint
88
*toTaint = source();
99
}
10-
void modify_copy(int* ptr) { // $ ast-def=ptr
10+
void modify_copy(int* ptr) { // $ ast-def=ptr ir-def=*ptr
1111
int deref = *ptr;
1212
int* other = &deref;
1313
source_ref(other);
@@ -19,7 +19,7 @@ void test_output_copy() {
1919
sink(x); // clean
2020
}
2121

22-
void modify(int* ptr) { // $ ast-def=ptr
22+
void modify(int* ptr) { // $ ast-def=ptr ir-def=*ptr
2323
int* deref = ptr;
2424
int* other = &*deref;
2525
source_ref(other);
@@ -31,7 +31,7 @@ void test_output() {
3131
sink(x); // $ ir MISSING: ast
3232
}
3333

34-
void modify_copy_of_pointer(int* p, unsigned len) { // $ ast-def=p
34+
void modify_copy_of_pointer(int* p, unsigned len) { // $ ast-def=p ir-def=*p
3535
int* p2 = new int[len];
3636
for(unsigned i = 0; i < len; ++i) {
3737
p2[i] = p[i];
@@ -46,7 +46,7 @@ void test_modify_copy_of_pointer() {
4646
sink(x[0]); // $ SPURIOUS: ast // clean
4747
}
4848

49-
void modify_pointer(int* p, unsigned len) { // $ ast-def=p
49+
void modify_pointer(int* p, unsigned len) { // $ ast-def=p ir-def=*p
5050
int** p2 = &p;
5151
for(unsigned i = 0; i < len; ++i) {
5252
*p2[i] = p[i];
@@ -63,17 +63,17 @@ void test_modify_of_pointer() {
6363

6464
char* strdup(const char* p);
6565

66-
void modify_copy_via_strdup(char* p) { // $ ast-def=p
66+
void modify_copy_via_strdup(char* p) { // $ ast-def=p ir-def=*p
6767
char* p2 = strdup(p);
6868
source_ref(p2);
6969
}
7070

71-
void test_modify_copy_via_strdup(char* p) { // $ ast-def=p
71+
void test_modify_copy_via_strdup(char* p) { // $ ast-def=p ir-def=*p
7272
modify_copy_via_strdup(p);
7373
sink(*p); // clean
7474
}
7575

76-
int* deref(int** p) { // $ ast-def=p
76+
int* deref(int** p) { // $ ast-def=p ir-def=*p ir-def=**p
7777
int* q = *p;
7878
return q;
7979
}
@@ -90,7 +90,7 @@ void addtaint1(int* q) { // $ ast-def=q ir-def=*q
9090
*q = source();
9191
}
9292

93-
void addtaint2(int** p) { // $ ast-def=p
93+
void addtaint2(int** p) { // $ ast-def=p ir-def=*p ir-def=**p
9494
int* q = *p;
9595
addtaint1(q);
9696
}
@@ -106,13 +106,13 @@ using size_t = decltype(sizeof(int));
106106

107107
void* memcpy(void* dest, const void* src, size_t);
108108

109-
void modify_copy_via_memcpy(char* p) { // $ ast-def=p
109+
void modify_copy_via_memcpy(char* p) { // $ ast-def=p ir-def=*p
110110
char* dest;
111111
char* p2 = (char*)memcpy(dest, p, 10);
112112
source_ref(p2);
113113
}
114114

115-
void test_modify_copy_via_memcpy(char* p) { // $ ast-def=p
115+
void test_modify_copy_via_memcpy(char* p) { // $ ast-def=p ir-def=*p
116116
modify_copy_via_memcpy(p);
117117
sink(*p); // clean
118118
}
@@ -134,29 +134,29 @@ void source_ref_ref(char** toTaint) { // $ ast-def=toTaint ir-def=*toTaint ir-de
134134
// This function copies the value of **p into a new location **p2 and then
135135
// taints **p. Thus, **p does not contain tainted data after returning from
136136
// this function.
137-
void modify_copy_via_strdup_ptr_001(char** p) { // $ ast-def=p
137+
void modify_copy_via_strdup_ptr_001(char** p) { // $ ast-def=p ir-def=*p ir-def=**p
138138
// **p -> **p2
139139
char** p2 = strdup_ptr_001(p);
140140
// source -> **p2
141141
source_ref_ref(p2);
142142
}
143143

144-
void test_modify_copy_via_strdup_001(char** p) { // $ ast-def=p
144+
void test_modify_copy_via_strdup_001(char** p) { // $ ast-def=p ir-def=*p ir-def=**p
145145
modify_copy_via_strdup_ptr_001(p);
146146
sink(**p); // clean
147147
}
148148

149149
// This function copies the value of *p into a new location *p2 and then
150150
// taints **p2. Thus, **p contains tainted data after returning from this
151151
// function.
152-
void modify_copy_via_strdup_ptr_011(char** p) { // $ ast-def=p
152+
void modify_copy_via_strdup_ptr_011(char** p) { // $ ast-def=p ir-def=*p ir-def=**p
153153
// **p -> **p2 and *p -> *p2
154154
char** p2 = strdup_ptr_011(p);
155155
// source -> **p2
156156
source_ref_ref(p2);
157157
}
158158

159-
void test_modify_copy_via_strdup_011(char** p) { // $ ast-def=p
159+
void test_modify_copy_via_strdup_011(char** p) { // $ ast-def=p ir-def=*p ir-def=**p
160160
modify_copy_via_strdup_ptr_011(p);
161161
sink(**p); // $ ir MISSING: ast
162162
}
@@ -171,7 +171,7 @@ void source_ref_2(char** toTaint) { // $ ast-def=toTaint ir-def=*toTaint ir-def=
171171
// This function copies the value of p into a new location p2 and then
172172
// taints *p2. Thus, *p contains tainted data after returning from this
173173
// function.
174-
void modify_copy_via_strdup_ptr_111_taint_ind(char** p) { // $ ast-def=p
174+
void modify_copy_via_strdup_ptr_111_taint_ind(char** p) { // $ ast-def=p ir-def=*p ir-def=**p
175175
// **p -> **p2, *p -> *p2, and p -> p2
176176
char** p2 = strdup_ptr_111(p);
177177
// source -> *p2
@@ -180,15 +180,15 @@ void modify_copy_via_strdup_ptr_111_taint_ind(char** p) { // $ ast-def=p
180180

181181
void sink(char*);
182182

183-
void test_modify_copy_via_strdup_111_taint_ind(char** p) { // $ ast-def=p
183+
void test_modify_copy_via_strdup_111_taint_ind(char** p) { // $ ast-def=p ir-def=*p ir-def=**p
184184
modify_copy_via_strdup_ptr_111_taint_ind(p);
185185
sink(*p); // $ ir MISSING: ast
186186
}
187187

188188
// This function copies the value of p into a new location p2 and then
189189
// taints **p2. Thus, **p contains tainted data after returning from this
190190
// function.
191-
void modify_copy_via_strdup_ptr_111_taint_ind_ind(char** p) { // $ ast-def=p
191+
void modify_copy_via_strdup_ptr_111_taint_ind_ind(char** p) { // $ ast-def=p ir-def=*p ir-def=**p
192192
// **p -> **p2, *p -> *p2, and p -> p2
193193
char** p2 = strdup_ptr_111(p);
194194
// source -> **p2
@@ -197,7 +197,7 @@ void modify_copy_via_strdup_ptr_111_taint_ind_ind(char** p) { // $ ast-def=p
197197

198198
void sink(char*);
199199

200-
void test_modify_copy_via_strdup_111_taint_ind_ind(char** p) { // $ ast-def=p
200+
void test_modify_copy_via_strdup_111_taint_ind_ind(char** p) { // $ ast-def=p ir-def=*p ir-def=**p
201201
modify_copy_via_strdup_ptr_111_taint_ind_ind(p);
202202
sink(**p); // $ ir MISSING: ast
203203
}

cpp/ql/test/library-tests/dataflow/dataflow-tests/lambdas.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void test_lambdas()
3737
};
3838
d(t, u);
3939

40-
auto e = [](int &a, int &b, int &c) { // $ ast-def=a ast-def=b ast-def=c ir-def=*c
40+
auto e = [](int &a, int &b, int &c) { // $ ast-def=a ast-def=b ast-def=c ir-def=*c ir-def=*a ir-def=*b
4141
sink(a); // $ ast,ir
4242
sink(b);
4343
c = source();

cpp/ql/test/library-tests/dataflow/dataflow-tests/ref.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace withoutFields {
1212
}
1313

1414
template<typename T>
15-
void assignWrapper(T &lhs, T rhs) { // $ ast-def=lhs ast-def=lhs
15+
void assignWrapper(T &lhs, T rhs) { // $ ast-def=lhs ast-def=lhs ir-def=*lhs
1616
assign(lhs, rhs);
1717
}
1818

@@ -71,15 +71,15 @@ namespace withFields {
7171
int val;
7272
};
7373

74-
void assign(Int &lhs, int rhs) { // $ ast-def=lhs
74+
void assign(Int &lhs, int rhs) { // $ ast-def=lhs ir-def=*lhs
7575
lhs.val = rhs;
7676
}
7777

78-
void assignWrapper(Int &lhs, int rhs) { // $ ast-def=lhs
78+
void assignWrapper(Int &lhs, int rhs) { // $ ast-def=lhs ir-def=*lhs
7979
assign(lhs, rhs);
8080
}
8181

82-
void notAssign(Int &lhs, int rhs) { // $ ast-def=lhs
82+
void notAssign(Int &lhs, int rhs) { // $ ast-def=lhs ir-def=*lhs
8383
lhs.val = rhs;
8484
// Field flow ignores that the field is subsequently overwritten, leading
8585
// to false flow here.
@@ -90,22 +90,22 @@ namespace withFields {
9090
}
9191
}
9292

93-
void sourceToParam(Int &out) { // $ ast-def=out
93+
void sourceToParam(Int &out) { // $ ast-def=out ir-def=*out
9494
out.val = source();
9595
if (arbitrary) {
9696
out.val = 1;
9797
}
9898
}
9999

100-
void sourceToParamWrapper(Int &out) { // $ ast-def=out
100+
void sourceToParamWrapper(Int &out) { // $ ast-def=out ir-def=*out
101101
if (arbitrary) {
102102
sourceToParam(out);
103103
} else {
104104
out.val = 1;
105105
}
106106
}
107107

108-
void notSource(Int &out) { // $ ast-def=out
108+
void notSource(Int &out) { // $ ast-def=out ir-def=*out
109109
out.val = source();
110110
// Field flow ignores that the field is subsequently overwritten, leading
111111
// to false flow here.

cpp/ql/test/library-tests/dataflow/dataflow-tests/self_parameter_flow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ void incr(unsigned char **ps) // $ ast-def=ps ir-def=*ps ir-def=**ps
33
*ps += 1;
44
}
55

6-
void callincr(unsigned char *s) // $ ast-def=s
6+
void callincr(unsigned char *s) // $ ast-def=s ir-def=*s
77
{
88
incr(&s);
99
}
1010

11-
void test(unsigned char *s) // $ ast-def=s
11+
void test(unsigned char *s) // $ ast-def=s ir-def=*s
1212
{
1313
callincr(s); // $ flow
1414
}

cpp/ql/test/library-tests/dataflow/dataflow-tests/test-source-sink.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ irFlow
264264
| test.cpp:576:17:576:31 | *call to indirect_source | test.cpp:568:10:568:19 | * ... |
265265
| test.cpp:576:17:576:31 | *call to indirect_source | test.cpp:572:10:572:19 | * ... |
266266
| test.cpp:576:17:576:31 | *call to indirect_source | test.cpp:578:10:578:19 | * ... |
267+
| test.cpp:583:11:583:16 | call to source | test.cpp:590:8:590:8 | x |
267268
| test.cpp:594:12:594:26 | *call to indirect_source | test.cpp:597:8:597:13 | * ... |
268269
| test.cpp:601:20:601:20 | intPointerSource output argument | test.cpp:603:8:603:9 | * ... |
269270
| test.cpp:607:20:607:20 | intPointerSource output argument | test.cpp:609:8:609:9 | * ... |

0 commit comments

Comments
 (0)