Skip to content

Commit e5a9b2b

Browse files
committed
Java: Adjust BasicBlock-based qltests.
1 parent 410013e commit e5a9b2b

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import java
2+
import codeql.util.Boolean
3+
4+
private predicate entryOrExit(ControlFlowNode n) {
5+
n instanceof ControlFlow::EntryNode or
6+
n instanceof ControlFlow::AnnotatedExitNode or
7+
n instanceof ControlFlow::ExitNode
8+
}
9+
10+
ControlFlowNode getFirstAstNode(BasicBlock bb) { result = getFirstAstNode(bb, false) }
11+
12+
ControlFlowNode getFirstAstNodeOrSynth(BasicBlock bb) { result = getFirstAstNode(bb, true) }
13+
14+
private ControlFlowNode getFirstAstNode(BasicBlock bb, Boolean allowSynthetic) {
15+
result =
16+
min(ControlFlowNode n, int i, int astOrder |
17+
bb.getNode(i) = n and
18+
if n.injects(_)
19+
then astOrder = 0
20+
else
21+
if entryOrExit(n)
22+
then astOrder = 1
23+
else (
24+
allowSynthetic = true and astOrder = 2
25+
)
26+
|
27+
n order by astOrder, i
28+
)
29+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import java
22
import semmle.code.java.controlflow.Dominance
3+
import utils.test.BasicBlock
34

45
from BasicBlock b, BasicBlock b2
56
where b.strictlyDominates(b2)
6-
select b, b2
7+
select getFirstAstNode(b), getFirstAstNode(b2)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import java
2+
import utils.test.BasicBlock
23

34
from BasicBlock b, BasicBlock b2
45
where b.getASuccessor() = b2
5-
select b, b2
6+
select getFirstAstNodeOrSynth(b), getFirstAstNodeOrSynth(b2)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import java
22
import semmle.code.java.controlflow.Guards
3+
import utils.test.BasicBlock
34

45
from ConditionBlock cb, boolean testIsTrue, BasicBlock controlled
56
where
67
cb.controls(controlled, testIsTrue) and
78
cb.getEnclosingCallable().getDeclaringType().hasName("Test")
8-
select cb.getCondition(), testIsTrue, controlled
9+
select cb.getCondition(), testIsTrue, getFirstAstNode(controlled)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import java
22
import semmle.code.java.controlflow.Guards
3+
import utils.test.BasicBlock
34

45
from Guard g, BasicBlock bb, GuardValue gv
56
where
67
g.valueControls(bb, gv) and
78
g.getEnclosingCallable().getDeclaringType().hasName("Logic") and
89
(exists(gv.asBooleanValue()) or gv.isThrowsException() or gv.getDualValue().isThrowsException())
9-
select g, gv, bb
10+
select g, gv, getFirstAstNode(bb)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import java
22
import semmle.code.java.controlflow.Guards
3+
import utils.test.BasicBlock
34

45
from Guard g, BasicBlock bb, GuardValue gv
56
where
67
g.valueControls(bb, gv) and
78
g.getEnclosingCallable().getDeclaringType().hasName("Preconditions") and
89
(gv.isThrowsException() or gv.getDualValue().isThrowsException())
9-
select g, gv, bb
10+
select g, gv, getFirstAstNode(bb)

0 commit comments

Comments
 (0)