Skip to content

Commit 6d3d902

Browse files
Merge pull request #867 from jbj/ir-ignoreExprAndDescendants-perf
C++: Replace FastTC with iteration in ignoreExpr
2 parents 7345c92 + 60141bf commit 6d3d902

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,18 @@ private Element getRealParent(Expr expr) {
3535
*/
3636
predicate isIRConstant(Expr expr) { exists(expr.getValue()) }
3737

38+
// Pulled out to work around QL-796
39+
private predicate isOrphan(Expr expr) {
40+
not exists(getRealParent(expr))
41+
}
42+
3843
/**
39-
* Holds if `expr` and all of its descendants should be ignored for the purposes
40-
* of IR generation due to some property of `expr` itself. Unlike
41-
* `ignoreExpr()`, this predicate does not ignore an expression solely because
42-
* it is a descendant of an ignored element.
44+
* Holds if `expr` should be ignored for the purposes of IR generation due to
45+
* some property of `expr` or one of its ancestors.
4346
*/
4447
private predicate ignoreExprAndDescendants(Expr expr) {
4548
// Ignore parentless expressions
46-
not exists(getRealParent(expr)) or
49+
isOrphan(expr) or
4750
// Ignore the constants in SwitchCase, since their values are embedded in the
4851
// CaseEdge.
4952
getRealParent(expr) instanceof SwitchCase or
@@ -59,7 +62,8 @@ private predicate ignoreExprAndDescendants(Expr expr) {
5962
// REVIEW: Ignore initializers for `NewArrayExpr` until we determine how to
6063
// represent them.
6164
newExpr.getInitializer().getFullyConverted() = expr
62-
)
65+
) or
66+
ignoreExprAndDescendants(getRealParent(expr)) // recursive case
6367
}
6468

6569
/**
@@ -80,7 +84,7 @@ private predicate ignoreExprOnly(Expr expr) {
8084
*/
8185
private predicate ignoreExpr(Expr expr) {
8286
ignoreExprOnly(expr) or
83-
ignoreExprAndDescendants(getRealParent*(expr))
87+
ignoreExprAndDescendants(expr)
8488
}
8589

8690
/**

0 commit comments

Comments
 (0)