Skip to content

Commit e522c57

Browse files
committed
C++: fix performance of argument hash-consing
1 parent 42b90ed commit e522c57

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

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

+11-9
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,7 @@ private predicate mk_NonmemberFunctionCall(Function fcn, HC_Args args, FunctionC
496496
analyzableNonmemberFunctionCall(fc) and
497497
(
498498
exists(HashCons head, HC_Args tail |
499-
args = HC_ArgCons(head, fc.getNumberOfArguments() - 1, tail) and
500-
mk_ArgCons(head, fc.getNumberOfArguments() - 1, tail, fc)
499+
mk_ArgConsInner(head, tail, fc.getNumberOfArguments() - 1, args, fc)
501500
)
502501
or
503502
fc.getNumberOfArguments() = 0 and
@@ -517,8 +516,7 @@ private predicate mk_ExprCall(HashCons hc, HC_Args args, ExprCall ec) {
517516
hc.getAnExpr() = ec.getExpr() and
518517
(
519518
exists(HashCons head, HC_Args tail |
520-
args = HC_ArgCons(head, ec.getNumberOfArguments() - 1, tail) and
521-
mk_ArgCons(head, ec.getNumberOfArguments() - 1, tail, ec)
519+
mk_ArgConsInner(head, tail, ec.getNumberOfArguments() - 1, args, ec)
522520
)
523521
or
524522
ec.getNumberOfArguments() = 0 and
@@ -547,8 +545,7 @@ private predicate mk_MemberFunctionCall(
547545
hashCons(fc.getQualifier().getFullyConverted()) = qual and
548546
(
549547
exists(HashCons head, HC_Args tail |
550-
args = HC_ArgCons(head, fc.getNumberOfArguments() - 1, tail) and
551-
mk_ArgCons(head, fc.getNumberOfArguments() - 1, tail, fc)
548+
mk_ArgConsInner(head, tail, fc.getNumberOfArguments() - 1, args, fc)
552549
)
553550
or
554551
fc.getNumberOfArguments() = 0 and
@@ -568,13 +565,12 @@ private predicate analyzableCall(Call c) {
568565
* Holds if `fc` is a call to `fcn`, `fc`'s first `i` arguments have hash-cons
569566
* `list`, and `fc`'s argument at index `i` has hash-cons `hc`.
570567
*/
571-
private predicate mk_ArgCons(HashCons hc, int i, HC_Args list,Call c) {
568+
private predicate mk_ArgCons(HashCons hc, int i, HC_Args list, Call c) {
572569
analyzableCall(c) and
573570
hc = hashCons(c.getArgument(i).getFullyConverted()) and
574571
(
575572
exists(HashCons head, HC_Args tail |
576-
list = HC_ArgCons(head, i - 1, tail) and
577-
mk_ArgCons(head, i - 1, tail, c) and
573+
mk_ArgConsInner(head, tail, i-1, list, c) and
578574
i > 0
579575
)
580576
or
@@ -583,6 +579,12 @@ private predicate mk_ArgCons(HashCons hc, int i, HC_Args list,Call c) {
583579
)
584580
}
585581

582+
// avoid a join ordering issue
583+
pragma[noopt]
584+
private predicate mk_ArgConsInner(HashCons head, HC_Args tail, int i, HC_Args list, Call c) {
585+
list = HC_ArgCons(head, i, tail) and
586+
mk_ArgCons(head, i, tail, c)
587+
}
586588

587589
/**
588590
* Holds if `fc` is a call to `fcn`, `fc`'s first `i` arguments have hash-cons

0 commit comments

Comments
 (0)