Skip to content

Commit 34314d0

Browse files
committed
C++: Annotation field flow tests with [IR] and [AST]
1 parent f5e491c commit 34314d0

File tree

11 files changed

+42
-42
lines changed

11 files changed

+42
-42
lines changed

cpp/ql/test/library-tests/dataflow/fields/A.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,21 @@ class A
4040
cc.insert(nullptr);
4141
ct.insert(new C());
4242
sink(&cc); // no flow
43-
sink(&ct); // flow
43+
sink(&ct); // flow [NOT DETECTED by IR]
4444
}
4545
void f1()
4646
{
4747
C *c = new C();
4848
B *b = B::make(c);
49-
sink(b->c); // flow
49+
sink(b->c); // flow [NOT DETECTED by IR]
5050
}
5151

5252
void f2()
5353
{
5454
B *b = new B();
5555
b->set(new C1());
56-
sink(b->get()); // flow
57-
sink((new B(new C()))->get()); // flow
56+
sink(b->get()); // flow [NOT DETECTED by IR]
57+
sink((new B(new C()))->get()); // flow [NOT DETECTED by IR]
5858
}
5959

6060
void f3()
@@ -63,7 +63,7 @@ class A
6363
B *b2;
6464
b2 = setOnB(b1, new C2());
6565
sink(b1->c); // no flow
66-
sink(b2->c); // flow
66+
sink(b2->c); // flow [NOT DETECTED by IR]
6767
}
6868

6969
void f4()
@@ -72,7 +72,7 @@ class A
7272
B *b2;
7373
b2 = setOnBWrap(b1, new C2());
7474
sink(b1->c); // no flow
75-
sink(b2->c); // flow
75+
sink(b2->c); // flow [NOT DETECTED by IR]
7676
}
7777

7878
B *setOnBWrap(B *b1, C *c)
@@ -104,7 +104,7 @@ class A
104104
{
105105
if (C1 *c1 = dynamic_cast<C1 *>(c))
106106
{
107-
sink(c1->a); // flow
107+
sink(c1->a); // flow [NOT DETECTED by IR]
108108
}
109109
C *cc;
110110
if (C2 *c2 = dynamic_cast<C2 *>(c))
@@ -117,7 +117,7 @@ class A
117117
}
118118
if (C1 *c1 = dynamic_cast<C1 *>(cc))
119119
{
120-
sink(c1->a); // no flow, stopped by cast to C2 [FALSE POSITIVE]
120+
sink(c1->a); // no flow, stopped by cast to C2 [FALSE POSITIVE in AST]
121121
}
122122
}
123123

@@ -129,7 +129,7 @@ class A
129129
{
130130
B *b = new B();
131131
f7(b);
132-
sink(b->c); // flow
132+
sink(b->c); // flow [NOT DETECTED by IR]
133133
}
134134

135135
class D
@@ -149,8 +149,8 @@ class A
149149
{
150150
B *b = new B();
151151
D *d = new D(b, r());
152-
sink(d->b); // flow x2
153-
sink(d->b->c); // flow
152+
sink(d->b); // flow x2 [NOT DETECTED by IR]
153+
sink(d->b->c); // flow [NOT DETECTED by IR]
154154
sink(b->c); // flow
155155
}
156156

@@ -162,11 +162,11 @@ class A
162162
MyList *l3 = new MyList(nullptr, l2);
163163
sink(l3->head); // no flow, b is nested beneath at least one ->next
164164
sink(l3->next->head); // no flow
165-
sink(l3->next->next->head); // flow
165+
sink(l3->next->next->head); // flow [NOT DETECTED by IR]
166166
sink(l3->next->next->next->head); // no flow
167167
for (MyList *l = l3; l != nullptr; l = l->next)
168168
{
169-
sink(l->head); // flow
169+
sink(l->head); // flow [NOT DETECTED by IR]
170170
}
171171
}
172172

cpp/ql/test/library-tests/dataflow/fields/B.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class B
66
Elem *e = new Elem();
77
Box1 *b1 = new Box1(e, nullptr);
88
Box2 *b2 = new Box2(b1);
9-
sink(b2->box1->elem1); // flow
9+
sink(b2->box1->elem1); // flow [NOT DETECTED by IR]
1010
sink(b2->box1->elem2); // no flow
1111
}
1212

@@ -16,7 +16,7 @@ class B
1616
Box1 *b1 = new B::Box1(nullptr, e);
1717
Box2 *b2 = new Box2(b1);
1818
sink(b2->box1->elem1); // no flow
19-
sink(b2->box1->elem2); // flow
19+
sink(b2->box1->elem2); // flow [NOT DETECTED by IR]
2020
}
2121

2222
static void sink(void *o) {}

cpp/ql/test/library-tests/dataflow/fields/C.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class C
2626

2727
void func()
2828
{
29-
sink(s1); // flow
29+
sink(s1); // flow [NOT DETECTED by IR]
3030
sink(s2); // flow [NOT DETECTED]
31-
sink(s3); // flow
31+
sink(s3); // flow [NOT DETECTED by IR]
3232
sink(s4); // flow [NOT DETECTED]
3333
}
3434

cpp/ql/test/library-tests/dataflow/fields/D.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class D {
1919
};
2020

2121
static void sinkWrap(Box2* b2) {
22-
sink(b2->getBox1()->getElem());
22+
sink(b2->getBox1()->getElem()); // flow from f1, f2, f3, f9 [NOT DETECTED by IR]
2323
}
2424

2525
Box2* boxfield;
@@ -61,6 +61,6 @@ class D {
6161

6262
private:
6363
void f5b() {
64-
sink(boxfield->box->elem);
64+
sink(boxfield->box->elem); // flow [NOT DETECTED by IR]
6565
}
6666
};

cpp/ql/test/library-tests/dataflow/fields/E.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void sink(char *b);
1818

1919
void handlePacket(packet *p)
2020
{
21-
sink(p->data.buffer);
21+
sink(p->data.buffer); // flow [NOT DETECTED by IR]
2222
}
2323

2424
void f(buf* b)
@@ -28,7 +28,7 @@ void f(buf* b)
2828
argument_source(raw);
2929
argument_source(b->buffer);
3030
argument_source(p.data.buffer);
31-
sink(raw);
32-
sink(b->buffer);
31+
sink(raw); // flow [NOT DETECTED by IR]
32+
sink(b->buffer); // flow [NOT DETECTED by IR]
3333
handlePacket(&p);
3434
}

cpp/ql/test/library-tests/dataflow/fields/aliasing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ void assignAfterAlias() {
3535
S s1 = { 0, 0 };
3636
S &ref1 = s1;
3737
ref1.m1 = user_input();
38-
sink(s1.m1); // flow [FALSE NEGATIVE]
38+
sink(s1.m1); // flow [NOT DETECTED by AST]
3939

4040
S s2 = { 0, 0 };
4141
S &ref2 = s2;
4242
s2.m1 = user_input();
43-
sink(ref2.m1); // flow [FALSE NEGATIVE]
43+
sink(ref2.m1); // flow [NOT DETECTED by AST]
4444
}
4545

4646
void assignAfterCopy() {
@@ -77,14 +77,14 @@ void pointerIntermediate() {
7777
Wrapper w = { { 0, 0 } };
7878
S *s = &w.s;
7979
s->m1 = user_input();
80-
sink(w.s.m1); // flow [FALSE NEGATIVE]
80+
sink(w.s.m1); // flow [NOT DETECTED by AST]
8181
}
8282

8383
void referenceIntermediate() {
8484
Wrapper w = { { 0, 0 } };
8585
S &s = w.s;
8686
s.m1 = user_input();
87-
sink(w.s.m1); // flow [FALSE NEGATIVE]
87+
sink(w.s.m1); // flow [NOT DETECTED by AST]
8888
}
8989

9090
void nestedAssign() {

cpp/ql/test/library-tests/dataflow/fields/by_reference.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,25 @@ struct S {
4848
void test_setDirectly() {
4949
S s;
5050
s.setDirectly(user_input());
51-
sink(s.getDirectly()); // flow
51+
sink(s.getDirectly()); // flow [NOT DETECTED by IR]
5252
}
5353

5454
void test_setIndirectly() {
5555
S s;
5656
s.setIndirectly(user_input());
57-
sink(s.getIndirectly()); // flow
57+
sink(s.getIndirectly()); // flow [NOT DETECTED by IR]
5858
}
5959

6060
void test_setThroughNonMember() {
6161
S s;
6262
s.setThroughNonMember(user_input());
63-
sink(s.getThroughNonMember()); // flow
63+
sink(s.getThroughNonMember()); // flow [NOT DETECTED by IR]
6464
}
6565

6666
void test_nonMemberSetA() {
6767
S s;
6868
nonMemberSetA(&s, user_input());
69-
sink(nonMemberGetA(&s)); // flow
69+
sink(nonMemberGetA(&s)); // flow [NOT DETECTED by IR]
7070
}
7171

7272
////////////////////
@@ -127,7 +127,7 @@ void test_outer_with_ref(Outer *pouter) {
127127
taint_inner_a_ref(*pouter->inner_ptr);
128128
taint_a_ref(pouter->a);
129129

130-
sink(outer.inner_nested.a); // flow
130+
sink(outer.inner_nested.a); // flow [IR]
131131
sink(outer.inner_ptr->a); // flow [NOT DETECTED by IR]
132132
sink(outer.a); // flow [NOT DETECTED by IR]
133133

cpp/ql/test/library-tests/dataflow/fields/complex.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ void bar(Bar &b)
4141
// then it tracks that both `a_` and `b_` have followed `f` in _some_ access
4242
// path somewhere in the search. That makes the library conclude that there
4343
// could be flow to `b.f.a_` even when the flow was actually to `b.f.b_`.
44-
sink(b.f.a()); // flow [FALSE POSITIVE through `b2.f.setB` and `b3.f.setB`]
45-
sink(b.f.b()); // flow [FALSE POSITIVE through `b1.f.setA` and `b3.f.setA`]
44+
sink(b.f.a()); // flow [FALSE POSITIVE through `b2.f.setB` and `b3.f.setB` in AST, NOT DETECTED by IR]
45+
sink(b.f.b()); // flow [FALSE POSITIVE through `b1.f.setA` (AST) and `b3.f.setA` in AST, NOT DETECTED by IR]
4646
}
4747

4848
void foo()

cpp/ql/test/library-tests/dataflow/fields/constructors.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class Foo
2525

2626
void bar(Foo &f)
2727
{
28-
sink(f.a()); // flow (through `f` and `h`)
29-
sink(f.b()); // flow (through `g` and `h`)
28+
sink(f.a()); // flow (through `f` and `h`) [NOT DETECTED by IR]
29+
sink(f.b()); // flow (through `g` and `h`) [NOT DETECTED by IR]
3030
}
3131

3232
void foo()

cpp/ql/test/library-tests/dataflow/fields/simple.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void single_field_test()
6464
A a;
6565
a.i = user_input();
6666
A a2 = a;
67-
sink(a2.i);
67+
sink(a2.i); // flow
6868
}
6969

7070
struct C {
@@ -81,7 +81,7 @@ struct C2
8181

8282
void m() {
8383
f2.f1 = user_input();
84-
sink(getf2f1()); // flow
84+
sink(getf2f1()); // flow [NOT DETECTED by IR]
8585
}
8686
};
8787

0 commit comments

Comments
 (0)