Skip to content

Commit f4b4ddb

Browse files
committed
CPP: Add a test examining the LoopEntryConditionEvaluator on this code.
1 parent 12bbb07 commit f4b4ddb

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
| test.cpp:35:2:37:2 | for(...;...;...) ... | test.cpp:35:18:35:23 | ... < ... | 1 | i | { ... } | i | ExprStmt |
2+
| test.cpp:43:2:45:2 | for(...;...;...) ... | test.cpp:43:18:43:26 | ... < ... | | i | { ... } | i | ExprStmt |
3+
| test.cpp:74:2:77:2 | while (...) ... | test.cpp:74:9:74:17 | ... > ... | 1 | count | { ... } | count | ExprStmt |
4+
| test.cpp:84:2:88:2 | while (...) ... | test.cpp:84:9:84:17 | ... > ... | | count | { ... } | count | if (...) ... |
5+
| test.cpp:171:3:173:3 | while (...) ... | test.cpp:171:10:171:43 | ... != ... | 0 | | { ... } | 0 | return ... |
6+
| test.cpp:251:2:255:2 | while (...) ... | test.cpp:251:9:251:12 | loop | 1 | loop | { ... } | loop | return ... |
7+
| test.cpp:263:2:267:2 | while (...) ... | test.cpp:263:9:263:20 | ... && ... | 1 | 1 | { ... } | ... && ... | return ... |
8+
| test.cpp:275:2:279:2 | while (...) ... | test.cpp:275:9:275:13 | ! ... | 1 | stop | { ... } | stop | return ... |
9+
| test.cpp:287:2:291:2 | while (...) ... | test.cpp:287:9:287:20 | ... && ... | 1 | loop | { ... } | loop | return ... |
10+
| test.cpp:299:2:303:2 | while (...) ... | test.cpp:299:9:299:20 | ... && ... | 1 | loop | { ... } | ... && ..., loop | return ... |
11+
| test.cpp:311:2:315:2 | while (...) ... | test.cpp:311:9:311:21 | ... \|\| ... | 1 | ... \|\| ... | { ... } | 0 | return ... |
12+
| test.cpp:323:2:328:2 | while (...) ... | test.cpp:323:9:323:17 | ... ? ... : ... | | b, c | { ... } | c | return ... |
13+
| test.cpp:336:2:341:2 | while (...) ... | test.cpp:336:9:336:21 | ... \|\| ... | 1 | b, c | { ... } | c | return ... |
14+
| test.cpp:348:2:351:17 | do (...) ... | test.cpp:351:11:351:15 | 0 | | { ... } | { ... } | { ... } | return ... |
15+
| test.cpp:361:2:364:2 | while (...) ... | test.cpp:361:9:361:21 | ... \|\| ... | 1 | ... \|\| ... | { ... } | 0 | while (...) ... |
16+
| test.cpp:365:2:368:2 | while (...) ... | test.cpp:365:9:365:13 | ! ... | 1 | stop | { ... } | stop | while (...) ... |
17+
| test.cpp:369:2:373:2 | while (...) ... | test.cpp:369:9:369:21 | ... \|\| ... | 1 | b, c | { ... } | c | do (...) ... |
18+
| test.cpp:374:2:376:17 | do (...) ... | test.cpp:376:11:376:15 | 0 | | do (...) ... | { ... } | { ... } | return ... |
19+
| test.cpp:384:2:386:2 | while (...) ... | test.cpp:384:9:384:12 | 1 | 1 | 1 | { ... } | | return ... |
20+
| test.cpp:394:2:396:2 | while (...) ... | test.cpp:394:9:394:21 | ... , ... | | { ... } | { ... } | | |
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import cpp
2+
import LoopConditionsConst
3+
4+
from Loop l, Expr condition
5+
where
6+
l.getCondition() = condition
7+
select
8+
l, condition,
9+
concat(int val | loopEntryConst(condition, val) | val.toString(), ", "),
10+
concat(BasicBlock bb | bb.getASuccessor() = l.getStmt() | bb.toString(), ", "),
11+
concat(l.getStmt().toString(), ", "),
12+
concat(BasicBlock bb | bb.getASuccessor() = l.getFollowingStmt() | bb.toString(), ", "),
13+
concat(l.getFollowingStmt().toString(), ", ")
14+
15+
/*
16+
dump a graph of BasicBlocks
17+
18+
import semmle.code.cpp.controlflow.LocalScopeVariableReachability
19+
20+
from BasicBlock pred
21+
select
22+
pred,
23+
concat(BasicBlock succ |
24+
pred.getASuccessor() = succ |
25+
pred.toString() + " -> " + succ.toString(), ", "),
26+
concat(BasicBlock succ, boolean predSkip, boolean succSkip |
27+
bbSuccessorEntryReachesLoopInvariant(pred, succ, predSkip, succSkip) |
28+
pred.toString() + " (" + predSkip.toString() + ") -> " + succ.toString() + " (" + succSkip.toString() + ")", ", "
29+
)
30+
*/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import cpp
2+
import semmle.code.cpp.controlflow.internal.ConstantExprs
3+
4+
predicate loopEntryConst(Expr condition, int val)
5+
{
6+
exists(LoopEntryConditionEvaluator x, ControlFlowNode loop |
7+
x.isLoopEntry(condition, loop) and
8+
val = x.getValue(condition)
9+
)
10+
}

0 commit comments

Comments
 (0)