Skip to content

Commit c9e56d1

Browse files
committed
C++: Add Expr.getUnconverted predicate
This gets rid of the expensive predicate `#Cast::Conversion::getExpr_dispred#ffPlus`, I've observed to cause memory pressure on large databases.
1 parent 9c06c48 commit c9e56d1

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

cpp/ql/src/semmle/code/cpp/exprs/Expr.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,20 @@ class Expr extends StmtParent, @expr {
442442
else result = this
443443
}
444444

445+
/**
446+
* Gets the unique non-`Conversion` expression `e` for which
447+
* `this = e.getConversion*()`.
448+
*
449+
* For example, if called on the expression `(int)(char)x`, this predicate
450+
* gets the expression `x`.
451+
*/
452+
Expr getUnconverted() {
453+
not this instanceof Conversion and
454+
result = this
455+
or
456+
result = this.(Conversion).getExpr().getUnconverted()
457+
}
458+
445459
/**
446460
* Gets the type of this expression, after any implicit conversions and explicit casts, and after resolving typedefs.
447461
*

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@ class ExprNode extends InstructionNode {
131131
* `Conversion`, then the result is that `Conversion`'s non-`Conversion` base
132132
* expression.
133133
*/
134-
Expr getExpr() {
135-
result.getConversion*() = instr.getConvertedResultExpression() and
136-
not result instanceof Conversion
137-
}
134+
Expr getExpr() { result = instr.getUnconvertedResultExpression() }
138135

139136
/**
140137
* Gets the expression corresponding to this node, if any. The returned

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,7 @@ private module Cached {
6868

6969
cached
7070
Expr getInstructionUnconvertedResultExpression(Instruction instruction) {
71-
exists(Expr converted |
72-
result = converted.(Conversion).getExpr+()
73-
or
74-
result = converted
75-
|
76-
not result instanceof Conversion and
77-
converted = getInstructionConvertedResultExpression(instruction)
78-
)
71+
result = getInstructionConvertedResultExpression(instruction).getUnconverted()
7972
}
8073

8174
cached

0 commit comments

Comments
 (0)