Skip to content

Commit 8e7c7d8

Browse files
committed
C#: Use Gvn comparison instead of StructuralComparisonConfiguration in UselessNullCoalescingExpression.
1 parent 4a1981e commit 8e7c7d8

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

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

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,14 @@
1414
import csharp
1515
import semmle.code.csharp.commons.StructuralComparison
1616

17-
class StructuralComparisonConfig extends StructuralComparisonConfiguration {
18-
StructuralComparisonConfig() { this = "UselessNullCoalescingExpression" }
19-
20-
override predicate candidate(ControlFlowElement x, ControlFlowElement y) {
21-
exists(NullCoalescingExpr nce |
22-
x.(Access) = nce.getLeftOperand() and
23-
y.(Access) = nce.getRightOperand().getAChildExpr*()
24-
)
25-
}
26-
27-
NullCoalescingExpr getUselessNullCoalescingExpr() {
28-
exists(AssignableAccess x |
29-
result.getLeftOperand() = x and
30-
forex(AssignableAccess y | same(x, y) | y instanceof AssignableRead and not y.isRefArgument())
31-
)
32-
}
17+
private predicate uselessNullCoalescingExpr(NullCoalescingExpr nce) {
18+
forex(AssignableAccess y |
19+
y = nce.getRightOperand().getAChildExpr*() and sameGvn(nce.getLeftOperand(), y)
20+
|
21+
y instanceof AssignableRead and not y.isRefArgument()
22+
)
3323
}
3424

35-
from StructuralComparisonConfig c, NullCoalescingExpr nce
36-
where nce = c.getUselessNullCoalescingExpr()
25+
from NullCoalescingExpr nce
26+
where uselessNullCoalescingExpr(nce)
3727
select nce, "Both operands of this null-coalescing expression access the same variable or property."

0 commit comments

Comments
 (0)