Skip to content

Commit 8b3e626

Browse files
committed
Guards: Only prune actually trivial guards.
1 parent 84b8b1c commit 8b3e626

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
@@ -815,7 +821,7 @@ module Make<
815821
v2.isNonNullValue()
816822
)
817823
) and
818-
not exprHasValue(g2, v2) // disregard trivial guard
824+
not trivialHasValue(g2, v2) // disregard trivial guard
819825
}
820826

821827
bindingset[g1, v1]
@@ -838,7 +844,7 @@ module Make<
838844
// g1 === ... ? e : g2
839845
g2 = getBranchExpr(cond, branch.booleanNot()) and
840846
v2 = v1 and
841-
not exprHasValue(g2, v2) // disregard trivial guard
847+
not trivialHasValue(g2, v2) // disregard trivial guard
842848
)
843849
}
844850

@@ -847,7 +853,7 @@ module Make<
847853
private predicate impliesStepSsaGuard(SsaDefinition def1, GuardValue v1, Guard g2, GuardValue v2) {
848854
def1.(SsaExplicitWrite).getValue() = g2 and
849855
v1 = v2 and
850-
not exprHasValue(g2, v2) // disregard trivial guard
856+
not trivialHasValue(g2, v2) // disregard trivial guard
851857
or
852858
exists(Expr e, GuardValue ev |
853859
guardDeterminesPhiInput(g2, v2.getDualValue(), def1, e) and
@@ -1097,7 +1103,7 @@ module Make<
10971103
call.getMethod() = wrapperGuard(ppos, v1, v2) and
10981104
call.getArgument(apos) = g2 and
10991105
parameterMatch(pragma[only_bind_out](ppos), pragma[only_bind_out](apos)) and
1100-
not exprHasValue(g2, v2) // disregard trivial guard
1106+
not trivialHasValue(g2, v2) // disregard trivial guard
11011107
)
11021108
}
11031109
}

0 commit comments

Comments
 (0)