@@ -4,8 +4,8 @@ import semmle.code.cpp.controlflow.IRGuards
4
4
query predicate astGuards ( GuardCondition guard ) { any ( ) }
5
5
6
6
query predicate astGuardsCompare ( int startLine , string msg ) {
7
- exists ( GuardCondition guard , Expr left , int k , string which , string op |
8
- exists ( boolean sense |
7
+ exists ( GuardCondition guard , Expr left , int k , string op |
8
+ exists ( boolean sense , string which |
9
9
sense = true and which = "true"
10
10
or
11
11
sense = false and which = "false"
@@ -21,14 +21,16 @@ query predicate astGuardsCompare(int startLine, string msg) {
21
21
|
22
22
msg = left + op + right + "+" + k + " when " + guard + " is " + which
23
23
)
24
+ )
25
+ or
26
+ exists ( AbstractValue value |
27
+ guard .comparesEq ( left , k , true , value ) and op = " == "
24
28
or
25
- (
26
- guard .comparesEq ( left , k , true , sense ) and op = " == "
27
- or
28
- guard .comparesEq ( left , k , false , sense ) and op = " != "
29
- ) and
30
- msg = left + op + k + " when " + guard + " is " + which
31
- ) and
29
+ guard .comparesEq ( left , k , false , value ) and op = " != "
30
+ |
31
+ msg = left + op + k + " when " + guard + " is " + value
32
+ )
33
+ |
32
34
startLine = guard .getLocation ( ) .getStartLine ( )
33
35
)
34
36
}
@@ -71,8 +73,8 @@ query predicate astGuardsEnsure_const(
71
73
query predicate irGuards ( IRGuardCondition guard ) { any ( ) }
72
74
73
75
query predicate irGuardsCompare ( int startLine , string msg ) {
74
- exists ( IRGuardCondition guard , Operand left , int k , string which , string op |
75
- exists ( boolean sense |
76
+ exists ( IRGuardCondition guard , Operand left , int k , string op |
77
+ exists ( boolean sense , string which |
76
78
sense = true and which = "true"
77
79
or
78
80
sense = false and which = "false"
@@ -91,16 +93,18 @@ query predicate irGuardsCompare(int startLine, string msg) {
91
93
right .getAnyDef ( ) .getUnconvertedResultExpression ( ) + "+" + k + " when " + guard + " is "
92
94
+ which
93
95
)
96
+ )
97
+ or
98
+ exists ( AbstractValue value |
99
+ guard .comparesEq ( left , k , true , value ) and op = " == "
94
100
or
95
- (
96
- guard .comparesEq ( left , k , true , sense ) and op = " == "
97
- or
98
- guard .comparesEq ( left , k , false , sense ) and op = " != "
99
- ) and
101
+ guard .comparesEq ( left , k , false , value ) and op = " != "
102
+ |
100
103
msg =
101
104
left .getAnyDef ( ) .getUnconvertedResultExpression ( ) + op + k + " when " + guard + " is " +
102
- which
103
- ) and
105
+ value
106
+ )
107
+ |
104
108
startLine = guard .getLocation ( ) .getStartLine ( )
105
109
)
106
110
}
0 commit comments