Skip to content

Commit d771f1e

Browse files
committed
C/C++: Disable constant folding of address-vs-null comparisons
1 parent a40719b commit d771f1e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,20 @@ private predicate ignoreConstantValue(Operation op) {
6262
op instanceof BitwiseXorExpr
6363
}
6464

65+
/** Holds if `expr` contains an address-of expression that EDG may have constant-folded. */
66+
private predicate containsAddressOf(Expr expr) {
67+
expr instanceof AddressOfExpr
68+
or
69+
containsAddressOf(expr.getAChild())
70+
}
71+
6572
/**
6673
* Holds if `expr` is a constant of a type that can be replaced directly with
6774
* its value in the IR. This does not include address constants as we have no
6875
* means to express those as QL values.
6976
*/
7077
predicate isIRConstant(Expr expr) {
78+
not containsAddressOf(expr) and
7179
exists(expr.getValue()) and
7280
// We avoid constant folding certain operations since it's often useful to
7381
// mark one of those as a source in dataflow, and if the operation is

0 commit comments

Comments
 (0)