Skip to content

Commit 1bb57da

Browse files
author
Robert Marsh
authored
Merge pull request #1866 from jbj/dataflow-test-alias-nested
C++: Tests for aliasing of nested structs
2 parents a329050 + 8579d7d commit 1bb57da

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,34 @@ void assignBeforeCopy() {
6161
S copy2 = s2;
6262
sink(copy2.m1); // flow
6363
}
64+
65+
struct Wrapper {
66+
S s;
67+
};
68+
69+
void copyIntermediate() {
70+
Wrapper w = { { 0, 0 } };
71+
S s = w.s;
72+
s.m1 = user_input();
73+
sink(w.s.m1); // no flow
74+
}
75+
76+
void pointerIntermediate() {
77+
Wrapper w = { { 0, 0 } };
78+
S *s = &w.s;
79+
s->m1 = user_input();
80+
sink(w.s.m1); // flow [FALSE NEGATIVE]
81+
}
82+
83+
void referenceIntermediate() {
84+
Wrapper w = { { 0, 0 } };
85+
S &s = w.s;
86+
s.m1 = user_input();
87+
sink(w.s.m1); // flow [FALSE NEGATIVE]
88+
}
89+
90+
void nestedAssign() {
91+
Wrapper w = { { 0, 0 } };
92+
w.s.m1 = user_input();
93+
sink(w.s.m1); // flow
94+
}

cpp/ql/test/library-tests/dataflow/fields/flow.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ edges
102102
| aliasing.cpp:60:3:60:22 | ... = ... [void] | aliasing.cpp:60:3:60:4 | s2 [post update] [m1, ... (1)] |
103103
| aliasing.cpp:60:11:60:20 | call to user_input [void] | aliasing.cpp:60:3:60:22 | ... = ... [void] |
104104
| aliasing.cpp:62:8:62:12 | copy2 [m1, ... (1)] | aliasing.cpp:62:14:62:15 | m1 |
105+
| aliasing.cpp:92:3:92:3 | w [post update] [s, ... (2)] | aliasing.cpp:93:8:93:8 | w [s, ... (2)] |
106+
| aliasing.cpp:92:3:92:23 | ... = ... [void] | aliasing.cpp:92:5:92:5 | s [post update] [m1, ... (1)] |
107+
| aliasing.cpp:92:5:92:5 | s [post update] [m1, ... (1)] | aliasing.cpp:92:3:92:3 | w [post update] [s, ... (2)] |
108+
| aliasing.cpp:92:12:92:21 | call to user_input [void] | aliasing.cpp:92:3:92:23 | ... = ... [void] |
109+
| aliasing.cpp:93:8:93:8 | w [s, ... (2)] | aliasing.cpp:93:10:93:10 | s [m1, ... (1)] |
110+
| aliasing.cpp:93:10:93:10 | s [m1, ... (1)] | aliasing.cpp:93:12:93:13 | m1 |
105111
| complex.cpp:34:15:34:15 | b [f, ... (2)] | complex.cpp:44:8:44:8 | b [f, ... (2)] |
106112
| complex.cpp:34:15:34:15 | b [f, ... (2)] | complex.cpp:45:8:45:8 | b [f, ... (2)] |
107113
| complex.cpp:44:8:44:8 | b [f, ... (2)] | complex.cpp:44:10:44:10 | f [a_, ... (1)] |
@@ -186,6 +192,7 @@ edges
186192
| aliasing.cpp:29:11:29:12 | m1 | aliasing.cpp:9:11:9:20 | call to user_input [void] | aliasing.cpp:29:11:29:12 | m1 | m1 flows from $@ | aliasing.cpp:9:11:9:20 | call to user_input [void] | call to user_input [void] |
187193
| aliasing.cpp:30:11:30:12 | m1 | aliasing.cpp:13:10:13:19 | call to user_input [void] | aliasing.cpp:30:11:30:12 | m1 | m1 flows from $@ | aliasing.cpp:13:10:13:19 | call to user_input [void] | call to user_input [void] |
188194
| aliasing.cpp:62:14:62:15 | m1 | aliasing.cpp:60:11:60:20 | call to user_input [void] | aliasing.cpp:62:14:62:15 | m1 | m1 flows from $@ | aliasing.cpp:60:11:60:20 | call to user_input [void] | call to user_input [void] |
195+
| aliasing.cpp:93:12:93:13 | m1 | aliasing.cpp:92:12:92:21 | call to user_input [void] | aliasing.cpp:93:12:93:13 | m1 | m1 flows from $@ | aliasing.cpp:92:12:92:21 | call to user_input [void] | call to user_input [void] |
189196
| complex.cpp:44:12:44:12 | call to a | complex.cpp:55:13:55:22 | call to user_input [void] | complex.cpp:44:12:44:12 | call to a | call to a flows from $@ | complex.cpp:55:13:55:22 | call to user_input [void] | call to user_input [void] |
190197
| complex.cpp:44:12:44:12 | call to a | complex.cpp:56:13:56:22 | call to user_input [void] | complex.cpp:44:12:44:12 | call to a | call to a flows from $@ | complex.cpp:56:13:56:22 | call to user_input [void] | call to user_input [void] |
191198
| complex.cpp:44:12:44:12 | call to a | complex.cpp:57:13:57:22 | call to user_input [void] | complex.cpp:44:12:44:12 | call to a | call to a flows from $@ | complex.cpp:57:13:57:22 | call to user_input [void] | call to user_input [void] |

0 commit comments

Comments
 (0)