13
13
*/
14
14
15
15
import cpp
16
- import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
16
+ import semmle.code.cpp.valuenumbering.HashCons
17
17
18
18
/** Holds if `exp` increments a boolean value. */
19
- predicate incrementBoolType ( Expr exp ) {
20
- exp .( IncrementOperation ) . getOperand ( ) .getType ( ) instanceof BoolType
19
+ predicate incrementBoolType ( IncrementOperation exp ) {
20
+ exp .getOperand ( ) .getType ( ) instanceof BoolType
21
21
}
22
22
23
23
/** Holds if `exp` applies the unary minus operator to a boolean type. */
24
- predicate revertSignBoolType ( Expr exp ) {
25
- exp .( AssignExpr ) . getRValue ( ) . ( UnaryMinusExpr ) . getAnOperand ( ) .getType ( ) instanceof BoolType and
26
- exp .( AssignExpr ) . getLValue ( ) .getType ( ) instanceof BoolType
24
+ predicate revertSignBoolType ( UnaryMinusExpr exp ) {
25
+ exp .getAnOperand ( ) .getType ( ) instanceof BoolType and
26
+ exp .getFullyConverted ( ) .getType ( ) instanceof BoolType
27
27
}
28
28
29
29
/** Holds, if this is an expression, uses comparison and assignment outside of execution precedence. */
@@ -33,6 +33,12 @@ predicate assignBoolType(Expr exp) {
33
33
exp .isCondition ( ) and
34
34
not co .isParenthesised ( ) and
35
35
not exp .( AssignExpr ) .getLValue ( ) .getType ( ) instanceof BoolType and
36
+ not exists ( Expr exbl |
37
+ hashCons ( exbl .( AssignExpr ) .getLValue ( ) ) = hashCons ( exp .( AssignExpr ) .getLValue ( ) ) and
38
+ not exbl .isCondition ( ) and
39
+ exbl .( AssignExpr ) .getRValue ( ) .getType ( ) instanceof BoolType and
40
+ exbl .( AssignExpr ) .getLValue ( ) .getType ( ) = exp .( AssignExpr ) .getLValue ( ) .getType ( )
41
+ ) and
36
42
co .getLeftOperand ( ) instanceof FunctionCall and
37
43
not co .getRightOperand ( ) .getType ( ) instanceof BoolType and
38
44
not co .getRightOperand ( ) .getValue ( ) = "0" and
0 commit comments