Skip to content

Commit 3c7522c

Browse files
committed
Guards: Replace recursion through universal quantification with rank-iteration.
1 parent a5279ec commit 3c7522c

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

shared/controlflow/codeql/controlflow/Guards.qll

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,10 +1088,11 @@ module Make<
10881088
* parameter has the value `val`.
10891089
*/
10901090
private predicate validReturnInCustomGuard(
1091-
ReturnExpr ret, ParameterPosition ppos, GuardValue retval, GuardValue val
1091+
ReturnExpr ret, int rnk, NonOverridableMethod m, ParameterPosition ppos, GuardValue retval,
1092+
GuardValue val
10921093
) {
1093-
exists(NonOverridableMethod m, SsaParameterInit param |
1094-
m.getAReturnExpr() = ret and
1094+
exists(SsaParameterInit param |
1095+
ret = rankedReturnExpr(m, rnk) and
10951096
param.getParameter() = m.getParameter(ppos)
10961097
|
10971098
exists(Guard g0, GuardValue v0 |
@@ -1104,6 +1105,24 @@ module Make<
11041105
)
11051106
}
11061107

1108+
private predicate validReturnInCustomGuardToRank(
1109+
int rnk, NonOverridableMethod m, ParameterPosition ppos, GuardValue retval, GuardValue val
1110+
) {
1111+
validReturnInCustomGuard(_, _, m, ppos, retval, val) and rnk = 0
1112+
or
1113+
validReturnInCustomGuardToRank(rnk - 1, m, ppos, retval, val) and
1114+
rnk <= maxRank(m) and
1115+
forall(ReturnExpr ret |
1116+
ret = rankedReturnExpr(m, rnk) and
1117+
not exists(GuardValue notRetval |
1118+
exprHasValue(ret, notRetval) and
1119+
disjointValues(notRetval, retval)
1120+
)
1121+
|
1122+
validReturnInCustomGuard(ret, rnk, m, ppos, retval, val)
1123+
)
1124+
}
1125+
11071126
private predicate guardDirectlyControlsExit(Guard guard, GuardValue val) {
11081127
exists(BasicBlock bb |
11091128
guard.directlyValueControls(bb, val) and
@@ -1119,15 +1138,7 @@ module Make<
11191138
private NonOverridableMethod wrapperGuard(
11201139
ParameterPosition ppos, GuardValue retval, GuardValue val
11211140
) {
1122-
forex(ReturnExpr ret |
1123-
result.getAReturnExpr() = ret and
1124-
not exists(GuardValue notRetval |
1125-
exprHasValue(ret, notRetval) and
1126-
disjointValues(notRetval, retval)
1127-
)
1128-
|
1129-
validReturnInCustomGuard(ret, ppos, retval, val)
1130-
)
1141+
validReturnInCustomGuardToRank(maxRank(result), result, ppos, retval, val)
11311142
or
11321143
exists(SsaParameterInit param, Guard g0, GuardValue v0 |
11331144
param.getParameter() = result.getParameter(ppos) and

0 commit comments

Comments
 (0)