Skip to content

Commit 9b805c0

Browse files
authored
Merge pull request github#1951 from pavgust/fix/hashcons-perf
C++: Fix HashCons library performance
2 parents 327ade1 + eca3190 commit 9b805c0

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

cpp/ql/src/semmle/code/cpp/valuenumbering/HashCons.qll

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -737,14 +737,15 @@ private predicate mk_FieldCons(
737737
exists(Expr e |
738738
e = cal.getFieldExpr(f).getFullyConverted() and
739739
f.getInitializationOrder() = i and
740-
hc = hashCons(e) and
741740
(
742741
exists(HashCons head, Field f2, HC_Fields tail |
742+
hc = hashCons(e) and
743743
hcf = HC_FieldCons(c, i - 1, f2, head, tail) and
744744
f2.getInitializationOrder() = i - 1 and
745745
mk_FieldCons(c, i - 1, f2, head, tail, cal)
746746
)
747747
or
748+
hc = hashCons(e) and
748749
i = 0 and
749750
hcf = HC_EmptyFields(c)
750751
)
@@ -765,11 +766,13 @@ private predicate mk_ClassAggregateLiteral(Class c, HC_Fields hcf, ClassAggregat
765766
analyzableClassAggregateLiteral(cal) and
766767
c = cal.getUnspecifiedType() and
767768
(
768-
exists(HC_Fields tail, Expr e, Field f |
769+
exists(HC_Fields tail, Expr e, Field f, int numChildren, HashCons eCons |
769770
f.getInitializationOrder() = cal.getNumChild() - 1 and
770771
e = cal.getFieldExpr(f).getFullyConverted() and
771-
hcf = HC_FieldCons(c, cal.getNumChild() - 1, f, hashCons(e), tail) and
772-
mk_FieldCons(c, cal.getNumChild() - 1, f, hashCons(e), tail, cal)
772+
eCons = hashCons(e) and
773+
numChildren = cal.getNumChild() and
774+
hcf = HC_FieldCons(c, numChildren - 1, f, eCons, tail) and
775+
mk_FieldCons(c, numChildren - 1, f, eCons, tail, cal)
773776
)
774777
or
775778
cal.getNumChild() = 0 and
@@ -800,9 +803,10 @@ private predicate mk_ArrayCons(Type t, int i, HashCons hc, HC_Array hca, ArrayAg
800803
private predicate mk_ArrayAggregateLiteral(Type t, HC_Array hca, ArrayAggregateLiteral aal) {
801804
t = aal.getUnspecifiedType() and
802805
(
803-
exists(HashCons head, HC_Array tail |
804-
hca = HC_ArrayCons(t, aal.getNumChild() - 1, head, tail) and
805-
mk_ArrayCons(t, aal.getNumChild() - 1, head, tail, aal)
806+
exists(HashCons head, HC_Array tail, int numElements |
807+
numElements = aal.getNumChild() and
808+
hca = HC_ArrayCons(t, numElements - 1, head, tail) and
809+
mk_ArrayCons(t, numElements - 1, head, tail, aal)
806810
)
807811
or
808812
aal.getNumChild() = 0 and

0 commit comments

Comments
 (0)