Skip to content

Commit d71934c

Browse files
committed
Guards: Only prune actually trivial guards.
1 parent 6408449 commit d71934c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

shared/controlflow/codeql/controlflow/Guards.qll

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,12 @@ module Make<
362362
v.asConstantValue() = c.asConstantValue()
363363
}
364364

365+
private predicate trivialHasValue(Expr e, GuardValue v) {
366+
constantHasValue(e, v)
367+
or
368+
e instanceof NonNullExpr and v.isNonNullValue()
369+
}
370+
365371
private predicate exceptionBranchPoint(BasicBlock bb1, BasicBlock normalSucc, BasicBlock excSucc) {
366372
exists(SuccessorType norm, ExceptionSuccessor exc |
367373
bb1.getASuccessor(norm) = normalSucc and
@@ -811,7 +817,7 @@ module Make<
811817
v2.isNonNullValue()
812818
)
813819
) and
814-
not exprHasValue(g2, v2) // disregard trivial guard
820+
not trivialHasValue(g2, v2) // disregard trivial guard
815821
}
816822

817823
bindingset[g1, v1]
@@ -834,7 +840,7 @@ module Make<
834840
// g1 === ... ? e : g2
835841
g2 = getBranchExpr(cond, branch.booleanNot()) and
836842
v2 = v1 and
837-
not exprHasValue(g2, v2) // disregard trivial guard
843+
not trivialHasValue(g2, v2) // disregard trivial guard
838844
)
839845
}
840846

@@ -843,7 +849,7 @@ module Make<
843849
private predicate impliesStepSsaGuard(SsaDefinition def1, GuardValue v1, Guard g2, GuardValue v2) {
844850
def1.(SsaWriteDefinition).getDefinition() = g2 and
845851
v1 = v2 and
846-
not exprHasValue(g2, v2) // disregard trivial guard
852+
not trivialHasValue(g2, v2) // disregard trivial guard
847853
or
848854
exists(Expr e, GuardValue ev |
849855
guardDeterminesPhiInput(g2, v2.getDualValue(), def1, e) and
@@ -1092,7 +1098,7 @@ module Make<
10921098
call.getMethod() = wrapperGuard(ppos, v1, v2) and
10931099
call.getArgument(apos) = g2 and
10941100
parameterMatch(pragma[only_bind_out](ppos), pragma[only_bind_out](apos)) and
1095-
not exprHasValue(g2, v2) // disregard trivial guard
1101+
not trivialHasValue(g2, v2) // disregard trivial guard
10961102
)
10971103
}
10981104
}

0 commit comments

Comments
 (0)