Skip to content

Commit 37a8fc8

Browse files
committed
Guards: Use unique aggregate.
1 parent ad5ab9f commit 37a8fc8

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

shared/controlflow/codeql/controlflow/Guards.qll

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,11 @@ module Make<
640640
Guard guard, GuardValue v, SsaPhiDefinition phi, Expr input
641641
) {
642642
exists(GuardValue dv, SsaExplicitWrite inp |
643-
guardControlsPhiBranch(guard, v, phi, inp) and
644-
// The `forall` below implies that there's only one such `inp` guarded by `guard == v`,
645-
// but checking this upfront improves performance of the `forall` check.
646-
1 = strictcount(SsaDefinition inp0 | guardControlsPhiBranch(guard, v, phi, inp0)) and
643+
// The `forall` below implies that there's only one `inp` guarded by
644+
// `guard == v`, but checking this upfront using `unique` as opposed to
645+
// merely stating `guardControlsPhiBranch(guard, v, phi, inp)` improves
646+
// performance of the `forall` check.
647+
inp = unique(SsaDefinition inp0 | guardControlsPhiBranch(guard, v, phi, inp0)) and
647648
inp.getValue() = input and
648649
dv = v.getDualValue() and
649650
forall(SsaDefinition other | phi.hasInputFromBlock(other, _) and other != inp |
@@ -744,7 +745,7 @@ module Make<
744745
possibleValue(v, false, e, k) and
745746
not possibleValue(v, true, e, k) and
746747
// there's only one expression with the value `k`
747-
1 = strictcount(Expr e0 | possibleValue(v, _, e0, k)) and
748+
e = unique(Expr e0 | possibleValue(v, _, e0, k)) and
748749
// and `v` has at least two possible values
749750
2 <= strictcount(GuardValue k0 | possibleValue(v, _, _, k0))
750751
}

0 commit comments

Comments
 (0)