Skip to content

Commit 727ab94

Browse files
authored
Merge pull request #140 from hvitved/csharp/cfg/renaming
C#: Rename and restructure control flow graph entities
2 parents 43e1e62 + 061b3d4 commit 727ab94

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3029
-2941
lines changed

change-notes/1.18/analysis-csharp.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,22 @@
4040

4141
## Changes to QL libraries
4242

43-
* A new non-member predicate `mayBeDisposed()` can be used to determine if a variable is potentially disposed inside a library. It will analyse the CIL code in the library to determine this.
43+
* A new non-member predicate `mayBeDisposed()` can be used to determine if a variable is potentially disposed inside a library. It will analyse the CIL code in the library to determine this.
44+
* Several control flow graph entities have been renamed (the old names still exist for backwards compatibility):
45+
- `ControlFlowNode` has been renamed to `ControlFlow::Node`.
46+
- `CallableEntryNode` has been renamed to `ControlFlow::Nodes::EntryNode`.
47+
- `CallableExitNode` has been renamed to `ControlFlow::Nodes::ExitNode`.
48+
- `ControlFlowEdgeType` has been renamed to `ControlFlow::SuccessorType`.
49+
- `ControlFlowEdgeSuccessor` has been renamed to `ControlFlow::SuccessorTypes::NormalSuccessor`.
50+
- `ControlFlowEdgeConditional` has been renamed to `ControlFlow::SuccessorTypes::ConditionalSuccessor`.
51+
- `ControlFlowEdgeBoolean` has been renamed to `ControlFlow::SuccessorTypes::BooleanSuccessor`.
52+
- `ControlFlowEdgeNullness` has been renamed to `ControlFlow::SuccessorTypes::NullnessSuccessor`.
53+
- `ControlFlowEdgeMatching` has been renamed to `ControlFlow::SuccessorTypes::MatchingSuccessor`.
54+
- `ControlFlowEdgeEmptiness` has been renamed to `ControlFlow::SuccessorTypes::EmptinessSuccessor`.
55+
- `ControlFlowEdgeReturn` has been renamed to `ControlFlow::SuccessorTypes::ReturnSuccessor`.
56+
- `ControlFlowEdgeBreak` has been renamed to `ControlFlow::SuccessorTypes::BreakSuccessor`.
57+
- `ControlFlowEdgeContinue` has been renamed to `ControlFlow::SuccessorTypes::ContinueSuccessor`.
58+
- `ControlFlowEdgeGotoLabel` has been renamed to `ControlFlow::SuccessorTypes::GotoLabelSuccessor`.
59+
- `ControlFlowEdgeGotoCase` has been renamed to `ControlFlow::SuccessorTypes::GotoCaseSuccessor`.
60+
- `ControlFlowEdgeGotoDefault` has been renamed to `ControlFlow::SuccessorTypes::GotoDefaultSuccessor`.
61+
- `ControlFlowEdgeException` has been renamed to `ControlFlow::SuccessorTypes::ExceptionSuccessor`.

csharp/ql/src/API Abuse/Dispose.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ private import semmle.code.csharp.frameworks.system.web.UI
55

66
class DisposableType extends RefType {
77
DisposableType() {
8-
this.getABaseType+() = getSystemIDisposableInterface()
8+
this.getABaseType+() instanceof SystemIDisposableInterface
99
}
1010
}
1111

@@ -17,13 +17,13 @@ class DisposableField extends Field {
1717

1818
class WebControl extends RefType {
1919
WebControl() {
20-
this.getBaseClass*() = getSystemWebUIControlClass()
20+
this.getBaseClass*() instanceof SystemWebUIControlClass
2121
}
2222
}
2323

2424
class WebPage extends RefType {
2525
WebPage() {
26-
this.getBaseClass*() = getSystemWebUIPageClass()
26+
this.getBaseClass*() instanceof SystemWebUIPageClass
2727
}
2828
}
2929

csharp/ql/src/Bad Practices/Control-Flow/ConstantCondition.ql

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import csharp
1515
import semmle.code.csharp.commons.Assertions
1616
import semmle.code.csharp.commons.Constants
17-
import ControlFlowGraph
1817

1918
/** A constant condition. */
2019
abstract class ConstantCondition extends Expr {
@@ -76,13 +75,13 @@ class ConstantNullnessCondition extends ConstantCondition {
7675
boolean b;
7776

7877
ConstantNullnessCondition() {
79-
forex(ControlFlowNode cfn |
78+
forex(ControlFlow::Node cfn |
8079
cfn = this.getAControlFlowNode() |
81-
exists(ControlFlowEdgeNullness t |
80+
exists(ControlFlow::SuccessorTypes::NullnessSuccessor t |
8281
exists(cfn.getASuccessorByType(t)) |
8382
if t.isNull() then b = true else b = false
8483
) and
85-
strictcount(ControlFlowEdgeType t | exists(cfn.getASuccessorByType(t))) = 1
84+
strictcount(ControlFlow::SuccessorType t | exists(cfn.getASuccessorByType(t))) = 1
8685
)
8786
}
8887

@@ -99,13 +98,13 @@ class ConstantMatchingCondition extends ConstantCondition {
9998
boolean b;
10099

101100
ConstantMatchingCondition() {
102-
forex(ControlFlowNode cfn |
101+
forex(ControlFlow::Node cfn |
103102
cfn = this.getAControlFlowNode() |
104-
exists(ControlFlowEdgeMatching t |
103+
exists(ControlFlow::SuccessorTypes::MatchingSuccessor t |
105104
exists(cfn.getASuccessorByType(t)) |
106105
if t.isMatch() then b = true else b = false
107106
) and
108-
strictcount(ControlFlowEdgeType t | exists(cfn.getASuccessorByType(t))) = 1
107+
strictcount(ControlFlow::SuccessorType t | exists(cfn.getASuccessorByType(t))) = 1
109108
)
110109
}
111110

csharp/ql/src/Bad Practices/ErroneousClassCompare.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ class StringComparison extends Expr {
3535
from StringComparison sc, PropertyAccess pa
3636
where sc.getAnOperand() instanceof StringLiteral
3737
and sc.getAnOperand() = pa
38-
and pa.getTarget() = getSystemTypeClass().getFullNameProperty()
38+
and pa.getTarget() = any(SystemTypeClass c).getFullNameProperty()
3939
select sc, "Erroneous class compare."

csharp/ql/src/Concurrency/Concurrency.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,17 @@ class LockStmtBlock extends LockedBlock
102102
exists( LockStmt s | this=s.getBlock() )
103103
}
104104

105-
predicate isLockThis()
105+
override predicate isLockThis()
106106
{
107107
exists( LockStmt s | this=s.getBlock() and s.isLockThis() )
108108
}
109109

110-
Variable getLockVariable()
110+
override Variable getLockVariable()
111111
{
112112
exists( LockStmt s | this=s.getBlock() and result=s.getLockVariable() )
113113
}
114114

115-
Type getLockTypeObject()
115+
override Type getLockTypeObject()
116116
{
117117
exists( LockStmt s | this=s.getBlock() and result=s.getLockTypeObject() )
118118
}
@@ -138,17 +138,17 @@ class SynchronizedMethodBlock extends LockedBlock
138138
{
139139
exists( SynchronizedMethod m | this=m.getStatementBody() )
140140
}
141-
predicate isLockThis()
141+
override predicate isLockThis()
142142
{
143143
exists( SynchronizedMethod m | this=m.getStatementBody() and m.isLockThis() )
144144
}
145145

146-
Variable getLockVariable()
146+
override Variable getLockVariable()
147147
{
148148
none()
149149
}
150150

151-
Type getLockTypeObject()
151+
override Type getLockTypeObject()
152152
{
153153
exists( SynchronizedMethod m | this=m.getStatementBody() and result=m.getLockTypeObject() )
154154
}

csharp/ql/src/Concurrency/UnsynchronizedStaticAccess.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import csharp
1414
import DataMembers
1515
import ThreadCreation
16-
import ControlFlowGraph
1716

1817
predicate correctlySynchronized(CollectionMember c, Expr access) {
1918
access = c.getAReadOrWrite() and
@@ -24,9 +23,9 @@ predicate correctlySynchronized(CollectionMember c, Expr access) {
2423
)
2524
}
2625

27-
ControlFlowNode unlockedReachable(Callable a) {
26+
ControlFlow::Node unlockedReachable(Callable a) {
2827
result = a.getEntryPoint() or
29-
exists(ControlFlowNode mid | mid = unlockedReachable(a) |
28+
exists(ControlFlow::Node mid | mid = unlockedReachable(a) |
3029
not mid.getElement() instanceof LockingCall and
3130
result = mid.getASuccessor()
3231
)

csharp/ql/src/Likely Bugs/NestedLoopsSameVariable.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import csharp
1515
import semmle.code.csharp.commons.ComparisonTest
16-
import semmle.code.csharp.controlflow.ControlFlowGraph::ControlFlowGraph
1716
import semmle.code.csharp.commons.StructuralComparison as SC
1817

1918
/** A structural comparison configuration for comparing the conditions of nested `for` loops. */
@@ -87,13 +86,13 @@ class NestedForLoopSameVariable extends ForStmt {
8786
}
8887

8988
/** Finds elements inside the outer loop that are no longer guarded by the loop invariant. */
90-
private ControlFlowNode getAnUnguardedNode()
89+
private ControlFlow::Node getAnUnguardedNode()
9190
{
9291
result.getElement().getParent+() = getOuterForStmt().getBody() and
9392
(
9493
result = this.getCondition().(ControlFlowElement).getAControlFlowExitNode().getAFalseSuccessor()
9594
or
96-
exists(ControlFlowNode mid | mid = getAnUnguardedNode() |
95+
exists(ControlFlow::Node mid | mid = getAnUnguardedNode() |
9796
mid.getASuccessor() = result and
9897
not exists(getAComparisonTest(result.getElement()))
9998
)

csharp/ql/src/Likely Bugs/Statements/UseBraces.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import csharp
1515

1616
// Iterate the control flow until we reach a Stmt
17-
Stmt findSuccessorStmt(ControlFlowGraph::ControlFlowNode n)
17+
Stmt findSuccessorStmt(ControlFlow::Node n)
1818
{
1919
result=n.getElement() or
2020
not n.getElement() instanceof Stmt and result=findSuccessorStmt(n.getASuccessor())

csharp/ql/src/Likely Bugs/UncheckedCastInEquals.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
import csharp
1313
import semmle.code.csharp.frameworks.System
1414

15-
predicate nodeBeforeParameterAccess(ControlFlowGraph::ControlFlowNode node)
15+
predicate nodeBeforeParameterAccess(ControlFlow::Node node)
1616
{
1717
exists(EqualsMethod equals | equals.getBody() = node.getElement())
1818
or
19-
exists(EqualsMethod equals, Parameter param, ControlFlowGraph::ControlFlowNode mid |
19+
exists(EqualsMethod equals, Parameter param, ControlFlow::Node mid |
2020
equals.getParameter(0) = param and
2121
equals.getAChild*() = mid.getElement() and
2222
nodeBeforeParameterAccess(mid) and

csharp/ql/src/Performance/StringBuilderInLoop.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import csharp
1212
import semmle.code.csharp.frameworks.system.Text
1313

14-
from ObjectCreation creation, LoopStmt loop, ControlFlowGraph::ControlFlowNode loopEntryNode
14+
from ObjectCreation creation, LoopStmt loop, ControlFlow::Node loopEntryNode
1515
where creation.getType() instanceof SystemTextStringBuilderClass
1616
and loopEntryNode = loop.getBody().getAControlFlowEntryNode()
1717
and loop.getBody().getAChild*() = creation

0 commit comments

Comments
 (0)