@@ -4,8 +4,8 @@ import semmle.code.cpp.controlflow.IRGuards
44query predicate astGuards ( GuardCondition guard ) { any ( ) }
55
66query 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 |
99 sense = true and which = "true"
1010 or
1111 sense = false and which = "false"
@@ -21,14 +21,16 @@ query predicate astGuardsCompare(int startLine, string msg) {
2121 |
2222 msg = left + op + right + "+" + k + " when " + guard + " is " + which
2323 )
24+ )
25+ or
26+ exists ( AbstractValue value |
27+ guard .comparesEq ( left , k , true , value ) and op = " == "
2428 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+ |
3234 startLine = guard .getLocation ( ) .getStartLine ( )
3335 )
3436}
@@ -71,8 +73,8 @@ query predicate astGuardsEnsure_const(
7173query predicate irGuards ( IRGuardCondition guard ) { any ( ) }
7274
7375query 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 |
7678 sense = true and which = "true"
7779 or
7880 sense = false and which = "false"
@@ -91,16 +93,18 @@ query predicate irGuardsCompare(int startLine, string msg) {
9193 right .getAnyDef ( ) .getUnconvertedResultExpression ( ) + "+" + k + " when " + guard + " is "
9294 + which
9395 )
96+ )
97+ or
98+ exists ( AbstractValue value |
99+ guard .comparesEq ( left , k , true , value ) and op = " == "
94100 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+ |
100103 msg =
101104 left .getAnyDef ( ) .getUnconvertedResultExpression ( ) + op + k + " when " + guard + " is " +
102- which
103- ) and
105+ value
106+ )
107+ |
104108 startLine = guard .getLocation ( ) .getStartLine ( )
105109 )
106110}
0 commit comments