@@ -4,22 +4,32 @@ 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 , Expr right , int k , string which , string op |
7
+ exists ( GuardCondition guard , Expr left , int k , string which , string op |
8
8
exists ( boolean sense |
9
9
sense = true and which = "true"
10
10
or
11
11
sense = false and which = "false"
12
12
|
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
+ )
14
24
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
20
31
) and
21
- startLine = guard .getLocation ( ) .getStartLine ( ) and
22
- msg = left + op + right + "+" + k + " when " + guard + " is " + which
32
+ startLine = guard .getLocation ( ) .getStartLine ( )
23
33
)
24
34
}
25
35
@@ -46,28 +56,52 @@ query predicate astGuardsEnsure(
46
56
)
47
57
}
48
58
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
+
49
71
query predicate irGuards ( IRGuardCondition guard ) { any ( ) }
50
72
51
73
query 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 |
53
75
exists ( boolean sense |
54
76
sense = true and which = "true"
55
77
or
56
78
sense = false and which = "false"
57
79
|
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
+ )
59
94
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
65
103
) 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 ( )
71
105
)
72
106
}
73
107
@@ -95,3 +129,16 @@ query predicate irGuardsEnsure(
95
129
block .getLocation ( ) .hasLocationInfo ( _, start , _, end , _)
96
130
)
97
131
}
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