Skip to content

Commit 97a487e

Browse files
committed
C#: Update the CFG implementation based on the new operations and remove hack that rotates children of assignments.
1 parent 7a9d8b6 commit 97a487e

File tree

1 file changed

+6
-41
lines changed

1 file changed

+6
-41
lines changed

csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,13 @@ class CfgScope extends Element, @top_level_exprorstmt_parent {
6262

6363
private class TAstNode = @callable or @control_flow_element;
6464

65-
private Element getAChild(Element p) {
66-
result = p.getAChild() or
67-
result = p.(AssignOperation).getExpandedAssignment()
68-
}
69-
7065
pragma[nomagic]
7166
private predicate astNode(Element e) {
7267
e = any(@top_level_exprorstmt_parent p | not p instanceof Attribute)
7368
or
7469
exists(Element parent |
7570
astNode(parent) and
76-
e = getAChild(parent)
71+
e = parent.getAChild()
7772
)
7873
}
7974

@@ -447,7 +442,6 @@ module Expressions {
447442
private AstNode getExprChild0(Expr e, int i) {
448443
not e instanceof NameOfExpr and
449444
not e instanceof QualifiableExpr and
450-
not e instanceof Assignment and
451445
not e instanceof AnonymousFunctionExpr and
452446
result = e.getChild(i)
453447
or
@@ -458,14 +452,6 @@ module Expressions {
458452
not qe instanceof ExtensionMethodCall and
459453
result = qe.getChild(i)
460454
)
461-
or
462-
e =
463-
any(Assignment a |
464-
// The left-hand side of an assignment is evaluated before the right-hand side
465-
i = 0 and result = a.getLValue()
466-
or
467-
i = 1 and result = a.getRValue()
468-
)
469455
}
470456

471457
private AstNode getExprChild(Expr e, int i) {
@@ -491,9 +477,8 @@ module Expressions {
491477
not this instanceof LogicalNotExpr and
492478
not this instanceof LogicalAndExpr and
493479
not this instanceof LogicalOrExpr and
494-
not this instanceof NullCoalescingExpr and
480+
not this instanceof NullCoalescingOperation and
495481
not this instanceof ConditionalExpr and
496-
not this instanceof AssignOperationWithExpandedAssignment and
497482
not this instanceof ConditionallyQualifiedExpr and
498483
not this instanceof ThrowExpr and
499484
not this instanceof ObjectCreation and
@@ -590,8 +575,7 @@ module Expressions {
590575
QualifiedAccessorWrite() {
591576
def.getExpr() = this and
592577
def.getTargetAccess().(WriteAccess) instanceof QualifiableExpr and
593-
not def instanceof AssignableDefinitions::OutRefDefinition and
594-
not this instanceof AssignOperationWithExpandedAssignment
578+
not def instanceof AssignableDefinitions::OutRefDefinition
595579
}
596580

597581
/**
@@ -723,7 +707,8 @@ module Expressions {
723707
}
724708
}
725709

726-
private class NullCoalescingExprTree extends PostOrderTree instanceof NullCoalescingExpr {
710+
private class NullCoalescingOperationTree extends PostOrderTree instanceof NullCoalescingOperation
711+
{
727712
final override predicate propagatesAbnormal(AstNode child) {
728713
child in [super.getLeftOperand(), super.getRightOperand()]
729714
}
@@ -774,26 +759,6 @@ module Expressions {
774759
}
775760
}
776761

777-
/**
778-
* An assignment operation that has an expanded version. We use the expanded
779-
* version in the control flow graph in order to get better data flow / taint
780-
* tracking.
781-
*/
782-
private class AssignOperationWithExpandedAssignment extends ControlFlowTree instanceof AssignOperation
783-
{
784-
private Expr expanded;
785-
786-
AssignOperationWithExpandedAssignment() { expanded = this.getExpandedAssignment() }
787-
788-
final override predicate first(AstNode first) { first(expanded, first) }
789-
790-
final override predicate last(AstNode last, Completion c) { last(expanded, last, c) }
791-
792-
final override predicate propagatesAbnormal(AstNode child) { none() }
793-
794-
final override predicate succ(AstNode pred, AstNode succ, Completion c) { none() }
795-
}
796-
797762
/** A conditionally qualified expression. */
798763
private class ConditionallyQualifiedExpr extends PostOrderTree instanceof QualifiableExpr {
799764
private Expr qualifier;
@@ -1551,7 +1516,7 @@ module Statements {
15511516
/** Gets a child of `cfe` that is in CFG scope `scope`. */
15521517
pragma[noinline]
15531518
private ControlFlowElement getAChildInScope(AstNode cfe, Callable scope) {
1554-
result = getAChild(cfe) and
1519+
result = cfe.getAChild() and
15551520
scope = result.getEnclosingCallable()
15561521
}
15571522

0 commit comments

Comments
 (0)