Skip to content

Commit a402ce5

Browse files
committed
C#: Fix bad join in cs/coalesce-of-identical-expressions.
1 parent 147ac37 commit a402ce5

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

csharp/ql/src/Language Abuse/UselessNullCoalescingExpression.ql

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,21 @@
1515
import csharp
1616
import semmle.code.csharp.commons.StructuralComparison
1717

18+
pragma[nomagic]
19+
private predicate relevant(Expr left, Expr right) {
20+
exists(NullCoalescingOperation nce |
21+
left = nce.getLeftOperand() and
22+
right = nce.getRightOperand()
23+
)
24+
}
25+
1826
pragma[noinline]
1927
private predicate same(AssignableAccess x, AssignableAccess y) {
20-
exists(NullCoalescingOperation nc |
21-
x = nc.getLeftOperand() and
22-
y = nc.getRightOperand().getAChildExpr*()
23-
) and
24-
sameGvn(x, y)
28+
exists(Expr e |
29+
relevant(x, e) and
30+
y = e.getAChildExpr*() and
31+
sameGvn(x, y)
32+
)
2533
}
2634

2735
private predicate uselessNullCoalescingOperation(NullCoalescingOperation nce) {

0 commit comments

Comments
 (0)