Skip to content

Commit 0583d85

Browse files
committed
C#: Remove getDefinitionExt references.
1 parent db7ec4a commit 0583d85

File tree

2 files changed

+28
-62
lines changed

2 files changed

+28
-62
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

Lines changed: 17 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ module LocalFlow {
664664
ssaDef.getADefinition() = def and
665665
ssaDef.getControlFlowNode() = cfn and
666666
nodeFrom = TAssignableDefinitionNode(def, cfn) and
667-
nodeTo.(SsaDefinitionExtNode).getDefinitionExt() = ssaDef
667+
nodeTo.(SsaDefinitionNode).getDefinition() = ssaDef
668668
)
669669
}
670670

@@ -1269,78 +1269,33 @@ predicate nodeIsHidden(Node n) {
12691269
}
12701270

12711271
/** An SSA node. */
1272-
abstract class SsaNode extends NodeImpl, TSsaNode {
1272+
class SsaNode extends NodeImpl, TSsaNode {
12731273
SsaImpl::DataFlowIntegration::SsaNode node;
1274-
SsaImpl::DefinitionExt def;
12751274

1276-
SsaNode() {
1277-
this = TSsaNode(node) and
1278-
def = node.getDefinitionExt()
1279-
}
1280-
1281-
SsaImpl::DefinitionExt getDefinitionExt() { result = def }
1275+
SsaNode() { this = TSsaNode(node) }
12821276

12831277
override DataFlowCallable getEnclosingCallableImpl() {
1284-
result.getAControlFlowNode().getBasicBlock() = def.getBasicBlock()
1278+
result.getAControlFlowNode().getBasicBlock() = node.getBasicBlock()
12851279
}
12861280

1287-
override Type getTypeImpl() { result = def.getSourceVariable().getType() }
1281+
override Type getTypeImpl() { result = node.getSourceVariable().getType() }
12881282

1289-
override ControlFlow::Node getControlFlowNodeImpl() {
1290-
result = def.(Ssa::Definition).getControlFlowNode()
1291-
}
1283+
override ControlFlow::Node getControlFlowNodeImpl() { none() }
12921284

12931285
override Location getLocationImpl() { result = node.getLocation() }
12941286

12951287
override string toStringImpl() { result = node.toString() }
12961288
}
12971289

1298-
/** An (extended) SSA definition, viewed as a node in a data flow graph. */
1299-
class SsaDefinitionExtNode extends SsaNode {
1300-
override SsaImpl::DataFlowIntegration::SsaDefinitionExtNode node;
1301-
}
1290+
/** An SSA definition, viewed as a node in a data flow graph. */
1291+
class SsaDefinitionNode extends SsaNode {
1292+
override SsaImpl::DataFlowIntegration::SsaDefinitionNode node;
13021293

1303-
/**
1304-
* A node that represents an input to an SSA phi (read) definition.
1305-
*
1306-
* This allows for barrier guards to filter input to phi nodes. For example, in
1307-
*
1308-
* ```csharp
1309-
* var x = taint;
1310-
* if (x != "safe")
1311-
* {
1312-
* x = "safe";
1313-
* }
1314-
* sink(x);
1315-
* ```
1316-
*
1317-
* the `false` edge out of `x != "safe"` guards the input from `x = taint` into the
1318-
* `phi` node after the condition.
1319-
*
1320-
* It is also relevant to filter input into phi read nodes:
1321-
*
1322-
* ```csharp
1323-
* var x = taint;
1324-
* if (b)
1325-
* {
1326-
* if (x != "safe1")
1327-
* {
1328-
* return;
1329-
* }
1330-
* } else {
1331-
* if (x != "safe2")
1332-
* {
1333-
* return;
1334-
* }
1335-
* }
1336-
*
1337-
* sink(x);
1338-
* ```
1339-
*
1340-
* both inputs into the phi read node after the outer condition are guarded.
1341-
*/
1342-
class SsaInputNode extends SsaNode {
1343-
override SsaImpl::DataFlowIntegration::SsaInputNode node;
1294+
SsaImpl::Definition getDefinition() { result = node.getDefinition() }
1295+
1296+
override ControlFlow::Node getControlFlowNodeImpl() {
1297+
result = this.getDefinition().(Ssa::Definition).getControlFlowNode()
1298+
}
13441299
}
13451300

13461301
/** A definition, viewed as a node in a data flow graph. */
@@ -1728,12 +1683,12 @@ private module ReturnNodes {
17281683
* A data-flow node that represents an assignment to an `out` or a `ref`
17291684
* parameter.
17301685
*/
1731-
class OutRefReturnNode extends ReturnNode, SsaDefinitionExtNode {
1686+
class OutRefReturnNode extends ReturnNode, SsaDefinitionNode {
17321687
OutRefReturnKind kind;
17331688

17341689
OutRefReturnNode() {
17351690
exists(Parameter p |
1736-
this.getDefinitionExt().(Ssa::Definition).isLiveOutRefParameterDefinition(p) and
1691+
this.getDefinition().(Ssa::Definition).isLiveOutRefParameterDefinition(p) and
17371692
kind.getPosition() = p.getPosition()
17381693
|
17391694
p.isOut() and kind instanceof OutReturnKind
@@ -2464,7 +2419,7 @@ private predicate readContentStep(Node node1, Content c, Node node2) {
24642419
exists(ForeachStmt fs, Ssa::ExplicitDefinition def |
24652420
x.hasDefPath(fs.getIterableExpr(), node1.getControlFlowNode(), def.getADefinition(),
24662421
def.getControlFlowNode()) and
2467-
node2.(SsaDefinitionExtNode).getDefinitionExt() = def and
2422+
node2.(SsaDefinitionNode).getDefinition() = def and
24682423
c instanceof ElementContent
24692424
)
24702425
or

shared/ssa/codeql/ssa/Ssa.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,17 @@ module Make<LocationSig Location, InputSig<Location> Input> {
16771677

16781678
final class SsaDefinitionExtNode = SsaDefinitionExtNodeImpl;
16791679

1680+
/** An SSA definition, viewed as a node in a data flow graph. */
1681+
private class SsaDefinitionNodeImpl extends SsaDefinitionExtNodeImpl {
1682+
private Definition def;
1683+
1684+
SsaDefinitionNodeImpl() { this = TSsaDefinitionNode(def) }
1685+
1686+
Definition getDefinition() { result = def }
1687+
}
1688+
1689+
final class SsaDefinitionNode = SsaDefinitionNodeImpl;
1690+
16801691
/**
16811692
* A node that represents an input to an SSA phi (read) definition.
16821693
*

0 commit comments

Comments
 (0)