Skip to content

Commit 2d76c15

Browse files
committed
C#: Add more barrier guards tests
1 parent 9bfd461 commit 2d76c15

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

csharp/ql/test/library-tests/dataflow/barrier-guards/BarrierFlow.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,86 @@ void M6(bool b)
8080

8181
Sink(x);
8282
}
83+
84+
void M7()
85+
{
86+
var x = Source(7);
87+
88+
if (x == "safe" && x == "safe")
89+
{
90+
Sink(x);
91+
}
92+
else
93+
{
94+
Sink(x); // $ hasValueFlow=7
95+
}
96+
97+
if (x != "safe" && x == "safe2")
98+
{
99+
Sink(x);
100+
}
101+
else
102+
{
103+
Sink(x); // $ hasValueFlow=7
104+
}
105+
106+
if (x == "safe" && x != "safe2")
107+
{
108+
Sink(x);
109+
}
110+
else
111+
{
112+
Sink(x); // $ hasValueFlow=7
113+
}
114+
115+
if (x != "safe1" && x != "safe2")
116+
{
117+
Sink(x); // $ hasValueFlow=7
118+
}
119+
else
120+
{
121+
Sink(x);
122+
}
123+
}
124+
125+
void M8()
126+
{
127+
var x = Source(8);
128+
129+
if (x == "safe1" || x == "safe2")
130+
{
131+
Sink(x);
132+
}
133+
else
134+
{
135+
Sink(x); // $ hasValueFlow=8
136+
}
137+
138+
if (x != "safe1" || x == "safe2")
139+
{
140+
Sink(x); // $ hasValueFlow=8
141+
}
142+
else
143+
{
144+
Sink(x);
145+
}
146+
147+
if (x == "safe1" || x != "safe2")
148+
{
149+
Sink(x); // $ hasValueFlow=8
150+
}
151+
else
152+
{
153+
Sink(x);
154+
}
155+
156+
if (x != "safe" || x != "safe")
157+
{
158+
Sink(x); // $ hasValueFlow=8
159+
}
160+
else
161+
{
162+
Sink(x);
163+
}
164+
}
83165
}

csharp/ql/test/library-tests/dataflow/barrier-guards/barrier-flow.expected

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,49 @@ edges
44
| BarrierFlow.cs:10:17:10:25 | call to method Source : Object | BarrierFlow.cs:10:13:10:13 | access to local variable x : Object | provenance | |
55
| BarrierFlow.cs:17:13:17:13 | access to local variable x : Object | BarrierFlow.cs:21:18:21:18 | access to local variable x | provenance | |
66
| BarrierFlow.cs:17:17:17:25 | call to method Source : Object | BarrierFlow.cs:17:13:17:13 | access to local variable x : Object | provenance | |
7+
| BarrierFlow.cs:86:13:86:13 | access to local variable x : Object | BarrierFlow.cs:94:18:94:18 | access to local variable x | provenance | |
8+
| BarrierFlow.cs:86:13:86:13 | access to local variable x : Object | BarrierFlow.cs:103:18:103:18 | access to local variable x | provenance | |
9+
| BarrierFlow.cs:86:13:86:13 | access to local variable x : Object | BarrierFlow.cs:112:18:112:18 | access to local variable x | provenance | |
10+
| BarrierFlow.cs:86:13:86:13 | access to local variable x : Object | BarrierFlow.cs:117:18:117:18 | access to local variable x | provenance | |
11+
| BarrierFlow.cs:86:13:86:13 | access to local variable x : Object | BarrierFlow.cs:121:18:121:18 | access to local variable x | provenance | |
12+
| BarrierFlow.cs:86:17:86:25 | call to method Source : Object | BarrierFlow.cs:86:13:86:13 | access to local variable x : Object | provenance | |
13+
| BarrierFlow.cs:127:13:127:13 | access to local variable x : Object | BarrierFlow.cs:135:18:135:18 | access to local variable x | provenance | |
14+
| BarrierFlow.cs:127:13:127:13 | access to local variable x : Object | BarrierFlow.cs:140:18:140:18 | access to local variable x | provenance | |
15+
| BarrierFlow.cs:127:13:127:13 | access to local variable x : Object | BarrierFlow.cs:149:18:149:18 | access to local variable x | provenance | |
16+
| BarrierFlow.cs:127:13:127:13 | access to local variable x : Object | BarrierFlow.cs:158:18:158:18 | access to local variable x | provenance | |
17+
| BarrierFlow.cs:127:17:127:25 | call to method Source : Object | BarrierFlow.cs:127:13:127:13 | access to local variable x : Object | provenance | |
718
nodes
819
| BarrierFlow.cs:10:13:10:13 | access to local variable x : Object | semmle.label | access to local variable x : Object |
920
| BarrierFlow.cs:10:17:10:25 | call to method Source : Object | semmle.label | call to method Source : Object |
1021
| BarrierFlow.cs:12:14:12:14 | access to local variable x | semmle.label | access to local variable x |
1122
| BarrierFlow.cs:17:13:17:13 | access to local variable x : Object | semmle.label | access to local variable x : Object |
1223
| BarrierFlow.cs:17:17:17:25 | call to method Source : Object | semmle.label | call to method Source : Object |
1324
| BarrierFlow.cs:21:18:21:18 | access to local variable x | semmle.label | access to local variable x |
25+
| BarrierFlow.cs:86:13:86:13 | access to local variable x : Object | semmle.label | access to local variable x : Object |
26+
| BarrierFlow.cs:86:17:86:25 | call to method Source : Object | semmle.label | call to method Source : Object |
27+
| BarrierFlow.cs:94:18:94:18 | access to local variable x | semmle.label | access to local variable x |
28+
| BarrierFlow.cs:103:18:103:18 | access to local variable x | semmle.label | access to local variable x |
29+
| BarrierFlow.cs:112:18:112:18 | access to local variable x | semmle.label | access to local variable x |
30+
| BarrierFlow.cs:117:18:117:18 | access to local variable x | semmle.label | access to local variable x |
31+
| BarrierFlow.cs:121:18:121:18 | access to local variable x | semmle.label | access to local variable x |
32+
| BarrierFlow.cs:127:13:127:13 | access to local variable x : Object | semmle.label | access to local variable x : Object |
33+
| BarrierFlow.cs:127:17:127:25 | call to method Source : Object | semmle.label | call to method Source : Object |
34+
| BarrierFlow.cs:135:18:135:18 | access to local variable x | semmle.label | access to local variable x |
35+
| BarrierFlow.cs:140:18:140:18 | access to local variable x | semmle.label | access to local variable x |
36+
| BarrierFlow.cs:149:18:149:18 | access to local variable x | semmle.label | access to local variable x |
37+
| BarrierFlow.cs:158:18:158:18 | access to local variable x | semmle.label | access to local variable x |
1438
subpaths
1539
testFailures
40+
| BarrierFlow.cs:121:18:121:18 | access to local variable x | Unexpected result: hasValueFlow=7 |
1641
#select
1742
| BarrierFlow.cs:12:14:12:14 | access to local variable x | BarrierFlow.cs:10:17:10:25 | call to method Source : Object | BarrierFlow.cs:12:14:12:14 | access to local variable x | $@ | BarrierFlow.cs:10:17:10:25 | call to method Source : Object | call to method Source : Object |
1843
| BarrierFlow.cs:21:18:21:18 | access to local variable x | BarrierFlow.cs:17:17:17:25 | call to method Source : Object | BarrierFlow.cs:21:18:21:18 | access to local variable x | $@ | BarrierFlow.cs:17:17:17:25 | call to method Source : Object | call to method Source : Object |
44+
| BarrierFlow.cs:94:18:94:18 | access to local variable x | BarrierFlow.cs:86:17:86:25 | call to method Source : Object | BarrierFlow.cs:94:18:94:18 | access to local variable x | $@ | BarrierFlow.cs:86:17:86:25 | call to method Source : Object | call to method Source : Object |
45+
| BarrierFlow.cs:103:18:103:18 | access to local variable x | BarrierFlow.cs:86:17:86:25 | call to method Source : Object | BarrierFlow.cs:103:18:103:18 | access to local variable x | $@ | BarrierFlow.cs:86:17:86:25 | call to method Source : Object | call to method Source : Object |
46+
| BarrierFlow.cs:112:18:112:18 | access to local variable x | BarrierFlow.cs:86:17:86:25 | call to method Source : Object | BarrierFlow.cs:112:18:112:18 | access to local variable x | $@ | BarrierFlow.cs:86:17:86:25 | call to method Source : Object | call to method Source : Object |
47+
| BarrierFlow.cs:117:18:117:18 | access to local variable x | BarrierFlow.cs:86:17:86:25 | call to method Source : Object | BarrierFlow.cs:117:18:117:18 | access to local variable x | $@ | BarrierFlow.cs:86:17:86:25 | call to method Source : Object | call to method Source : Object |
48+
| BarrierFlow.cs:121:18:121:18 | access to local variable x | BarrierFlow.cs:86:17:86:25 | call to method Source : Object | BarrierFlow.cs:121:18:121:18 | access to local variable x | $@ | BarrierFlow.cs:86:17:86:25 | call to method Source : Object | call to method Source : Object |
49+
| BarrierFlow.cs:135:18:135:18 | access to local variable x | BarrierFlow.cs:127:17:127:25 | call to method Source : Object | BarrierFlow.cs:135:18:135:18 | access to local variable x | $@ | BarrierFlow.cs:127:17:127:25 | call to method Source : Object | call to method Source : Object |
50+
| BarrierFlow.cs:140:18:140:18 | access to local variable x | BarrierFlow.cs:127:17:127:25 | call to method Source : Object | BarrierFlow.cs:140:18:140:18 | access to local variable x | $@ | BarrierFlow.cs:127:17:127:25 | call to method Source : Object | call to method Source : Object |
51+
| BarrierFlow.cs:149:18:149:18 | access to local variable x | BarrierFlow.cs:127:17:127:25 | call to method Source : Object | BarrierFlow.cs:149:18:149:18 | access to local variable x | $@ | BarrierFlow.cs:127:17:127:25 | call to method Source : Object | call to method Source : Object |
52+
| BarrierFlow.cs:158:18:158:18 | access to local variable x | BarrierFlow.cs:127:17:127:25 | call to method Source : Object | BarrierFlow.cs:158:18:158:18 | access to local variable x | $@ | BarrierFlow.cs:127:17:127:25 | call to method Source : Object | call to method Source : Object |

0 commit comments

Comments
 (0)