Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad8f30d

Browse files
author
Robert Marsh
committed
C++: accept test output and add IR guards tests
1 parent d7e630b commit ad8f30d

12 files changed

Lines changed: 458 additions & 5 deletions

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@
2828
| test.c:146:7:146:8 | ! ... |
2929
| test.c:146:8:146:8 | x |
3030
| test.cpp:18:8:18:10 | call to get |
31+
| test.cpp:18:8:18:12 | (bool)... |
3132
| test.cpp:31:7:31:13 | ... == ... |
3233
| test.cpp:42:13:42:20 | call to getABool |

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
| 17 | y < 1+1 when ... > ... is false |
1515
| 17 | y >= 1+1 when ... && ... is true |
1616
| 17 | y >= 1+1 when ... > ... is true |
17+
| 18 | call to get != call to get+0 when (bool)... is true |
18+
| 18 | call to get != call to get+0 when call to get is true |
19+
| 18 | call to get == call to get+0 when (bool)... is false |
20+
| 18 | call to get == call to get+0 when call to get is false |
1721
| 26 | 0 < x+0 when ... > ... is true |
1822
| 26 | 0 >= x+0 when ... > ... is false |
1923
| 26 | x < 0+1 when ... > ... is false |

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,18 @@
7474
| test.c:109:19:109:23 | ... < ... | false | 113 | 113 |
7575
| test.c:126:7:126:7 | 1 | true | 126 | 126 |
7676
| test.c:126:7:126:7 | 1 | true | 126 | 128 |
77-
| test.c:126:7:126:7 | 1 | true | 131 | 131 |
78-
| test.c:126:7:126:7 | 1 | true | 131 | 132 |
79-
| test.c:126:7:126:7 | 1 | true | 134 | 123 |
8077
| test.c:126:7:126:28 | ... && ... | true | 126 | 128 |
8178
| test.c:126:12:126:26 | call to test3_condition | true | 126 | 128 |
8279
| test.c:131:7:131:7 | b | true | 131 | 132 |
83-
| test.c:137:7:137:7 | 0 | false | 142 | 136 |
80+
| test.c:137:7:137:7 | 0 | true | 137 | 138 |
81+
| test.c:137:7:137:7 | 0 | true | 138 | 139 |
8482
| test.c:138:9:138:9 | i | true | 138 | 139 |
8583
| test.c:146:7:146:8 | ! ... | true | 146 | 147 |
8684
| test.c:146:8:146:8 | x | false | 146 | 147 |
87-
| test.cpp:18:8:18:10 | call to get | false | 20 | 16 |
85+
| test.cpp:18:8:18:10 | call to get | true | 19 | 19 |
86+
| test.cpp:18:8:18:12 | (bool)... | true | 19 | 19 |
87+
| test.cpp:31:7:31:13 | ... == ... | false | 30 | 30 |
8888
| test.cpp:31:7:31:13 | ... == ... | false | 34 | 34 |
89+
| test.cpp:31:7:31:13 | ... == ... | true | 30 | 30 |
8990
| test.cpp:31:7:31:13 | ... == ... | true | 31 | 32 |
9091
| test.cpp:42:13:42:20 | call to getABool | true | 43 | 45 |

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,13 @@
154154
| test.c:109:9:109:23 | ... \|\| ... | test.c:109:23:109:23 | 0 | < | test.c:109:19:109:19 | y | 1 | 113 | 113 |
155155
| test.c:109:19:109:23 | ... < ... | test.c:109:19:109:19 | y | >= | test.c:109:23:109:23 | 0 | 0 | 113 | 113 |
156156
| test.c:109:19:109:23 | ... < ... | test.c:109:23:109:23 | 0 | < | test.c:109:19:109:19 | y | 1 | 113 | 113 |
157+
| test.cpp:18:8:18:10 | call to get | test.cpp:18:8:18:10 | call to get | != | test.cpp:18:8:18:10 | call to get | 0 | 19 | 19 |
158+
| test.cpp:18:8:18:12 | (bool)... | test.cpp:18:8:18:10 | call to get | != | test.cpp:18:8:18:10 | call to get | 0 | 19 | 19 |
159+
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | != | test.cpp:31:12:31:13 | - ... | 0 | 30 | 30 |
157160
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | != | test.cpp:31:12:31:13 | - ... | 0 | 34 | 34 |
161+
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | == | test.cpp:31:12:31:13 | - ... | 0 | 30 | 30 |
158162
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:7:31:7 | x | == | test.cpp:31:12:31:13 | - ... | 0 | 31 | 32 |
163+
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:12:31:13 | - ... | != | test.cpp:31:7:31:7 | x | 0 | 30 | 30 |
159164
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:12:31:13 | - ... | != | test.cpp:31:7:31:7 | x | 0 | 34 | 34 |
165+
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:12:31:13 | - ... | == | test.cpp:31:7:31:7 | x | 0 | 30 | 30 |
160166
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:12:31:13 | - ... | == | test.cpp:31:7:31:7 | x | 0 | 31 | 32 |
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
| test.c:7:9:7:13 | ... > ... |
2+
| test.c:17:8:17:12 | ... < ... |
3+
| test.c:17:17:17:21 | ... > ... |
4+
| test.c:26:11:26:15 | ... > ... |
5+
| test.c:34:16:34:21 | ... < ... |
6+
| test.c:42:16:42:21 | ... < ... |
7+
| test.c:44:12:44:16 | ... > ... |
8+
| test.c:45:16:45:20 | ... > ... |
9+
| test.c:58:9:58:14 | ... == ... |
10+
| test.c:58:19:58:23 | ... < ... |
11+
| test.c:75:9:75:14 | ... == ... |
12+
| test.c:85:8:85:13 | ... == ... |
13+
| test.c:85:18:85:23 | ... != ... |
14+
| test.c:94:11:94:16 | ... != ... |
15+
| test.c:102:16:102:21 | ... < ... |
16+
| test.c:109:9:109:14 | ... == ... |
17+
| test.c:109:19:109:23 | ... < ... |
18+
| test.c:126:7:126:7 | 1 |
19+
| test.c:126:12:126:26 | call to test3_condition |
20+
| test.c:131:7:131:7 | b |
21+
| test.c:137:7:137:7 | 0 |
22+
| test.c:138:9:138:9 | i |
23+
| test.c:146:8:146:8 | x |
24+
| test.cpp:18:8:18:12 | (bool)... |
25+
| test.cpp:31:7:31:13 | ... == ... |
26+
| test.cpp:42:13:42:20 | call to getABool |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import cpp
2+
import semmle.code.cpp.controlflow.IRGuards
3+
4+
from IRGuardCondition guard
5+
select guard.getAST()
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
| 7 | 0 < x+0 when ... > ... is true |
2+
| 7 | 0 >= x+0 when ... > ... is false |
3+
| 7 | x < 0+1 when ... > ... is false |
4+
| 7 | x >= 0+1 when ... > ... is true |
5+
| 17 | 0 < x+1 when ... < ... is false |
6+
| 17 | 0 >= x+1 when ... < ... is true |
7+
| 17 | 1 < y+0 when ... > ... is true |
8+
| 17 | 1 >= y+0 when ... > ... is false |
9+
| 17 | (long)... < y+0 when ... > ... is true |
10+
| 17 | (long)... >= y+0 when ... > ... is false |
11+
| 17 | x < 0+0 when ... < ... is true |
12+
| 17 | x >= 0+0 when ... < ... is false |
13+
| 17 | y < 1+1 when ... > ... is false |
14+
| 17 | y < (long)...+1 when ... > ... is false |
15+
| 17 | y >= 1+1 when ... > ... is true |
16+
| 17 | y >= (long)...+1 when ... > ... is true |
17+
| 18 | (bool)... != call to get+0 when (bool)... is true |
18+
| 18 | (bool)... != call to get+0 when call to get is true |
19+
| 18 | (bool)... == call to get+0 when (bool)... is false |
20+
| 18 | (bool)... == call to get+0 when call to get is false |
21+
| 18 | call to get != (bool)...+0 when (bool)... is true |
22+
| 18 | call to get != (bool)...+0 when call to get is true |
23+
| 18 | call to get != call to get+0 when (bool)... is true |
24+
| 18 | call to get != call to get+0 when call to get is true |
25+
| 18 | call to get == (bool)...+0 when (bool)... is false |
26+
| 18 | call to get == (bool)...+0 when call to get is false |
27+
| 18 | call to get == call to get+0 when (bool)... is false |
28+
| 18 | call to get == call to get+0 when call to get is false |
29+
| 26 | 0 < x+0 when ... > ... is true |
30+
| 26 | 0 >= x+0 when ... > ... is false |
31+
| 26 | x < 0+1 when ... > ... is false |
32+
| 26 | x >= 0+1 when ... > ... is true |
33+
| 31 | - ... != x+0 when ... == ... is false |
34+
| 31 | - ... == x+0 when ... == ... is true |
35+
| 31 | x != - ...+0 when ... == ... is false |
36+
| 31 | x == - ...+0 when ... == ... is true |
37+
| 34 | 10 < j+1 when ... < ... is false |
38+
| 34 | 10 >= j+1 when ... < ... is true |
39+
| 34 | j < 10+0 when ... < ... is true |
40+
| 34 | j >= 10+0 when ... < ... is false |
41+
| 42 | 10 < j+1 when ... < ... is false |
42+
| 42 | 10 >= j+1 when ... < ... is true |
43+
| 42 | j < 10+0 when ... < ... is true |
44+
| 42 | j >= 10+0 when ... < ... is false |
45+
| 44 | 0 < z+0 when ... > ... is true |
46+
| 44 | 0 >= z+0 when ... > ... is false |
47+
| 44 | z < 0+1 when ... > ... is false |
48+
| 44 | z >= 0+1 when ... > ... is true |
49+
| 45 | 0 < y+0 when ... > ... is true |
50+
| 45 | 0 >= y+0 when ... > ... is false |
51+
| 45 | (long)... < y+0 when ... > ... is true |
52+
| 45 | (long)... >= y+0 when ... > ... is false |
53+
| 45 | y < 0+1 when ... > ... is false |
54+
| 45 | y < (long)...+1 when ... > ... is false |
55+
| 45 | y >= 0+1 when ... > ... is true |
56+
| 45 | y >= (long)...+1 when ... > ... is true |
57+
| 58 | 0 != x+0 when ... == ... is false |
58+
| 58 | 0 < y+1 when ... < ... is false |
59+
| 58 | 0 == x+0 when ... == ... is true |
60+
| 58 | 0 >= y+1 when ... < ... is true |
61+
| 58 | (long)... < y+1 when ... < ... is false |
62+
| 58 | (long)... >= y+1 when ... < ... is true |
63+
| 58 | x != 0+0 when ... == ... is false |
64+
| 58 | x == 0+0 when ... == ... is true |
65+
| 58 | y < 0+0 when ... < ... is true |
66+
| 58 | y < (long)...+0 when ... < ... is true |
67+
| 58 | y >= 0+0 when ... < ... is false |
68+
| 58 | y >= (long)...+0 when ... < ... is false |
69+
| 75 | 0 != x+0 when ... == ... is false |
70+
| 75 | 0 == x+0 when ... == ... is true |
71+
| 75 | x != 0+0 when ... == ... is false |
72+
| 75 | x == 0+0 when ... == ... is true |
73+
| 85 | 0 != x+0 when ... == ... is false |
74+
| 85 | 0 != y+0 when ... != ... is true |
75+
| 85 | 0 == x+0 when ... == ... is true |
76+
| 85 | 0 == y+0 when ... != ... is false |
77+
| 85 | (long)... != y+0 when ... != ... is true |
78+
| 85 | (long)... == y+0 when ... != ... is false |
79+
| 85 | x != 0+0 when ... == ... is false |
80+
| 85 | x == 0+0 when ... == ... is true |
81+
| 85 | y != 0+0 when ... != ... is true |
82+
| 85 | y != (long)...+0 when ... != ... is true |
83+
| 85 | y == 0+0 when ... != ... is false |
84+
| 85 | y == (long)...+0 when ... != ... is false |
85+
| 94 | 0 != x+0 when ... != ... is true |
86+
| 94 | 0 == x+0 when ... != ... is false |
87+
| 94 | x != 0+0 when ... != ... is true |
88+
| 94 | x == 0+0 when ... != ... is false |
89+
| 102 | 10 < j+1 when ... < ... is false |
90+
| 102 | 10 >= j+1 when ... < ... is true |
91+
| 102 | j < 10+0 when ... < ... is true |
92+
| 102 | j >= 10+0 when ... < ... is false |
93+
| 109 | 0 != x+0 when ... == ... is false |
94+
| 109 | 0 < y+1 when ... < ... is false |
95+
| 109 | 0 == x+0 when ... == ... is true |
96+
| 109 | 0 >= y+1 when ... < ... is true |
97+
| 109 | (long)... < y+1 when ... < ... is false |
98+
| 109 | (long)... >= y+1 when ... < ... is true |
99+
| 109 | x != 0+0 when ... == ... is false |
100+
| 109 | x == 0+0 when ... == ... is true |
101+
| 109 | y < 0+0 when ... < ... is true |
102+
| 109 | y < (long)...+0 when ... < ... is true |
103+
| 109 | y >= 0+0 when ... < ... is false |
104+
| 109 | y >= (long)...+0 when ... < ... is false |
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @name Guards comparison test
3+
* @description List comparison parts.
4+
* @kind test
5+
*/
6+
7+
import cpp
8+
import semmle.code.cpp.controlflow.IRGuards
9+
10+
Element clearConversions(Element e) {
11+
if e instanceof Conversion
12+
then result = e.(Conversion).getExpr*()
13+
else result = e
14+
}
15+
16+
from IRGuardCondition guard, Instruction left, Instruction right, int k, string which, string op, string msg
17+
where
18+
(exists(boolean sense | sense = true and which = "true" or sense = false and which = "false" |
19+
guard.comparesLt(left, right, k, true, sense) and op = " < "
20+
or
21+
guard.comparesLt(left, right, k, false, sense) and op = " >= "
22+
or
23+
guard.comparesEq(left, right, k, true, sense) and op = " == "
24+
or
25+
guard.comparesEq(left, right, k, false, sense) and op = " != "
26+
)
27+
)
28+
and msg = clearConversions(left.getAST()) + op + clearConversions(right.getAST()) + "+" + k + " when " + clearConversions(guard.getAST()) + " is " + which
29+
30+
select guard.getLocation().getStartLine(), msg
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
| test.c:7:9:7:13 | ... > ... | false | 11 | 11 |
2+
| test.c:7:9:7:13 | ... > ... | true | 8 | 8 |
3+
| test.c:17:8:17:12 | ... < ... | true | 17 | 17 |
4+
| test.c:17:8:17:12 | ... < ... | true | 18 | 18 |
5+
| test.c:17:17:17:21 | ... > ... | true | 18 | 18 |
6+
| test.c:26:11:26:15 | ... > ... | false | 2 | 2 |
7+
| test.c:26:11:26:15 | ... > ... | false | 31 | 31 |
8+
| test.c:26:11:26:15 | ... > ... | false | 34 | 34 |
9+
| test.c:26:11:26:15 | ... > ... | false | 35 | 35 |
10+
| test.c:26:11:26:15 | ... > ... | false | 39 | 39 |
11+
| test.c:26:11:26:15 | ... > ... | false | 42 | 42 |
12+
| test.c:26:11:26:15 | ... > ... | false | 43 | 43 |
13+
| test.c:26:11:26:15 | ... > ... | false | 45 | 45 |
14+
| test.c:26:11:26:15 | ... > ... | false | 46 | 46 |
15+
| test.c:26:11:26:15 | ... > ... | false | 49 | 49 |
16+
| test.c:26:11:26:15 | ... > ... | false | 52 | 52 |
17+
| test.c:26:11:26:15 | ... > ... | false | 56 | 56 |
18+
| test.c:26:11:26:15 | ... > ... | false | 58 | 58 |
19+
| test.c:26:11:26:15 | ... > ... | false | 59 | 59 |
20+
| test.c:26:11:26:15 | ... > ... | false | 62 | 62 |
21+
| test.c:26:11:26:15 | ... > ... | true | 27 | 27 |
22+
| test.c:34:16:34:21 | ... < ... | false | 2 | 2 |
23+
| test.c:34:16:34:21 | ... < ... | false | 39 | 39 |
24+
| test.c:34:16:34:21 | ... < ... | false | 42 | 42 |
25+
| test.c:34:16:34:21 | ... < ... | false | 43 | 43 |
26+
| test.c:34:16:34:21 | ... < ... | false | 45 | 45 |
27+
| test.c:34:16:34:21 | ... < ... | false | 46 | 46 |
28+
| test.c:34:16:34:21 | ... < ... | false | 49 | 49 |
29+
| test.c:34:16:34:21 | ... < ... | false | 52 | 52 |
30+
| test.c:34:16:34:21 | ... < ... | false | 56 | 56 |
31+
| test.c:34:16:34:21 | ... < ... | false | 58 | 58 |
32+
| test.c:34:16:34:21 | ... < ... | false | 59 | 59 |
33+
| test.c:34:16:34:21 | ... < ... | false | 62 | 62 |
34+
| test.c:34:16:34:21 | ... < ... | true | 35 | 35 |
35+
| test.c:42:16:42:21 | ... < ... | true | 42 | 42 |
36+
| test.c:42:16:42:21 | ... < ... | true | 43 | 43 |
37+
| test.c:42:16:42:21 | ... < ... | true | 45 | 45 |
38+
| test.c:42:16:42:21 | ... < ... | true | 46 | 46 |
39+
| test.c:42:16:42:21 | ... < ... | true | 49 | 49 |
40+
| test.c:42:16:42:21 | ... < ... | true | 52 | 52 |
41+
| test.c:44:12:44:16 | ... > ... | false | 52 | 52 |
42+
| test.c:44:12:44:16 | ... > ... | true | 45 | 45 |
43+
| test.c:44:12:44:16 | ... > ... | true | 46 | 46 |
44+
| test.c:44:12:44:16 | ... > ... | true | 49 | 49 |
45+
| test.c:45:16:45:20 | ... > ... | false | 49 | 49 |
46+
| test.c:45:16:45:20 | ... > ... | true | 46 | 46 |
47+
| test.c:58:9:58:14 | ... == ... | false | 58 | 58 |
48+
| test.c:58:9:58:14 | ... == ... | false | 62 | 62 |
49+
| test.c:58:19:58:23 | ... < ... | false | 62 | 62 |
50+
| test.c:75:9:75:14 | ... == ... | false | 79 | 79 |
51+
| test.c:75:9:75:14 | ... == ... | true | 76 | 76 |
52+
| test.c:85:8:85:13 | ... == ... | true | 85 | 85 |
53+
| test.c:85:8:85:13 | ... == ... | true | 86 | 86 |
54+
| test.c:85:18:85:23 | ... != ... | true | 86 | 86 |
55+
| test.c:94:11:94:16 | ... != ... | false | 70 | 70 |
56+
| test.c:94:11:94:16 | ... != ... | false | 99 | 99 |
57+
| test.c:94:11:94:16 | ... != ... | false | 102 | 102 |
58+
| test.c:94:11:94:16 | ... != ... | false | 103 | 103 |
59+
| test.c:94:11:94:16 | ... != ... | false | 107 | 107 |
60+
| test.c:94:11:94:16 | ... != ... | false | 109 | 109 |
61+
| test.c:94:11:94:16 | ... != ... | false | 110 | 110 |
62+
| test.c:94:11:94:16 | ... != ... | false | 113 | 113 |
63+
| test.c:94:11:94:16 | ... != ... | true | 95 | 95 |
64+
| test.c:102:16:102:21 | ... < ... | false | 70 | 70 |
65+
| test.c:102:16:102:21 | ... < ... | false | 107 | 107 |
66+
| test.c:102:16:102:21 | ... < ... | false | 109 | 109 |
67+
| test.c:102:16:102:21 | ... < ... | false | 110 | 110 |
68+
| test.c:102:16:102:21 | ... < ... | false | 113 | 113 |
69+
| test.c:102:16:102:21 | ... < ... | true | 103 | 103 |
70+
| test.c:109:9:109:14 | ... == ... | false | 109 | 109 |
71+
| test.c:109:9:109:14 | ... == ... | false | 113 | 113 |
72+
| test.c:109:19:109:23 | ... < ... | false | 113 | 113 |
73+
| test.c:126:7:126:7 | 1 | true | 126 | 126 |
74+
| test.c:126:7:126:7 | 1 | true | 127 | 127 |
75+
| test.c:126:12:126:26 | call to test3_condition | true | 127 | 127 |
76+
| test.c:131:7:131:7 | b | true | 132 | 132 |
77+
| test.c:137:7:137:7 | 0 | true | 138 | 138 |
78+
| test.c:137:7:137:7 | 0 | true | 139 | 139 |
79+
| test.c:138:9:138:9 | i | true | 139 | 139 |
80+
| test.c:146:8:146:8 | x | false | 147 | 147 |
81+
| test.cpp:18:8:18:12 | (bool)... | true | 0 | 0 |
82+
| test.cpp:31:7:31:13 | ... == ... | false | 34 | 34 |
83+
| test.cpp:31:7:31:13 | ... == ... | true | 30 | 30 |
84+
| test.cpp:31:7:31:13 | ... == ... | true | 32 | 32 |
85+
| test.cpp:42:13:42:20 | call to getABool | true | 44 | 44 |
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @name Guards control test
3+
* @description List which guards control which blocks
4+
* @kind test
5+
*/
6+
7+
import cpp
8+
import semmle.code.cpp.controlflow.IRGuards
9+
10+
from IRGuardCondition guard, boolean sense, int start, int end
11+
where
12+
exists(IRBlock block |
13+
guard.controls(block, sense) and
14+
block.getLocation().hasLocationInfo(_, start, _, end, _)
15+
)
16+
select guard.getAST(), sense, start, end

0 commit comments

Comments
 (0)