@@ -4,22 +4,32 @@ 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 , Expr right , int k , string which , string op |
7+ exists ( GuardCondition guard , Expr left , int k , string which , string op |
88 exists ( boolean sense |
99 sense = true and which = "true"
1010 or
1111 sense = false and which = "false"
1212 |
13- guard .comparesLt ( left , right , k , true , sense ) and op = " < "
13+ exists ( Expr right |
14+ guard .comparesLt ( left , right , k , true , sense ) and op = " < "
15+ or
16+ guard .comparesLt ( left , right , k , false , sense ) and op = " >= "
17+ or
18+ guard .comparesEq ( left , right , k , true , sense ) and op = " == "
19+ or
20+ guard .comparesEq ( left , right , k , false , sense ) and op = " != "
21+ |
22+ msg = left + op + right + "+" + k + " when " + guard + " is " + which
23+ )
1424 or
15- guard .comparesLt ( left , right , k , false , sense ) and op = " >= "
16- or
17- guard .comparesEq ( left , right , k , true , sense ) and op = " == "
18- or
19- guard .comparesEq ( left , right , k , false , sense ) and op = " != "
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
2031 ) and
21- startLine = guard .getLocation ( ) .getStartLine ( ) and
22- msg = left + op + right + "+" + k + " when " + guard + " is " + which
32+ startLine = guard .getLocation ( ) .getStartLine ( )
2333 )
2434}
2535
@@ -46,28 +56,52 @@ query predicate astGuardsEnsure(
4656 )
4757}
4858
59+ query predicate astGuardsEnsure_const (
60+ GuardCondition guard , Expr left , string op , int k , int start , int end
61+ ) {
62+ exists ( BasicBlock block |
63+ guard .ensuresEq ( left , k , block , true ) and op = "=="
64+ or
65+ guard .ensuresEq ( left , k , block , false ) and op = "!="
66+ |
67+ block .hasLocationInfo ( _, start , _, end , _)
68+ )
69+ }
70+
4971query predicate irGuards ( IRGuardCondition guard ) { any ( ) }
5072
5173query predicate irGuardsCompare ( int startLine , string msg ) {
52- exists ( IRGuardCondition guard , Operand left , Operand right , int k , string which , string op |
74+ exists ( IRGuardCondition guard , Operand left , int k , string which , string op |
5375 exists ( boolean sense |
5476 sense = true and which = "true"
5577 or
5678 sense = false and which = "false"
5779 |
58- guard .comparesLt ( left , right , k , true , sense ) and op = " < "
80+ exists ( Operand right |
81+ guard .comparesLt ( left , right , k , true , sense ) and op = " < "
82+ or
83+ guard .comparesLt ( left , right , k , false , sense ) and op = " >= "
84+ or
85+ guard .comparesEq ( left , right , k , true , sense ) and op = " == "
86+ or
87+ guard .comparesEq ( left , right , k , false , sense ) and op = " != "
88+ |
89+ msg =
90+ left .getAnyDef ( ) .getUnconvertedResultExpression ( ) + op +
91+ right .getAnyDef ( ) .getUnconvertedResultExpression ( ) + "+" + k + " when " + guard + " is "
92+ + which
93+ )
5994 or
60- guard .comparesLt ( left , right , k , false , sense ) and op = " >= "
61- or
62- guard .comparesEq ( left , right , k , true , sense ) and op = " == "
63- or
64- guard .comparesEq ( left , right , k , false , sense ) and op = " != "
95+ (
96+ guard .comparesEq ( left , k , true , sense ) and op = " == "
97+ or
98+ guard .comparesEq ( left , k , false , sense ) and op = " != "
99+ ) and
100+ msg =
101+ left .getAnyDef ( ) .getUnconvertedResultExpression ( ) + op + k + " when " + guard + " is " +
102+ which
65103 ) and
66- startLine = guard .getLocation ( ) .getStartLine ( ) and
67- msg =
68- left .getAnyDef ( ) .getUnconvertedResultExpression ( ) + op +
69- right .getAnyDef ( ) .getUnconvertedResultExpression ( ) + "+" + k + " when " + guard + " is " +
70- which
104+ startLine = guard .getLocation ( ) .getStartLine ( )
71105 )
72106}
73107
@@ -95,3 +129,16 @@ query predicate irGuardsEnsure(
95129 block .getLocation ( ) .hasLocationInfo ( _, start , _, end , _)
96130 )
97131}
132+
133+ query predicate irGuardsEnsure_const (
134+ IRGuardCondition guard , Instruction left , string op , int k , int start , int end
135+ ) {
136+ exists ( IRBlock block , Operand leftOp |
137+ guard .ensuresEq ( leftOp , k , block , true ) and op = "=="
138+ or
139+ guard .ensuresEq ( leftOp , k , block , false ) and op = "!="
140+ |
141+ leftOp = left .getAUse ( ) and
142+ block .getLocation ( ) .hasLocationInfo ( _, start , _, end , _)
143+ )
144+ }
0 commit comments