Skip to content

Commit e0a7889

Browse files
committed
C++: Undo the hack.
1 parent bd09aad commit e0a7889

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaImpl.qll

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -432,23 +432,7 @@ private class DirectUseImpl extends UseImpl, TDirectUseImpl {
432432
override string toString() { result = "Use of " + this.getSourceVariable() }
433433

434434
final override predicate hasIndexInBlock(IRBlock block, int index) {
435-
// See the comment in `ssa0`'s `OperandBasedUse` for an explanation of this
436-
// predicate's implementation.
437-
if this.getBase().getAst() = any(Cpp::PostfixCrementOperation c).getOperand()
438-
then
439-
exists(Operand op, int indirection, Instruction base |
440-
indirection = this.getIndirection() and
441-
base = this.getBase() and
442-
op =
443-
min(Operand cand, int i |
444-
isUse(_, cand, base, indirection, indirectionIndex) and
445-
block.getInstruction(i) = cand.getUse()
446-
|
447-
cand order by i
448-
) and
449-
block.getInstruction(index) = op.getUse()
450-
)
451-
else operand.getUse() = block.getInstruction(index)
435+
operand.getUse() = block.getInstruction(index)
452436
}
453437

454438
private BaseSourceVariableInstruction getBase() { isUse(_, operand, result, _, indirectionIndex) }

cpp/ql/test/library-tests/dataflow/dataflow-tests/test-source-sink.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,11 @@ irFlow
378378
| test.cpp:1195:10:1195:24 | *call to indirect_source | test.cpp:1224:19:1224:37 | ** ... |
379379
| test.cpp:1195:10:1195:24 | *call to indirect_source | test.cpp:1227:10:1227:29 | * ... |
380380
| test.cpp:1258:11:1258:16 | call to source | test.cpp:1259:8:1259:10 | ... ++ |
381+
| test.cpp:1258:11:1258:16 | call to source | test.cpp:1260:8:1260:8 | x |
381382
| test.cpp:1262:7:1262:12 | call to source | test.cpp:1263:8:1263:10 | ... -- |
383+
| test.cpp:1262:7:1262:12 | call to source | test.cpp:1264:8:1264:8 | x |
382384
| test.cpp:1284:11:1284:16 | call to source | test.cpp:1285:8:1285:20 | ... ? ... : ... |
385+
| test.cpp:1284:11:1284:16 | call to source | test.cpp:1286:8:1286:8 | x |
383386
| test.cpp:1288:7:1288:12 | call to source | test.cpp:1290:8:1290:8 | x |
384387
| test.cpp:1292:7:1292:12 | call to source | test.cpp:1294:8:1294:8 | x |
385388
| test.cpp:1296:7:1296:12 | call to source | test.cpp:1297:8:1297:18 | ... ? ... : ... |
@@ -388,6 +391,7 @@ irFlow
388391
| test.cpp:1300:7:1300:12 | call to source | test.cpp:1302:8:1302:8 | x |
389392
| test.cpp:1304:7:1304:12 | call to source | test.cpp:1306:8:1306:8 | x |
390393
| test.cpp:1308:7:1308:12 | call to source | test.cpp:1309:8:1309:16 | ... ++ |
394+
| test.cpp:1308:7:1308:12 | call to source | test.cpp:1310:8:1310:8 | x |
391395
| test.cpp:1312:7:1312:12 | call to source | test.cpp:1313:8:1313:24 | ... ? ... : ... |
392396
| test.cpp:1312:7:1312:12 | call to source | test.cpp:1314:8:1314:8 | x |
393397
| true_upon_entry.cpp:9:11:9:16 | call to source | true_upon_entry.cpp:13:8:13:8 | x |

cpp/ql/test/library-tests/dataflow/dataflow-tests/test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,11 +1257,11 @@ namespace globals_without_explicit_def {
12571257
void crement_test1() {
12581258
int x = source();
12591259
sink(x++); // $ ir ast
1260-
sink(x);
1260+
sink(x); // $ SPURIOUS: ir
12611261

12621262
x = source();
12631263
sink(x--); // $ ir ast
1264-
sink(x);
1264+
sink(x); // $ SPURIOUS: ir
12651265

12661266
x = source();
12671267
sink(++x); // $ SPURIOUS: ast
@@ -1283,7 +1283,7 @@ void crement_test1() {
12831283
void crement_test2(bool b, int y) {
12841284
int x = source();
12851285
sink(b ? x++ : x--); // $ ir ast
1286-
sink(x);
1286+
sink(x); // $ SPURIOUS: ir
12871287

12881288
x = source();
12891289
sink((b ? x : y)++); // $ ast MISSING: ir
@@ -1307,7 +1307,7 @@ void crement_test2(bool b, int y) {
13071307

13081308
x = source();
13091309
sink((long)x++); // $ ir ast
1310-
sink(x);
1310+
sink(x); // $ SPURIOUS: ir
13111311

13121312
x = source();
13131313
sink(b ? (long)x++ : 0); // $ ir ast

0 commit comments

Comments
 (0)