Skip to content

Commit bf61114

Browse files
committed
C++: Add a test with pointer comparisons and float comparisons.
1 parent d6c57de commit bf61114

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@
119119
| 102 | j < 10+0 when ... < ... is true |
120120
| 102 | j >= 10 when ... < ... is false |
121121
| 102 | j >= 10+0 when ... < ... is false |
122+
| 105 | 0.0 != f+0 when ... != ... is true |
123+
| 105 | 0.0 == f+0 when ... != ... is false |
124+
| 105 | f != 0.0+0 when ... != ... is true |
125+
| 105 | f == 0.0+0 when ... != ... is false |
122126
| 109 | 0 != x+0 when ... == ... is false |
123127
| 109 | 0 != x+0 when ... \|\| ... is false |
124128
| 109 | 0 < y+1 when ... < ... is false |
@@ -137,3 +141,7 @@
137141
| 109 | y >= 0 when ... \|\| ... is false |
138142
| 109 | y >= 0+0 when ... < ... is false |
139143
| 109 | y >= 0+0 when ... \|\| ... is false |
144+
| 111 | 0.0 != i+0 when ... != ... is true |
145+
| 111 | 0.0 == i+0 when ... != ... is false |
146+
| 111 | i != 0.0+0 when ... != ... is true |
147+
| 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ binary
155155
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:12:31:13 | - ... | != | test.cpp:31:7:31:7 | x | 0 | 34 | 34 |
156156
| test.cpp:31:7:31:13 | ... == ... | test.cpp:31:12:31:13 | - ... | == | test.cpp:31:7:31:7 | x | 0 | 30 | 30 |
157157
| 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 |
158162
unary
159163
| test.c:7:9:7:13 | ... > ... | test.c:7:9:7:9 | x | < | 1 | 10 | 11 |
160164
| test.c:7:9:7:13 | ... > ... | test.c:7:9:7:9 | x | >= | 1 | 7 | 9 |

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,30 @@ void test_switches_default(int i) {
8585
default:
8686
use1(i);
8787
}
88-
}
88+
}
89+
90+
void use(...);
91+
92+
void pointer_comparison(char* c) {
93+
if(c) {
94+
use(c);
95+
}
96+
}
97+
98+
void implicit_float_comparison(float f) {
99+
if(f) {
100+
use(f);
101+
}
102+
}
103+
104+
void explicit_float_comparison(float f) {
105+
if(f != 0.0f) {
106+
use(f);
107+
}
108+
}
109+
110+
void int_float_comparison(int i) {
111+
if(i != 0.0f) {
112+
use(i);
113+
}
114+
}

0 commit comments

Comments
 (0)