Skip to content

Commit 2ca0df0

Browse files
committed
C#: Remove omittable exists variables
1 parent 3fcc99e commit 2ca0df0

File tree

31 files changed

+303
-378
lines changed

31 files changed

+303
-378
lines changed

csharp/ql/lib/experimental/code/csharp/Cryptography/NonCryptographicHashes.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ private predicate maybeUsedInElfHashFunction(Variable v, Operation xor, Operatio
7676
* where the parameter `param` is likely the message to hash
7777
*/
7878
predicate isCallableAPotentialNonCryptographicHashFunction(Callable callable, Parameter param) {
79-
exists(Variable v, Expr op1, Expr op2, LoopStmt loop |
80-
maybeANonCryptographicHash(callable, v, op1, op2, loop) and
79+
exists(Expr op1, Expr op2 |
80+
maybeANonCryptographicHash(callable, _, op1, op2, _) and
8181
callable.getAParameter() = param and
8282
exists(ParameterNode p, ExprNode n |
8383
p.getParameter() = param and

csharp/ql/lib/semmle/code/csharp/Conversion.qll

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,7 @@ private module Identity {
277277
UnboundGenericType ugt, IdentityConvertibleGenericType fromType,
278278
IdentityConvertibleGenericType toType
279279
) {
280-
exists(TypeArgument fromTypeArgument, TypeArgument toTypeArgument |
281-
convIdentitySingle0(ugt, toType, fromTypeArgument, toTypeArgument)
282-
|
280+
exists(TypeArgument fromTypeArgument | convIdentitySingle0(ugt, toType, fromTypeArgument, _) |
283281
fromTypeArgument = getTypeArgumentRanked(ugt, fromType, 0)
284282
)
285283
}
@@ -312,13 +310,10 @@ private module Identity {
312310
UnboundGenericType ugt, IdentityConvertibleGenericType fromType,
313311
IdentityConvertibleGenericType toType
314312
) {
315-
exists(
316-
Type fromTypeArgument0, Type toTypeArgument0, Type fromTypeArgument1, Type toTypeArgument1
317-
|
318-
convIdentityMultiple01Aux0(ugt, toType, fromTypeArgument0, toTypeArgument0, toTypeArgument1)
313+
exists(Type fromTypeArgument0, Type toTypeArgument1 |
314+
convIdentityMultiple01Aux0(ugt, toType, fromTypeArgument0, _, toTypeArgument1)
319315
|
320-
convIdentityMultiple01Aux1(ugt, fromType, fromTypeArgument0, fromTypeArgument1,
321-
toTypeArgument1)
316+
convIdentityMultiple01Aux1(ugt, fromType, fromTypeArgument0, _, toTypeArgument1)
322317
)
323318
}
324319

@@ -336,8 +331,8 @@ private module Identity {
336331
UnboundGenericType ugt, IdentityConvertibleGenericType fromType,
337332
IdentityConvertibleGenericType toType, int i
338333
) {
339-
exists(TypeArgument fromTypeArgument, TypeArgument toTypeArgument |
340-
convIdentityMultiple2Aux(ugt, toType, i, fromTypeArgument, toTypeArgument)
334+
exists(TypeArgument fromTypeArgument |
335+
convIdentityMultiple2Aux(ugt, toType, i, fromTypeArgument, _)
341336
|
342337
fromTypeArgument = getTypeArgumentRanked(ugt, fromType, i)
343338
)
@@ -938,9 +933,7 @@ private module Variance {
938933
UnboundGenericType ugt, VarianceConvertibleGenericType fromType,
939934
VarianceConvertibleGenericType toType
940935
) {
941-
exists(TypeArgument fromTypeArgument, TypeArgument toTypeArgument |
942-
convVarianceSingle0(ugt, toType, fromTypeArgument, toTypeArgument)
943-
|
936+
exists(TypeArgument fromTypeArgument | convVarianceSingle0(ugt, toType, fromTypeArgument, _) |
944937
fromTypeArgument = getTypeArgumentRanked(ugt, fromType, 0, _)
945938
)
946939
}
@@ -973,14 +966,10 @@ private module Variance {
973966
UnboundGenericType ugt, VarianceConvertibleGenericType fromType,
974967
VarianceConvertibleGenericType toType
975968
) {
976-
exists(
977-
TypeArgument fromTypeArgument0, TypeArgument toTypeArgument0, TypeArgument fromTypeArgument1,
978-
TypeArgument toTypeArgument1
979-
|
980-
convVarianceMultiple01Aux0(ugt, toType, fromTypeArgument0, toTypeArgument0, toTypeArgument1)
969+
exists(TypeArgument fromTypeArgument0, TypeArgument toTypeArgument1 |
970+
convVarianceMultiple01Aux0(ugt, toType, fromTypeArgument0, _, toTypeArgument1)
981971
|
982-
convVarianceMultiple01Aux1(ugt, fromType, fromTypeArgument0, fromTypeArgument1,
983-
toTypeArgument1)
972+
convVarianceMultiple01Aux1(ugt, fromType, fromTypeArgument0, _, toTypeArgument1)
984973
)
985974
}
986975

@@ -998,8 +987,8 @@ private module Variance {
998987
UnboundGenericType ugt, VarianceConvertibleGenericType fromType,
999988
VarianceConvertibleGenericType toType, int i
1000989
) {
1001-
exists(TypeArgument fromTypeArgument, TypeArgument toTypeArgument |
1002-
convVarianceMultiple2Aux(ugt, toType, i, fromTypeArgument, toTypeArgument)
990+
exists(TypeArgument fromTypeArgument |
991+
convVarianceMultiple2Aux(ugt, toType, i, fromTypeArgument, _)
1003992
|
1004993
fromTypeArgument = getTypeArgumentRanked(ugt, fromType, i, _)
1005994
)

csharp/ql/lib/semmle/code/csharp/Unification.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ module Gvn {
434434

435435
pragma[nomagic]
436436
private predicate unifiable(ConstructedGvnType t1, ConstructedGvnType t2, boolean subsumes) {
437-
exists(CompoundTypeKind k, GvnTypeArgument arg1, GvnTypeArgument arg2 |
438-
unifiableSingle0(k, t2, arg1, arg2, subsumes) and
437+
exists(CompoundTypeKind k, GvnTypeArgument arg1 |
438+
unifiableSingle0(k, t2, arg1, _, subsumes) and
439439
arg1 = getTypeArgument(k, t1, 0)
440440
)
441441
or

csharp/ql/lib/semmle/code/csharp/commons/StructuralComparison.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ private module Cached {
181181
result = TConstantGvn(cfe.(Expr).getValue())
182182
or
183183
not exists(cfe.(Expr).getValue()) and
184-
exists(GvnKind kind, int index |
185-
result = toGvn(cfe, kind, index - 1) and
184+
exists(int index |
185+
result = toGvn(cfe, _, index - 1) and
186186
index = getNumberOfActualChildren(cfe)
187187
)
188188
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,9 @@ module PreSsa {
115115
if def.getTargetAccess().isRefArgument() then certain = false else certain = true
116116
)
117117
or
118-
exists(Callable c |
119-
implicitEntryDef(c, bb, v) and
120-
i = -1 and
121-
certain = true
122-
)
118+
implicitEntryDef(_, bb, v) and
119+
i = -1 and
120+
certain = true
123121
}
124122

125123
predicate variableRead(BasicBlock bb, int i, SourceVariable v, boolean certain) {

csharp/ql/lib/semmle/code/csharp/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
/**

csharp/ql/lib/semmle/code/csharp/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
/**

0 commit comments

Comments
 (0)