Skip to content

Commit b69e7c6

Browse files
authored
Exclude exit nodes from Java PrintCFG query for deterministic test output (#23)
1 parent 2c48986 commit b69e7c6

File tree

2 files changed

+16
-33
lines changed

2 files changed

+16
-33
lines changed

server/ql/java/tools/src/PrintCFG/PrintCFG.ql

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,26 @@ import java
1010
import semmle.code.java.ControlFlowGraph
1111

1212
/**
13-
* Configuration for PrintCFG that outputs all CFG nodes and edges.
13+
* Holds if the node is an exit-related CFG node.
14+
* These nodes are excluded from the output because their ordering
15+
* is non-deterministic across CodeQL CLI versions.
16+
*/
17+
private predicate isExitNode(ControlFlow::Node node) {
18+
node.toString().matches("%Exit")
19+
}
20+
21+
/**
22+
* Configuration for PrintCFG that outputs all CFG nodes and edges,
23+
* excluding exit nodes for deterministic output.
1424
*/
1525
query predicate nodes(ControlFlow::Node node, string property, string value) {
1626
property = "semmle.label" and
17-
value = node.toString()
27+
value = node.toString() and
28+
not isExitNode(node)
1829
}
1930

2031
query predicate edges(ControlFlow::Node pred, ControlFlow::Node succ) {
21-
pred.getASuccessor() = succ
32+
pred.getASuccessor() = succ and
33+
not isExitNode(pred) and
34+
not isExitNode(succ)
2235
}

server/ql/java/tools/test/PrintCFG/PrintCFG.expected

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Example1.java:
33
#-----| -> super(...)
44

55
# 3| super(...)
6-
#-----| -> Normal Exit
76

87
# 5| { ... }
98
#-----| -> if (...)
@@ -48,7 +47,6 @@ Example1.java:
4847
#-----| -> 1
4948

5049
# 20| return ...
51-
#-----| -> Normal Exit
5250

5351
# 23| { ... }
5452
#-----| -> <Expr>;
@@ -60,19 +58,16 @@ Example1.java:
6058
#-----| -> 0
6159

6260
# 29| return ...
63-
#-----| -> Normal Exit
6461

6562
# 30| case ...
6663
#-----| -> 1
6764

6865
# 31| return ...
69-
#-----| -> Normal Exit
7066

7167
# 32| default
7268
#-----| -> value
7369

7470
# 33| return ...
75-
#-----| -> Normal Exit
7671

7772
# 6| ... > ...
7873
#-----| -> { ... }
@@ -110,7 +105,6 @@ Example1.java:
110105

111106
# 12| ... < ...
112107
#-----| -> { ... }
113-
#-----| -> Normal Exit
114108

115109
# 12| ...++
116110
#-----| -> i
@@ -190,27 +184,3 @@ Example1.java:
190184

191185
# 33| 2
192186
#-----| -> ... * ...
193-
194-
# 3| Exceptional Exit
195-
#-----| -> Exit
196-
197-
# 3| Normal Exit
198-
#-----| -> Exit
199-
200-
# 5| Exceptional Exit
201-
#-----| -> Exit
202-
203-
# 5| Normal Exit
204-
#-----| -> Exit
205-
206-
# 18| Exceptional Exit
207-
#-----| -> Exit
208-
209-
# 18| Normal Exit
210-
#-----| -> Exit
211-
212-
# 3| Exit
213-
214-
# 5| Exit
215-
216-
# 18| Exit

0 commit comments

Comments
 (0)