Skip to content

Commit 06a7e3f

Browse files
committed
Dataflow: Cache typeStrongerThan.
1 parent bd99f32 commit 06a7e3f

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2951,7 +2951,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
29512951
if castingNodeEx(node)
29522952
then
29532953
exists(DataFlowType nt | nt = node.getDataFlowType() |
2954-
if typeStrongerThan(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
2954+
if typeStrongerThanFilter(nt, t0) then t = nt else (compatibleTypes(nt, t0) and t = t0)
29552955
)
29562956
else t = t0
29572957
}

shared/dataflow/codeql/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,9 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
886886
cached
887887
predicate nodeDataFlowType(Node n, DataFlowType t) { t = getNodeType(n) }
888888

889+
cached
890+
predicate typeStrongerThanCached(DataFlowType t1, DataFlowType t2) { typeStrongerThan(t1, t2) }
891+
889892
cached
890893
predicate jumpStepCached(Node node1, Node node2) { jumpStep(node1, node2) }
891894

@@ -1622,7 +1625,9 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
16221625

16231626
bindingset[t1, t2]
16241627
pragma[inline_late]
1625-
private predicate typeStrongerThan0(DataFlowType t1, DataFlowType t2) { typeStrongerThan(t1, t2) }
1628+
predicate typeStrongerThanFilter(DataFlowType t1, DataFlowType t2) {
1629+
typeStrongerThanCached(t1, t2)
1630+
}
16261631

16271632
private predicate callEdge(DataFlowCall call, DataFlowCallable c, ArgNode arg, ParamNode p) {
16281633
viableParamArg(call, p, arg) and
@@ -1703,7 +1708,7 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
17031708
nodeDataFlowType(arg, at) and
17041709
nodeDataFlowType(p, pt) and
17051710
relevantCallEdge(_, _, arg, p) and
1706-
typeStrongerThan0(pt, at)
1711+
typeStrongerThanFilter(pt, at)
17071712
)
17081713
or
17091714
exists(ParamNode p, DataFlowType at, DataFlowType pt |
@@ -1714,7 +1719,7 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
17141719
nodeDataFlowType(p, pt) and
17151720
paramMustFlow(p, arg) and
17161721
relevantCallEdge(_, _, arg, _) and
1717-
typeStrongerThan0(at, pt)
1722+
typeStrongerThanFilter(at, pt)
17181723
)
17191724
or
17201725
exists(ParamNode p |
@@ -1754,7 +1759,7 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
17541759
nodeDataFlowType(arg, at) and
17551760
nodeDataFlowType(p, pt) and
17561761
relevantCallEdge(_, _, arg, p) and
1757-
typeStrongerThan0(at, pt)
1762+
typeStrongerThanFilter(at, pt)
17581763
)
17591764
or
17601765
exists(ArgNode arg |
@@ -1823,8 +1828,13 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
18231828
* stronger then compatibility is checked and `t1` is returned.
18241829
*/
18251830
bindingset[t1, t2]
1831+
pragma[inline_late]
18261832
DataFlowType getStrongestType(DataFlowType t1, DataFlowType t2) {
1827-
if typeStrongerThan(t2, t1) then result = t2 else (compatibleTypes(t1, t2) and result = t1)
1833+
if typeStrongerThanCached(t2, t1)
1834+
then result = t2
1835+
else (
1836+
compatibleTypes(t1, t2) and result = t1
1837+
)
18281838
}
18291839

18301840
/**

0 commit comments

Comments
 (0)