Skip to content

Commit 3c22067

Browse files
authored
Merge pull request #16333 from MathiasVP/fix-guards-on-pointers
2 parents 8c87cb8 + d18cdee commit 3c22067

File tree

11 files changed

+212
-14
lines changed

11 files changed

+212
-14
lines changed

cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,5 +1156,14 @@ private predicate add_eq(
11561156
)
11571157
}
11581158

1159+
private class IntegerOrPointerConstantInstruction extends ConstantInstruction {
1160+
IntegerOrPointerConstantInstruction() {
1161+
this instanceof IntegerConstantInstruction or
1162+
this instanceof PointerConstantInstruction
1163+
}
1164+
}
1165+
11591166
/** The int value of integer constant expression. */
1160-
private int int_value(Instruction i) { result = i.(IntegerConstantInstruction).getValue().toInt() }
1167+
private int int_value(Instruction i) {
1168+
result = i.(IntegerOrPointerConstantInstruction).getValue().toInt()
1169+
}

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/Instruction.qll

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -994,9 +994,8 @@ class ConstantInstruction extends ConstantValueInstruction {
994994
*/
995995
class IntegerConstantInstruction extends ConstantInstruction {
996996
IntegerConstantInstruction() {
997-
exists(IRType resultType |
998-
resultType = this.getResultIRType() and
999-
(resultType instanceof IRIntegerType or resultType instanceof IRBooleanType)
997+
exists(IRType resultType | resultType = this.getResultIRType() |
998+
resultType instanceof IRIntegerType or resultType instanceof IRBooleanType
1000999
)
10011000
}
10021001
}
@@ -1008,6 +1007,17 @@ class FloatConstantInstruction extends ConstantInstruction {
10081007
FloatConstantInstruction() { this.getResultIRType() instanceof IRFloatingPointType }
10091008
}
10101009

1010+
/**
1011+
* An instruction whose result is a constant value of a pointer type.
1012+
*/
1013+
class PointerConstantInstruction extends ConstantInstruction {
1014+
PointerConstantInstruction() {
1015+
exists(IRType resultType | resultType = this.getResultIRType() |
1016+
resultType instanceof IRAddressType or resultType instanceof IRFunctionAddressType
1017+
)
1018+
}
1019+
}
1020+
10111021
/**
10121022
* An instruction whose result is the address of a string literal.
10131023
*/

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/Instruction.qll

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -994,9 +994,8 @@ class ConstantInstruction extends ConstantValueInstruction {
994994
*/
995995
class IntegerConstantInstruction extends ConstantInstruction {
996996
IntegerConstantInstruction() {
997-
exists(IRType resultType |
998-
resultType = this.getResultIRType() and
999-
(resultType instanceof IRIntegerType or resultType instanceof IRBooleanType)
997+
exists(IRType resultType | resultType = this.getResultIRType() |
998+
resultType instanceof IRIntegerType or resultType instanceof IRBooleanType
1000999
)
10011000
}
10021001
}
@@ -1008,6 +1007,17 @@ class FloatConstantInstruction extends ConstantInstruction {
10081007
FloatConstantInstruction() { this.getResultIRType() instanceof IRFloatingPointType }
10091008
}
10101009

1010+
/**
1011+
* An instruction whose result is a constant value of a pointer type.
1012+
*/
1013+
class PointerConstantInstruction extends ConstantInstruction {
1014+
PointerConstantInstruction() {
1015+
exists(IRType resultType | resultType = this.getResultIRType() |
1016+
resultType instanceof IRAddressType or resultType instanceof IRFunctionAddressType
1017+
)
1018+
}
1019+
}
1020+
10111021
/**
10121022
* An instruction whose result is the address of a string literal.
10131023
*/

cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/Instruction.qll

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -994,9 +994,8 @@ class ConstantInstruction extends ConstantValueInstruction {
994994
*/
995995
class IntegerConstantInstruction extends ConstantInstruction {
996996
IntegerConstantInstruction() {
997-
exists(IRType resultType |
998-
resultType = this.getResultIRType() and
999-
(resultType instanceof IRIntegerType or resultType instanceof IRBooleanType)
997+
exists(IRType resultType | resultType = this.getResultIRType() |
998+
resultType instanceof IRIntegerType or resultType instanceof IRBooleanType
1000999
)
10011000
}
10021001
}
@@ -1008,6 +1007,17 @@ class FloatConstantInstruction extends ConstantInstruction {
10081007
FloatConstantInstruction() { this.getResultIRType() instanceof IRFloatingPointType }
10091008
}
10101009

1010+
/**
1011+
* An instruction whose result is a constant value of a pointer type.
1012+
*/
1013+
class PointerConstantInstruction extends ConstantInstruction {
1014+
PointerConstantInstruction() {
1015+
exists(IRType resultType | resultType = this.getResultIRType() |
1016+
resultType instanceof IRAddressType or resultType instanceof IRFunctionAddressType
1017+
)
1018+
}
1019+
}
1020+
10111021
/**
10121022
* An instruction whose result is the address of a string literal.
10131023
*/

cpp/ql/test/library-tests/controlflow/guards-ir/tests.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ astGuardsCompare
5656
| 17 | y < 1+1 when ... > ... is false |
5757
| 17 | y >= 1+1 when ... && ... is true |
5858
| 17 | y >= 1+1 when ... > ... is true |
59+
| 18 | call to get != 0 when call to get is true |
60+
| 18 | call to get == 0 when call to get is false |
5961
| 26 | 0 < x+0 when ... > ... is true |
6062
| 26 | 0 >= x+0 when ... > ... is false |
6163
| 26 | x < 0+1 when ... > ... is false |
@@ -487,6 +489,7 @@ astGuardsEnsure_const
487489
| test.c:109:9:109:23 | ... \|\| ... | test.c:109:9:109:9 | x | != | 0 | 113 | 113 |
488490
| test.c:175:13:175:32 | ... == ... | test.c:175:13:175:15 | call to foo | != | 0 | 175 | 175 |
489491
| test.c:175:13:175:32 | ... == ... | test.c:175:13:175:15 | call to foo | == | 0 | 175 | 175 |
492+
| test.cpp:18:8:18:10 | call to get | test.cpp:18:8:18:10 | call to get | != | 0 | 19 | 19 |
490493
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | != | -1 | 30 | 30 |
491494
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | != | -1 | 34 | 34 |
492495
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | == | -1 | 30 | 30 |
@@ -545,6 +548,8 @@ irGuardsCompare
545548
| 17 | y < 2 when CompareGT: ... > ... is false |
546549
| 17 | y >= 1+1 when CompareGT: ... > ... is true |
547550
| 17 | y >= 2 when CompareGT: ... > ... is true |
551+
| 18 | call to get != 0 when CompareNE: (bool)... is true |
552+
| 18 | call to get == 0 when CompareNE: (bool)... is false |
548553
| 26 | 0 < x+0 when CompareGT: ... > ... is true |
549554
| 26 | 0 >= x+0 when CompareGT: ... > ... is false |
550555
| 26 | x < 0+1 when CompareGT: ... > ... is false |
@@ -996,6 +1001,7 @@ irGuardsEnsure_const
9961001
| test.c:109:19:109:23 | CompareLT: ... < ... | test.c:109:19:109:19 | Load: y | >= | 0 | 113 | 113 |
9971002
| test.c:175:13:175:32 | CompareEQ: ... == ... | test.c:175:13:175:15 | Call: call to foo | != | 0 | 175 | 175 |
9981003
| test.c:175:13:175:32 | CompareEQ: ... == ... | test.c:175:13:175:15 | Call: call to foo | == | 0 | 175 | 175 |
1004+
| test.cpp:18:8:18:12 | CompareNE: (bool)... | test.cpp:18:8:18:10 | Call: call to get | != | 0 | 19 | 19 |
9991005
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | test.cpp:31:7:31:7 | Load: x | != | -1 | 34 | 34 |
10001006
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | test.cpp:31:7:31:7 | Load: x | == | -1 | 30 | 30 |
10011007
| test.cpp:31:7:31:13 | CompareEQ: ... == ... | test.cpp:31:7:31:7 | Load: x | == | -1 | 32 | 32 |

cpp/ql/test/library-tests/controlflow/guards/Guards.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@
3232
| test.cpp:61:10:61:10 | i |
3333
| test.cpp:74:10:74:10 | i |
3434
| test.cpp:84:10:84:10 | i |
35+
| test.cpp:93:6:93:6 | c |
36+
| test.cpp:99:6:99:6 | f |
37+
| test.cpp:105:6:105:14 | ... != ... |
38+
| test.cpp:111:6:111:14 | ... != ... |

cpp/ql/test/library-tests/controlflow/guards/GuardsCompare.expected

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
| 17 | y >= 1+1 when ... > ... is true |
2323
| 17 | y >= 2 when ... && ... is true |
2424
| 17 | y >= 2 when ... > ... is true |
25+
| 18 | call to get != 0 when call to get is true |
26+
| 18 | call to get == 0 when call to get is false |
2527
| 26 | 0 < x+0 when ... > ... is true |
2628
| 26 | 0 >= x+0 when ... > ... is false |
2729
| 26 | x < 0+1 when ... > ... is false |
@@ -107,6 +109,8 @@
107109
| 85 | y != 0+0 when ... && ... is true |
108110
| 85 | y == 0 when ... != ... is false |
109111
| 85 | y == 0+0 when ... != ... is false |
112+
| 93 | c != 0 when c is true |
113+
| 93 | c == 0 when c is false |
110114
| 94 | 0 != x+0 when ... != ... is true |
111115
| 94 | 0 == x+0 when ... != ... is false |
112116
| 94 | x != 0 when ... != ... is true |
@@ -119,6 +123,10 @@
119123
| 102 | j < 10+0 when ... < ... is true |
120124
| 102 | j >= 10 when ... < ... is false |
121125
| 102 | j >= 10+0 when ... < ... is false |
126+
| 105 | 0.0 != f+0 when ... != ... is true |
127+
| 105 | 0.0 == f+0 when ... != ... is false |
128+
| 105 | f != 0.0+0 when ... != ... is true |
129+
| 105 | f == 0.0+0 when ... != ... is false |
122130
| 109 | 0 != x+0 when ... == ... is false |
123131
| 109 | 0 != x+0 when ... \|\| ... is false |
124132
| 109 | 0 < y+1 when ... < ... is false |
@@ -137,3 +145,7 @@
137145
| 109 | y >= 0 when ... \|\| ... is false |
138146
| 109 | y >= 0+0 when ... < ... is false |
139147
| 109 | y >= 0+0 when ... \|\| ... is false |
148+
| 111 | 0.0 != i+0 when ... != ... is true |
149+
| 111 | 0.0 == i+0 when ... != ... is false |
150+
| 111 | i != 0.0+0 when ... != ... is true |
151+
| 111 | i == 0.0+0 when ... != ... is false |

cpp/ql/test/library-tests/controlflow/guards/GuardsControl.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,7 @@
9090
| test.cpp:61:10:61:10 | i | Case[1] | 65 | 66 |
9191
| test.cpp:74:10:74:10 | i | Case[0..10] | 75 | 77 |
9292
| test.cpp:74:10:74:10 | i | Case[11..20] | 78 | 79 |
93+
| test.cpp:93:6:93:6 | c | true | 93 | 94 |
94+
| test.cpp:99:6:99:6 | f | true | 99 | 100 |
95+
| test.cpp:105:6:105:14 | ... != ... | true | 105 | 106 |
96+
| test.cpp:111:6:111:14 | ... != ... | true | 111 | 112 |

cpp/ql/test/library-tests/controlflow/guards/GuardsEnsure.expected

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
binary
12
| test.c:7:9:7:13 | ... > ... | test.c:7:9:7:9 | x | < | test.c:7:13:7:13 | 0 | 1 | 10 | 11 |
23
| test.c:7:9:7:13 | ... > ... | test.c:7:9:7:9 | x | >= | test.c:7:13:7:13 | 0 | 1 | 7 | 9 |
34
| test.c:7:9:7:13 | ... > ... | test.c:7:13:7:13 | 0 | < | test.c:7:9:7:9 | x | 0 | 7 | 9 |
@@ -154,3 +155,94 @@
154155
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:12:31:13 | - ... | != | test.cpp:31:7:31:7 | x | 0 | 34 | 34 |
155156
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:12:31:13 | - ... | == | test.cpp:31:7:31:7 | x | 0 | 30 | 30 |
156157
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:12:31:13 | - ... | == | test.cpp:31:7:31:7 | x | 0 | 31 | 32 |
158+
| test.cpp:105:6:105:14 | ... != ... | test.cpp:105:6:105:6 | f | != | test.cpp:105:11:105:14 | 0.0 | 0 | 105 | 106 |
159+
| test.cpp:105:6:105:14 | ... != ... | test.cpp:105:11:105:14 | 0.0 | != | test.cpp:105:6:105:6 | f | 0 | 105 | 106 |
160+
| test.cpp:111:6:111:14 | ... != ... | test.cpp:111:6:111:6 | i | != | test.cpp:111:11:111:14 | 0.0 | 0 | 111 | 112 |
161+
| test.cpp:111:6:111:14 | ... != ... | test.cpp:111:11:111:14 | 0.0 | != | test.cpp:111:6:111:6 | i | 0 | 111 | 112 |
162+
unary
163+
| test.c:7:9:7:13 | ... > ... | test.c:7:9:7:9 | x | < | 1 | 10 | 11 |
164+
| test.c:7:9:7:13 | ... > ... | test.c:7:9:7:9 | x | >= | 1 | 7 | 9 |
165+
| test.c:17:8:17:12 | ... < ... | test.c:17:8:17:8 | x | < | 0 | 17 | 17 |
166+
| test.c:17:8:17:12 | ... < ... | test.c:17:8:17:8 | x | < | 0 | 18 | 18 |
167+
| test.c:17:8:17:21 | ... && ... | test.c:17:8:17:8 | x | < | 0 | 18 | 18 |
168+
| test.c:17:8:17:21 | ... && ... | test.c:17:17:17:17 | y | >= | 2 | 18 | 18 |
169+
| test.c:17:17:17:21 | ... > ... | test.c:17:17:17:17 | y | >= | 2 | 18 | 18 |
170+
| test.c:26:11:26:15 | ... > ... | test.c:26:11:26:11 | x | < | 1 | 2 | 2 |
171+
| test.c:26:11:26:15 | ... > ... | test.c:26:11:26:11 | x | < | 1 | 31 | 34 |
172+
| test.c:26:11:26:15 | ... > ... | test.c:26:11:26:11 | x | < | 1 | 34 | 34 |
173+
| test.c:26:11:26:15 | ... > ... | test.c:26:11:26:11 | x | < | 1 | 39 | 42 |
174+
| test.c:26:11:26:15 | ... > ... | test.c:26:11:26:11 | x | < | 1 | 42 | 42 |
175+
| test.c:26:11:26:15 | ... > ... | test.c:26:11:26:11 | x | < | 1 | 42 | 44 |
176+
| test.c:26:11:26:15 | ... > ... | test.c:26:11:26:11 | x | < | 1 | 45 | 45 |
177+
| test.c:26:11:26:15 | ... > ... | test.c:26:11:26:11 | x | < | 1 | 45 | 47 |
178+
| test.c:26:11:26:15 | ... > ... | test.c:26:11:26:11 | x | < | 1 | 51 | 53 |
179+
| test.c:26:11:26:15 | ... > ... | test.c:26:11:26:11 | x | < | 1 | 56 | 58 |
180+
| test.c:26:11:26:15 | ... > ... | test.c:26:11:26:11 | x | < | 1 | 58 | 58 |
181+
| test.c:26:11:26:15 | ... > ... | test.c:26:11:26:11 | x | < | 1 | 58 | 66 |
182+
| test.c:26:11:26:15 | ... > ... | test.c:26:11:26:11 | x | < | 1 | 62 | 62 |
183+
| test.c:26:11:26:15 | ... > ... | test.c:26:11:26:11 | x | >= | 1 | 26 | 28 |
184+
| test.c:34:16:34:21 | ... < ... | test.c:34:16:34:16 | j | < | 10 | 34 | 34 |
185+
| test.c:34:16:34:21 | ... < ... | test.c:34:16:34:16 | j | >= | 10 | 2 | 2 |
186+
| test.c:34:16:34:21 | ... < ... | test.c:34:16:34:16 | j | >= | 10 | 39 | 42 |
187+
| test.c:34:16:34:21 | ... < ... | test.c:34:16:34:16 | j | >= | 10 | 42 | 42 |
188+
| test.c:34:16:34:21 | ... < ... | test.c:34:16:34:16 | j | >= | 10 | 42 | 44 |
189+
| test.c:34:16:34:21 | ... < ... | test.c:34:16:34:16 | j | >= | 10 | 45 | 45 |
190+
| test.c:34:16:34:21 | ... < ... | test.c:34:16:34:16 | j | >= | 10 | 45 | 47 |
191+
| test.c:34:16:34:21 | ... < ... | test.c:34:16:34:16 | j | >= | 10 | 51 | 53 |
192+
| test.c:34:16:34:21 | ... < ... | test.c:34:16:34:16 | j | >= | 10 | 56 | 58 |
193+
| test.c:34:16:34:21 | ... < ... | test.c:34:16:34:16 | j | >= | 10 | 58 | 58 |
194+
| test.c:34:16:34:21 | ... < ... | test.c:34:16:34:16 | j | >= | 10 | 58 | 66 |
195+
| test.c:34:16:34:21 | ... < ... | test.c:34:16:34:16 | j | >= | 10 | 62 | 62 |
196+
| test.c:42:16:42:21 | ... < ... | test.c:42:16:42:16 | j | < | 10 | 42 | 42 |
197+
| test.c:42:16:42:21 | ... < ... | test.c:42:16:42:16 | j | < | 10 | 42 | 44 |
198+
| test.c:42:16:42:21 | ... < ... | test.c:42:16:42:16 | j | < | 10 | 45 | 45 |
199+
| test.c:42:16:42:21 | ... < ... | test.c:42:16:42:16 | j | < | 10 | 45 | 47 |
200+
| test.c:42:16:42:21 | ... < ... | test.c:42:16:42:16 | j | < | 10 | 51 | 53 |
201+
| test.c:44:12:44:16 | ... > ... | test.c:44:12:44:12 | z | < | 1 | 42 | 42 |
202+
| test.c:44:12:44:16 | ... > ... | test.c:44:12:44:12 | z | < | 1 | 51 | 53 |
203+
| test.c:44:12:44:16 | ... > ... | test.c:44:12:44:12 | z | >= | 1 | 45 | 45 |
204+
| test.c:44:12:44:16 | ... > ... | test.c:44:12:44:12 | z | >= | 1 | 45 | 47 |
205+
| test.c:45:16:45:20 | ... > ... | test.c:45:16:45:16 | y | >= | 1 | 45 | 47 |
206+
| test.c:58:9:58:14 | ... == ... | test.c:58:9:58:9 | x | != | 0 | 58 | 58 |
207+
| test.c:58:9:58:14 | ... == ... | test.c:58:9:58:9 | x | != | 0 | 62 | 62 |
208+
| test.c:58:9:58:23 | ... \|\| ... | test.c:58:9:58:9 | x | != | 0 | 62 | 62 |
209+
| test.c:58:9:58:23 | ... \|\| ... | test.c:58:19:58:19 | y | >= | 0 | 62 | 62 |
210+
| test.c:58:19:58:23 | ... < ... | test.c:58:19:58:19 | y | >= | 0 | 62 | 62 |
211+
| test.c:75:9:75:14 | ... == ... | test.c:75:9:75:9 | x | != | 0 | 78 | 79 |
212+
| test.c:75:9:75:14 | ... == ... | test.c:75:9:75:9 | x | == | 0 | 75 | 77 |
213+
| test.c:85:8:85:13 | ... == ... | test.c:85:8:85:8 | x | == | 0 | 85 | 85 |
214+
| test.c:85:8:85:13 | ... == ... | test.c:85:8:85:8 | x | == | 0 | 86 | 86 |
215+
| test.c:85:8:85:23 | ... && ... | test.c:85:8:85:8 | x | == | 0 | 86 | 86 |
216+
| test.c:85:8:85:23 | ... && ... | test.c:85:18:85:18 | y | != | 0 | 86 | 86 |
217+
| test.c:85:18:85:23 | ... != ... | test.c:85:18:85:18 | y | != | 0 | 86 | 86 |
218+
| test.c:94:11:94:16 | ... != ... | test.c:94:11:94:11 | x | != | 0 | 94 | 96 |
219+
| test.c:94:11:94:16 | ... != ... | test.c:94:11:94:11 | x | == | 0 | 70 | 70 |
220+
| test.c:94:11:94:16 | ... != ... | test.c:94:11:94:11 | x | == | 0 | 99 | 102 |
221+
| test.c:94:11:94:16 | ... != ... | test.c:94:11:94:11 | x | == | 0 | 102 | 102 |
222+
| test.c:94:11:94:16 | ... != ... | test.c:94:11:94:11 | x | == | 0 | 107 | 109 |
223+
| test.c:94:11:94:16 | ... != ... | test.c:94:11:94:11 | x | == | 0 | 109 | 109 |
224+
| test.c:94:11:94:16 | ... != ... | test.c:94:11:94:11 | x | == | 0 | 109 | 117 |
225+
| test.c:94:11:94:16 | ... != ... | test.c:94:11:94:11 | x | == | 0 | 113 | 113 |
226+
| test.c:102:16:102:21 | ... < ... | test.c:102:16:102:16 | j | < | 10 | 102 | 102 |
227+
| test.c:102:16:102:21 | ... < ... | test.c:102:16:102:16 | j | >= | 10 | 70 | 70 |
228+
| test.c:102:16:102:21 | ... < ... | test.c:102:16:102:16 | j | >= | 10 | 107 | 109 |
229+
| test.c:102:16:102:21 | ... < ... | test.c:102:16:102:16 | j | >= | 10 | 109 | 109 |
230+
| test.c:102:16:102:21 | ... < ... | test.c:102:16:102:16 | j | >= | 10 | 109 | 117 |
231+
| test.c:102:16:102:21 | ... < ... | test.c:102:16:102:16 | j | >= | 10 | 113 | 113 |
232+
| test.c:109:9:109:14 | ... == ... | test.c:109:9:109:9 | x | != | 0 | 109 | 109 |
233+
| test.c:109:9:109:14 | ... == ... | test.c:109:9:109:9 | x | != | 0 | 113 | 113 |
234+
| test.c:109:9:109:23 | ... \|\| ... | test.c:109:9:109:9 | x | != | 0 | 113 | 113 |
235+
| test.c:109:9:109:23 | ... \|\| ... | test.c:109:19:109:19 | y | >= | 0 | 113 | 113 |
236+
| test.c:109:19:109:23 | ... < ... | test.c:109:19:109:19 | y | >= | 0 | 113 | 113 |
237+
| test.cpp:18:8:18:10 | call to get | test.cpp:18:8:18:10 | call to get | != | 0 | 19 | 19 |
238+
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | != | -1 | 30 | 30 |
239+
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | != | -1 | 34 | 34 |
240+
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | == | -1 | 30 | 30 |
241+
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | == | -1 | 31 | 32 |
242+
| test.cpp:61:10:61:10 | i | test.cpp:61:10:61:10 | i | == | 0 | 62 | 64 |
243+
| test.cpp:61:10:61:10 | i | test.cpp:61:10:61:10 | i | == | 1 | 65 | 66 |
244+
| test.cpp:74:10:74:10 | i | test.cpp:74:10:74:10 | i | < | 11 | 75 | 77 |
245+
| test.cpp:74:10:74:10 | i | test.cpp:74:10:74:10 | i | < | 21 | 78 | 79 |
246+
| test.cpp:74:10:74:10 | i | test.cpp:74:10:74:10 | i | >= | 0 | 75 | 77 |
247+
| test.cpp:74:10:74:10 | i | test.cpp:74:10:74:10 | i | >= | 11 | 78 | 79 |
248+
| test.cpp:93:6:93:6 | c | test.cpp:93:6:93:6 | c | != | 0 | 93 | 94 |

cpp/ql/test/library-tests/controlflow/guards/GuardsEnsure.ql

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
import cpp
88
import semmle.code.cpp.controlflow.Guards
99

10-
from GuardCondition guard, Expr left, Expr right, int k, int start, int end, string op
11-
where
10+
query predicate binary(
11+
GuardCondition guard, Expr left, string op, Expr right, int k, int start, int end
12+
) {
1213
exists(BasicBlock block |
1314
guard.ensuresLt(left, right, k, block, true) and op = "<"
1415
or
@@ -20,4 +21,18 @@ where
2021
|
2122
block.hasLocationInfo(_, start, _, end, _)
2223
)
23-
select guard, left, op, right, k, start, end
24+
}
25+
26+
query predicate unary(GuardCondition guard, Expr left, string op, int k, int start, int end) {
27+
exists(BasicBlock block |
28+
guard.ensuresLt(left, k, block, true) and op = "<"
29+
or
30+
guard.ensuresLt(left, k, block, false) and op = ">="
31+
or
32+
guard.ensuresEq(left, k, block, true) and op = "=="
33+
or
34+
guard.ensuresEq(left, k, block, false) and op = "!="
35+
|
36+
block.hasLocationInfo(_, start, _, end, _)
37+
)
38+
}

0 commit comments

Comments
 (0)