Skip to content

Commit 5a986f5

Browse files
committed
SSA: Remove empty predicates and dead code.
1 parent 308d154 commit 5a986f5

File tree

7 files changed

+3
-114
lines changed
  • cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal
  • csharp/ql/lib/semmle/code/csharp/dataflow/internal
  • javascript/ql/lib/semmle/javascript/dataflow/internal/sharedlib
  • java/ql/lib/semmle/code/java/dataflow/internal
  • ruby/ql/lib/codeql/ruby/dataflow/internal
  • rust/ql/lib/codeql/rust/dataflow/internal
  • shared/ssa/codeql/ssa

7 files changed

+3
-114
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternals.qll

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,6 @@ class GlobalDef extends Definition {
956956
private module SsaImpl = SsaImplCommon::Make<Location, SsaInput>;
957957

958958
private module DataFlowIntegrationInput implements SsaImpl::DataFlowIntegrationInputSig {
959-
private import codeql.util.Void
960-
961959
class Expr extends Instruction {
962960
Expr() {
963961
exists(IRBlock bb, int i |
@@ -979,14 +977,6 @@ private module DataFlowIntegrationInput implements SsaImpl::DataFlowIntegrationI
979977

980978
predicate ssaDefHasSource(SsaImpl::WriteDefinition def) { none() }
981979

982-
predicate ssaDefAssigns(SsaImpl::WriteDefinition def, Expr value) { none() }
983-
984-
class Parameter extends Void {
985-
Location getLocation() { none() }
986-
}
987-
988-
predicate ssaDefInitializesParam(SsaImpl::WriteDefinition def, Parameter p) { none() }
989-
990980
predicate allowFlowIntoUncertainDef(SsaImpl::UncertainWriteDefinition def) { any() }
991981

992982
private EdgeKind getConditionalEdge(boolean branch) {

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,16 +1029,6 @@ private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInpu
10291029
def instanceof Ssa::ImplicitParameterDefinition
10301030
}
10311031

1032-
predicate ssaDefAssigns(WriteDefinition def, Expr value) {
1033-
// exclude flow directly from RHS to SSA definition, as we instead want to
1034-
// go from RHS to matching assingnable definition, and from there to SSA definition
1035-
none()
1036-
}
1037-
1038-
class Parameter = Ssa::ImplicitParameterDefinition;
1039-
1040-
predicate ssaDefInitializesParam(WriteDefinition def, Parameter p) { none() }
1041-
10421032
/**
10431033
* Allows for flow into uncertain defintions that are not call definitions,
10441034
* as we, conservatively, consider such definitions to be certain.

java/ql/lib/semmle/code/java/dataflow/internal/SsaImpl.qll

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -647,16 +647,10 @@ private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInpu
647647

648648
Expr getARead(Definition def) { result = getAUse(def) }
649649

650-
class Parameter = J::Parameter;
651-
652650
predicate ssaDefHasSource(WriteDefinition def) {
653651
def instanceof SsaExplicitUpdate or def.(SsaImplicitInit).isParameterDefinition(_)
654652
}
655653

656-
predicate ssaDefAssigns(Impl::WriteDefinition def, Expr value) { none() }
657-
658-
predicate ssaDefInitializesParam(Impl::WriteDefinition def, Parameter p) { none() }
659-
660654
predicate allowFlowIntoUncertainDef(UncertainWriteDefinition def) {
661655
def instanceof SsaUncertainImplicitUpdate
662656
}

javascript/ql/lib/semmle/javascript/dataflow/internal/sharedlib/Ssa.qll

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,6 @@ module SsaDataflowInput implements DataFlowIntegrationInputSig {
6161
none()
6262
}
6363

64-
predicate ssaDefAssigns(WriteDefinition def, Expr value) {
65-
// This library only handles use-use flow after a post-update, there are no definitions, only uses.
66-
none()
67-
}
68-
69-
class Parameter = js::Parameter;
70-
71-
predicate ssaDefInitializesParam(WriteDefinition def, Parameter p) {
72-
// This library only handles use-use flow after a post-update, there are no definitions, only uses.
73-
none()
74-
}
75-
7664
cached
7765
Expr getARead(Definition def) {
7866
// Copied from implementation so we can cache it here

ruby/ql/lib/codeql/ruby/dataflow/internal/SsaImpl.qll

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,18 +473,12 @@ class ParameterExt extends TParameterExt {
473473
private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInputSig {
474474
private import codeql.ruby.controlflow.internal.Guards as Guards
475475

476-
class Parameter = ParameterExt;
477-
478476
class Expr extends Cfg::CfgNodes::ExprCfgNode {
479477
predicate hasCfgNode(SsaInput::BasicBlock bb, int i) { this = bb.getNode(i) }
480478
}
481479

482480
Expr getARead(Definition def) { result = Cached::getARead(def) }
483481

484-
predicate ssaDefAssigns(WriteDefinition def, Expr value) { none() }
485-
486-
predicate ssaDefInitializesParam(WriteDefinition def, Parameter p) { none() }
487-
488482
class Guard extends Cfg::CfgNodes::AstCfgNode {
489483
/**
490484
* Holds if the control flow branching from `bb1` is dependent on this guard,

rust/ql/lib/codeql/rust/dataflow/internal/SsaImpl.qll

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,6 @@ private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInpu
342342

343343
predicate ssaDefHasSource(WriteDefinition def) { none() } // handled in `DataFlowImpl.qll` instead
344344

345-
/** Holds if SSA definition `def` assigns `value` to the underlying variable. */
346-
predicate ssaDefAssigns(WriteDefinition def, Expr value) {
347-
none() // handled in `DataFlowImpl.qll` instead
348-
}
349-
350345
private predicate isArg(CfgNodes::CallExprBaseCfgNode call, CfgNodes::ExprCfgNode e) {
351346
call.getArgument(_) = e
352347
or
@@ -366,13 +361,6 @@ private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInpu
366361
)
367362
}
368363

369-
class Parameter = CfgNodes::ParamBaseCfgNode;
370-
371-
/** Holds if SSA definition `def` initializes parameter `p` at function entry. */
372-
predicate ssaDefInitializesParam(WriteDefinition def, Parameter p) {
373-
none() // handled in `DataFlowImpl.qll` instead
374-
}
375-
376364
class Guard extends CfgNodes::AstCfgNode {
377365
/**
378366
* Holds if the control flow branching from `bb1` is dependent on this guard,

shared/ssa/codeql/ssa/Ssa.qll

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,21 +1468,6 @@ module Make<LocationSig Location, InputSig<Location> Input> {
14681468
*/
14691469
default predicate ssaDefHasSource(WriteDefinition def) { any() }
14701470

1471-
/** Holds if SSA definition `def` assigns `value` to the underlying variable. */
1472-
predicate ssaDefAssigns(WriteDefinition def, Expr value);
1473-
1474-
/** A parameter. */
1475-
class Parameter {
1476-
/** Gets a textual representation of this parameter. */
1477-
string toString();
1478-
1479-
/** Gets the location of this parameter. */
1480-
Location getLocation();
1481-
}
1482-
1483-
/** Holds if SSA definition `def` initializes parameter `p` at function entry. */
1484-
predicate ssaDefInitializesParam(WriteDefinition def, Parameter p);
1485-
14861471
/**
14871472
* Holds if flow should be allowed into uncertain SSA definition `def` from
14881473
* previous definitions or reads.
@@ -1675,17 +1660,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {
16751660
cached
16761661
private newtype TNode =
16771662
TWriteDefSource(WriteDefinition def) { DfInput::ssaDefHasSource(def) } or
1678-
TParamNode(DfInput::Parameter p) {
1679-
exists(WriteDefinition def | DfInput::ssaDefInitializesParam(def, p))
1680-
} or
1681-
TExprNode(DfInput::Expr e, Boolean isPost) {
1682-
e = DfInput::getARead(_)
1683-
or
1684-
exists(DefinitionExt def |
1685-
DfInput::ssaDefAssigns(def, e) and
1686-
isPost = false
1687-
)
1688-
} or
1663+
TExprNode(DfInput::Expr e, Boolean isPost) { e = DfInput::getARead(_) } or
16891664
TSsaDefinitionNode(DefinitionExt def) { not phiHasUniqNextNode(def) } or
16901665
TSsaInputNode(SsaPhiExt phi, BasicBlock input) { relevantPhiInputNode(phi, input) }
16911666

@@ -1722,22 +1697,6 @@ module Make<LocationSig Location, InputSig<Location> Input> {
17221697

17231698
final class WriteDefSourceNode = WriteDefSourceNodeImpl;
17241699

1725-
/** A parameter node. */
1726-
private class ParameterNodeImpl extends NodeImpl, TParamNode {
1727-
private DfInput::Parameter p;
1728-
1729-
ParameterNodeImpl() { this = TParamNode(p) }
1730-
1731-
/** Gets the underlying parameter. */
1732-
DfInput::Parameter getParameter() { result = p }
1733-
1734-
override string toString() { result = p.toString() }
1735-
1736-
override Location getLocation() { result = p.getLocation() }
1737-
}
1738-
1739-
final class ParameterNode = ParameterNodeImpl;
1740-
17411700
/** A (post-update) expression node. */
17421701
abstract private class ExprNodePreOrPostImpl extends NodeImpl, TExprNode {
17431702
DfInput::Expr e;
@@ -2003,14 +1962,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {
20031962
predicate localFlowStep(SourceVariable v, Node nodeFrom, Node nodeTo, boolean isUseStep) {
20041963
exists(Definition def |
20051964
// Flow from write definition source into SSA definition
2006-
nodeFrom = TWriteDefSource(def)
2007-
or
2008-
// Flow from assignment into SSA definition
2009-
DfInput::ssaDefAssigns(def, nodeFrom.(ExprNode).getExpr())
2010-
or
2011-
// Flow from parameter into entry definition
2012-
DfInput::ssaDefInitializesParam(def, nodeFrom.(ParameterNode).getParameter())
2013-
|
1965+
nodeFrom = TWriteDefSource(def) and
20141966
isUseStep = false and
20151967
if DfInput::includeWriteDefsInFlowStep()
20161968
then
@@ -2042,14 +1994,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {
20421994
predicate localMustFlowStep(SourceVariable v, Node nodeFrom, Node nodeTo) {
20431995
exists(Definition def |
20441996
// Flow from write definition source into SSA definition
2045-
nodeFrom = TWriteDefSource(def)
2046-
or
2047-
// Flow from assignment into SSA definition
2048-
DfInput::ssaDefAssigns(def, nodeFrom.(ExprNode).getExpr())
2049-
or
2050-
// Flow from parameter into entry definition
2051-
DfInput::ssaDefInitializesParam(def, nodeFrom.(ParameterNode).getParameter())
2052-
|
1997+
nodeFrom = TWriteDefSource(def) and
20531998
v = def.getSourceVariable() and
20541999
if DfInput::includeWriteDefsInFlowStep()
20552000
then nodeTo.(SsaDefinitionNode).getDefinition() = def

0 commit comments

Comments
 (0)