Skip to content

Commit 7a92970

Browse files
committed
Go: Remove omittable exists variables
1 parent 2ca0df0 commit 7a92970

File tree

20 files changed

+99
-135
lines changed

20 files changed

+99
-135
lines changed

go/ql/lib/semmle/go/Expr.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,7 @@ class ReferenceExpr extends Expr {
22112211
this = rs.getValue()
22122212
)
22132213
or
2214-
exists(ValueSpec spec, int i | this = spec.getNameExpr(i))
2214+
exists(ValueSpec spec | this = spec.getNameExpr(_))
22152215
or
22162216
exists(FuncDecl fd | this = fd.getNameExpr())
22172217
}

go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ newtype TControlFlowNode =
196196
* expression is initialized.
197197
*/
198198
MkZeroInitNode(ValueEntity v) {
199-
exists(ValueSpec spec, int i |
199+
exists(ValueSpec spec |
200200
not exists(spec.getAnInit()) and
201-
spec.getNameExpr(i) = v.getDeclaration()
201+
spec.getNameExpr(_) = v.getDeclaration()
202202
)
203203
or
204204
exists(v.(ResultVariable).getFunction().getBody())
@@ -2057,7 +2057,7 @@ module CFG {
20572057
*/
20582058
cached
20592059
predicate mayReturnNormally(ControlFlowTree root) {
2060-
exists(ControlFlow::Node last, Completion cmpl | lastNode(root, last, cmpl) and cmpl != Panic())
2060+
exists(Completion cmpl | lastNode(root, _, cmpl) and cmpl != Panic())
20612061
}
20622062

20632063
/**

go/ql/lib/semmle/go/dataflow/SSA.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ class SsaWithFields extends TSsaWithFields {
344344
SsaVariable getBaseVariable() {
345345
this = TRoot(result)
346346
or
347-
exists(SsaWithFields base, Field f | this = TStep(base, f) | result = base.getBaseVariable())
347+
exists(SsaWithFields base | this = TStep(base, _) | result = base.getBaseVariable())
348348
}
349349

350350
/** Gets a use that refers to this SSA variable with fields. */

go/ql/lib/semmle/go/dataflow/internal/DataFlowDispatch.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private predicate isConcreteInterfaceCall(DataFlow::Node call, DataFlow::Node re
5656
* but its concrete types can be determined by local reasoning.
5757
*/
5858
private DataFlowCallable getConcreteTarget(DataFlow::CallNode call) {
59-
exists(DataFlow::Node recv, string m | isConcreteInterfaceCall(call, recv, m) |
59+
exists(string m | isConcreteInterfaceCall(call, _, m) |
6060
exists(Type concreteReceiverType |
6161
concreteReceiverType = getConcreteType(getInterfaceCallReceiverSource(call)) and
6262
result.asFunction() = concreteReceiverType.getMethod(m)

go/ql/lib/semmle/go/dataflow/internal/DataFlowImpl.qll

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -876,9 +876,9 @@ private module Stage1 implements StageSig {
876876

877877
pragma[nomagic]
878878
private predicate revFlowOut(ReturnPosition pos, Configuration config) {
879-
exists(DataFlowCall call, NodeEx out |
879+
exists(NodeEx out |
880880
revFlow(out, _, config) and
881-
viableReturnPosOutNodeCandFwd1(call, pos, out, config)
881+
viableReturnPosOutNodeCandFwd1(_, pos, out, config)
882882
)
883883
}
884884

@@ -1731,8 +1731,8 @@ private module MkStage<StageSig PrevStage> {
17311731
)
17321732
or
17331733
// flow through a callable
1734-
exists(DataFlowCall call, ParamNodeEx p, ReturnPosition pos, Ap innerReturnAp |
1735-
revFlowThrough(call, returnCtx, p, state, pos, returnAp, ap, innerReturnAp, config) and
1734+
exists(DataFlowCall call, ParamNodeEx p, Ap innerReturnAp |
1735+
revFlowThrough(call, returnCtx, p, state, _, returnAp, ap, innerReturnAp, config) and
17361736
flowThroughIntoCall(call, node, p, _, ap, innerReturnAp, config)
17371737
)
17381738
or
@@ -1901,8 +1901,8 @@ private module MkStage<StageSig PrevStage> {
19011901

19021902
pragma[nomagic]
19031903
predicate parameterMayFlowThrough(ParamNodeEx p, Ap ap, Configuration config) {
1904-
exists(RetNodeEx ret, ReturnPosition pos |
1905-
returnFlowsThrough(ret, pos, _, _, p, ap, _, config) and
1904+
exists(ReturnPosition pos |
1905+
returnFlowsThrough(_, pos, _, _, p, ap, _, config) and
19061906
parameterFlowsThroughRev(p, ap, pos, _, config)
19071907
)
19081908
}
@@ -1923,8 +1923,8 @@ private module MkStage<StageSig PrevStage> {
19231923
DataFlowCall call, ArgNodeEx arg, FlowState state, ReturnCtx returnCtx, ApOption returnAp,
19241924
Ap ap, Configuration config
19251925
) {
1926-
exists(ParamNodeEx p, ReturnPosition pos, Ap innerReturnAp |
1927-
revFlowThrough(call, returnCtx, p, state, pos, returnAp, ap, innerReturnAp, config) and
1926+
exists(ParamNodeEx p, Ap innerReturnAp |
1927+
revFlowThrough(call, returnCtx, p, state, _, returnAp, ap, innerReturnAp, config) and
19281928
flowThroughIntoCall(call, arg, p, _, ap, innerReturnAp, config)
19291929
)
19301930
}
@@ -3749,8 +3749,8 @@ private predicate paramFlowsThrough(
37493749
ReturnKindExt kind, FlowState state, CallContextCall cc, SummaryCtxSome sc, AccessPath ap,
37503750
AccessPathApprox apa, Configuration config
37513751
) {
3752-
exists(PathNodeMid mid, RetNodeEx ret |
3753-
pathNode(mid, ret, state, cc, sc, ap, config, _) and
3752+
exists(RetNodeEx ret |
3753+
pathNode(_, ret, state, cc, sc, ap, config, _) and
37543754
kind = ret.getKind() and
37553755
apa = ap.getApprox() and
37563756
parameterFlowThroughAllowed(sc.getParamNode(), kind)
@@ -4212,37 +4212,33 @@ private module FlowExploration {
42124212
ap = TRevPartialNil() and
42134213
exists(config.explorationLimit())
42144214
or
4215-
exists(PartialPathNodeRev mid |
4216-
revPartialPathStep(mid, node, state, sc1, sc2, sc3, ap, config) and
4217-
not clearsContentEx(node, ap.getHead()) and
4218-
(
4219-
notExpectsContent(node) or
4220-
expectsContentEx(node, ap.getHead())
4221-
) and
4222-
not fullBarrier(node, config) and
4223-
not stateBarrier(node, state, config) and
4224-
distSink(node.getEnclosingCallable(), config) <= config.explorationLimit()
4225-
)
4215+
revPartialPathStep(_, node, state, sc1, sc2, sc3, ap, config) and
4216+
not clearsContentEx(node, ap.getHead()) and
4217+
(
4218+
notExpectsContent(node) or
4219+
expectsContentEx(node, ap.getHead())
4220+
) and
4221+
not fullBarrier(node, config) and
4222+
not stateBarrier(node, state, config) and
4223+
distSink(node.getEnclosingCallable(), config) <= config.explorationLimit()
42264224
}
42274225

42284226
pragma[nomagic]
42294227
private predicate partialPathNodeMk0(
42304228
NodeEx node, FlowState state, CallContext cc, TSummaryCtx1 sc1, TSummaryCtx2 sc2,
42314229
TSummaryCtx3 sc3, PartialAccessPath ap, Configuration config
42324230
) {
4233-
exists(PartialPathNodeFwd mid |
4234-
partialPathStep(mid, node, state, cc, sc1, sc2, sc3, ap, config) and
4235-
not fullBarrier(node, config) and
4236-
not stateBarrier(node, state, config) and
4237-
not clearsContentEx(node, ap.getHead().getContent()) and
4238-
(
4239-
notExpectsContent(node) or
4240-
expectsContentEx(node, ap.getHead().getContent())
4241-
) and
4242-
if node.asNode() instanceof CastingNode
4243-
then compatibleTypes(node.getDataFlowType(), ap.getType())
4244-
else any()
4245-
)
4231+
partialPathStep(_, node, state, cc, sc1, sc2, sc3, ap, config) and
4232+
not fullBarrier(node, config) and
4233+
not stateBarrier(node, state, config) and
4234+
not clearsContentEx(node, ap.getHead().getContent()) and
4235+
(
4236+
notExpectsContent(node) or
4237+
expectsContentEx(node, ap.getHead().getContent())
4238+
) and
4239+
if node.asNode() instanceof CastingNode
4240+
then compatibleTypes(node.getDataFlowType(), ap.getType())
4241+
else any()
42464242
}
42474243

42484244
/**

go/ql/lib/semmle/go/dataflow/internal/DataFlowImpl2.qll

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -876,9 +876,9 @@ private module Stage1 implements StageSig {
876876

877877
pragma[nomagic]
878878
private predicate revFlowOut(ReturnPosition pos, Configuration config) {
879-
exists(DataFlowCall call, NodeEx out |
879+
exists(NodeEx out |
880880
revFlow(out, _, config) and
881-
viableReturnPosOutNodeCandFwd1(call, pos, out, config)
881+
viableReturnPosOutNodeCandFwd1(_, pos, out, config)
882882
)
883883
}
884884

@@ -1731,8 +1731,8 @@ private module MkStage<StageSig PrevStage> {
17311731
)
17321732
or
17331733
// flow through a callable
1734-
exists(DataFlowCall call, ParamNodeEx p, ReturnPosition pos, Ap innerReturnAp |
1735-
revFlowThrough(call, returnCtx, p, state, pos, returnAp, ap, innerReturnAp, config) and
1734+
exists(DataFlowCall call, ParamNodeEx p, Ap innerReturnAp |
1735+
revFlowThrough(call, returnCtx, p, state, _, returnAp, ap, innerReturnAp, config) and
17361736
flowThroughIntoCall(call, node, p, _, ap, innerReturnAp, config)
17371737
)
17381738
or
@@ -1901,8 +1901,8 @@ private module MkStage<StageSig PrevStage> {
19011901

19021902
pragma[nomagic]
19031903
predicate parameterMayFlowThrough(ParamNodeEx p, Ap ap, Configuration config) {
1904-
exists(RetNodeEx ret, ReturnPosition pos |
1905-
returnFlowsThrough(ret, pos, _, _, p, ap, _, config) and
1904+
exists(ReturnPosition pos |
1905+
returnFlowsThrough(_, pos, _, _, p, ap, _, config) and
19061906
parameterFlowsThroughRev(p, ap, pos, _, config)
19071907
)
19081908
}
@@ -1923,8 +1923,8 @@ private module MkStage<StageSig PrevStage> {
19231923
DataFlowCall call, ArgNodeEx arg, FlowState state, ReturnCtx returnCtx, ApOption returnAp,
19241924
Ap ap, Configuration config
19251925
) {
1926-
exists(ParamNodeEx p, ReturnPosition pos, Ap innerReturnAp |
1927-
revFlowThrough(call, returnCtx, p, state, pos, returnAp, ap, innerReturnAp, config) and
1926+
exists(ParamNodeEx p, Ap innerReturnAp |
1927+
revFlowThrough(call, returnCtx, p, state, _, returnAp, ap, innerReturnAp, config) and
19281928
flowThroughIntoCall(call, arg, p, _, ap, innerReturnAp, config)
19291929
)
19301930
}
@@ -3749,8 +3749,8 @@ private predicate paramFlowsThrough(
37493749
ReturnKindExt kind, FlowState state, CallContextCall cc, SummaryCtxSome sc, AccessPath ap,
37503750
AccessPathApprox apa, Configuration config
37513751
) {
3752-
exists(PathNodeMid mid, RetNodeEx ret |
3753-
pathNode(mid, ret, state, cc, sc, ap, config, _) and
3752+
exists(RetNodeEx ret |
3753+
pathNode(_, ret, state, cc, sc, ap, config, _) and
37543754
kind = ret.getKind() and
37553755
apa = ap.getApprox() and
37563756
parameterFlowThroughAllowed(sc.getParamNode(), kind)
@@ -4212,37 +4212,33 @@ private module FlowExploration {
42124212
ap = TRevPartialNil() and
42134213
exists(config.explorationLimit())
42144214
or
4215-
exists(PartialPathNodeRev mid |
4216-
revPartialPathStep(mid, node, state, sc1, sc2, sc3, ap, config) and
4217-
not clearsContentEx(node, ap.getHead()) and
4218-
(
4219-
notExpectsContent(node) or
4220-
expectsContentEx(node, ap.getHead())
4221-
) and
4222-
not fullBarrier(node, config) and
4223-
not stateBarrier(node, state, config) and
4224-
distSink(node.getEnclosingCallable(), config) <= config.explorationLimit()
4225-
)
4215+
revPartialPathStep(_, node, state, sc1, sc2, sc3, ap, config) and
4216+
not clearsContentEx(node, ap.getHead()) and
4217+
(
4218+
notExpectsContent(node) or
4219+
expectsContentEx(node, ap.getHead())
4220+
) and
4221+
not fullBarrier(node, config) and
4222+
not stateBarrier(node, state, config) and
4223+
distSink(node.getEnclosingCallable(), config) <= config.explorationLimit()
42264224
}
42274225

42284226
pragma[nomagic]
42294227
private predicate partialPathNodeMk0(
42304228
NodeEx node, FlowState state, CallContext cc, TSummaryCtx1 sc1, TSummaryCtx2 sc2,
42314229
TSummaryCtx3 sc3, PartialAccessPath ap, Configuration config
42324230
) {
4233-
exists(PartialPathNodeFwd mid |
4234-
partialPathStep(mid, node, state, cc, sc1, sc2, sc3, ap, config) and
4235-
not fullBarrier(node, config) and
4236-
not stateBarrier(node, state, config) and
4237-
not clearsContentEx(node, ap.getHead().getContent()) and
4238-
(
4239-
notExpectsContent(node) or
4240-
expectsContentEx(node, ap.getHead().getContent())
4241-
) and
4242-
if node.asNode() instanceof CastingNode
4243-
then compatibleTypes(node.getDataFlowType(), ap.getType())
4244-
else any()
4245-
)
4231+
partialPathStep(_, node, state, cc, sc1, sc2, sc3, ap, config) and
4232+
not fullBarrier(node, config) and
4233+
not stateBarrier(node, state, config) and
4234+
not clearsContentEx(node, ap.getHead().getContent()) and
4235+
(
4236+
notExpectsContent(node) or
4237+
expectsContentEx(node, ap.getHead().getContent())
4238+
) and
4239+
if node.asNode() instanceof CastingNode
4240+
then compatibleTypes(node.getDataFlowType(), ap.getType())
4241+
else any()
42464242
}
42474243

42484244
/**

go/ql/lib/semmle/go/dataflow/internal/DataFlowUtil.qll

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,8 @@ signature predicate guardChecksSig(Node g, Expr e, boolean branch);
281281
module BarrierGuard<guardChecksSig/3 guardChecks> {
282282
/** Gets a node that is safely guarded by the given guard check. */
283283
Node getABarrierNode() {
284-
exists(Node g, ControlFlow::ConditionGuardNode guard, Node nd, SsaWithFields var |
285-
result = var.getAUse()
286-
|
287-
guards(g, guard, nd, var) and
284+
exists(ControlFlow::ConditionGuardNode guard, SsaWithFields var | result = var.getAUse() |
285+
guards(_, guard, _, var) and
288286
guard.dominates(result.getBasicBlock())
289287
)
290288
}
@@ -293,10 +291,8 @@ module BarrierGuard<guardChecksSig/3 guardChecks> {
293291
* Gets a node that is safely guarded by the given guard check.
294292
*/
295293
Node getABarrierNodeForGuard(Node guardCheck) {
296-
exists(ControlFlow::ConditionGuardNode guard, Node nd, SsaWithFields var |
297-
result = var.getAUse()
298-
|
299-
guards(guardCheck, guard, nd, var) and
294+
exists(ControlFlow::ConditionGuardNode guard, SsaWithFields var | result = var.getAUse() |
295+
guards(guardCheck, guard, _, var) and
300296
guard.dominates(result.getBasicBlock())
301297
)
302298
}
@@ -322,11 +318,8 @@ module BarrierGuard<guardChecksSig/3 guardChecks> {
322318
guard.ensures(g, branch)
323319
)
324320
or
325-
exists(
326-
Function f, FunctionInput inp, FunctionOutput outp, DataFlow::Property p, CallNode c,
327-
Node resNode, Node check, boolean outcome
328-
|
329-
guardingCall(g, f, inp, outp, p, c, nd, resNode) and
321+
exists(DataFlow::Property p, Node resNode, Node check, boolean outcome |
322+
guardingCall(g, _, _, _, p, _, nd, resNode) and
330323
p.checkOn(check, outcome, resNode) and
331324
guard.ensures(pragma[only_bind_into](check), outcome)
332325
)

go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,8 @@ module Private {
580580
head = TWithContentSummaryComponent(cont)
581581
)
582582
or
583-
exists(ContentSet cont |
584-
head = TWithoutContentSummaryComponent(cont) and
585-
result = getNodeType(summaryNodeInputState(c, s.tail()))
586-
)
583+
head = TWithoutContentSummaryComponent(_) and
584+
result = getNodeType(summaryNodeInputState(c, s.tail()))
587585
or
588586
exists(ReturnKind rk |
589587
head = TReturnSummaryComponent(rk) and
@@ -658,8 +656,8 @@ module Private {
658656

659657
/** Holds if summary node `ret` is a return node of kind `rk`. */
660658
predicate summaryReturnNode(Node ret, ReturnKind rk) {
661-
exists(SummarizedCallable callable, SummaryComponentStack s |
662-
ret = summaryNodeOutputState(callable, s) and
659+
exists(SummaryComponentStack s |
660+
ret = summaryNodeOutputState(_, s) and
663661
s = TSingletonSummaryComponentStack(TReturnSummaryComponent(rk))
664662
)
665663
}

go/ql/lib/semmle/go/dataflow/internal/TaintTrackingUtil.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,8 @@ predicate functionEnsuresInputIsConstant(
368368
ri.getReturnStmt().getAnExpr() = ret.asExpr() and
369369
ret.asExpr() = Builtin::nil().getAReference()
370370
|
371-
exists(DataFlow::Node exprNode |
372-
DataFlow::localFlow(inp.getExitNode(fd), exprNode) and
373-
mustPassConstantCaseTestToReach(ri, inp.getExitNode(fd))
374-
)
371+
DataFlow::localFlow(inp.getExitNode(fd), _) and
372+
mustPassConstantCaseTestToReach(ri, inp.getExitNode(fd))
375373
)
376374
)
377375
}

go/ql/lib/semmle/go/security/ExternalAPIs.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class ExternalApiDataNode extends DataFlow::Node {
7575
// Not defined in a test file
7676
not call.getFile() instanceof TestFile and
7777
// Not already modeled as a taint step
78-
not exists(DataFlow::Node next | TaintTracking::localTaintStep(this, next)) and
78+
not TaintTracking::localTaintStep(this, _) and
7979
// Not a call to a known safe external API
8080
not call.getTarget() instanceof SafeExternalApiFunction
8181
}

0 commit comments

Comments
 (0)