Skip to content

Commit 88b7ad0

Browse files
committed
C#: Take phi nodes into account in Steps::getARead()
1 parent cb8e2d4 commit 88b7ad0

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

csharp/ql/src/semmle/code/csharp/dataflow/internal/Steps.qll

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ import csharp
66
* Provides functionality for performing simple data flow analysis.
77
* This library is used by the dispatch library, which in turn is used by the
88
* SSA library, so we cannot make use of the SSA library in this library.
9-
* Instead, this library relies on a self-contained, minimalistic SSA-like
10-
* implementation.
9+
* Instead, this library relies on the `BaseSsa` library.
1110
*/
1211
module Steps {
1312
private import semmle.code.csharp.dataflow.internal.BaseSSA
1413

1514
/**
16-
* Gets a read that is guaranteed to read the value assigned at definition `def`.
15+
* Gets a read that may read the value assigned at definition `def`.
1716
*/
1817
private AssignableRead getARead(AssignableDefinition def) {
1918
exists(BaseSsa::Definition ssaDef |
20-
ssaDef.getDefinition() = def and
19+
ssaDef.getAnUltimateDefinition().getDefinition() = def and
2120
result = ssaDef.getARead()
2221
)
2322
or

csharp/ql/test/query-tests/Dead Code/DeadStoreOfLocal/DeadStoreOfLocal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ void M9()
278278

279279
void M10(bool b)
280280
{
281-
var x = ""; // GOOD [FALSE POSITIVE]
281+
var x = ""; // GOOD
282282
Action action;
283283
if (b)
284284
action = () => System.Console.WriteLine(x);

csharp/ql/test/query-tests/Dead Code/DeadStoreOfLocal/DeadStoreOfLocal.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
| DeadStoreOfLocal.cs:142:26:142:27 | Exception ex | This assignment to $@ is useless, since its value is never read. | DeadStoreOfLocal.cs:142:26:142:27 | ex | ex |
1010
| DeadStoreOfLocal.cs:246:17:246:24 | Int32 y = ... | This assignment to $@ is useless, since its value is never read. | DeadStoreOfLocal.cs:246:17:246:17 | y | y |
1111
| DeadStoreOfLocal.cs:261:17:261:21 | Int32 x = ... | This assignment to $@ is useless, since its value is never read. | DeadStoreOfLocal.cs:261:17:261:17 | x | x |
12-
| DeadStoreOfLocal.cs:281:13:281:18 | String x = ... | This assignment to $@ is useless, since its value is never read. | DeadStoreOfLocal.cs:281:13:281:13 | x | x |
1312
| DeadStoreOfLocal.cs:300:23:300:28 | Object v1 | This assignment to $@ is useless, since its value is never read. | DeadStoreOfLocal.cs:300:27:300:28 | v1 | v1 |
1413
| DeadStoreOfLocal.cs:314:18:314:23 | Object v2 | This assignment to $@ is useless, since its value is never read. | DeadStoreOfLocal.cs:314:22:314:23 | v2 | v2 |
1514
| DeadStoreOfLocal.cs:331:9:331:32 | ... = ... | This assignment to $@ is useless, since its value is never read. | DeadStoreOfLocal.cs:327:23:327:23 | b | b |

0 commit comments

Comments
 (0)