diff --git a/server/ql/java/tools/src/PrintCFG/PrintCFG.ql b/server/ql/java/tools/src/PrintCFG/PrintCFG.ql index 25a254e0..eb78d8c2 100644 --- a/server/ql/java/tools/src/PrintCFG/PrintCFG.ql +++ b/server/ql/java/tools/src/PrintCFG/PrintCFG.ql @@ -10,13 +10,26 @@ import java import semmle.code.java.ControlFlowGraph /** - * Configuration for PrintCFG that outputs all CFG nodes and edges. + * Holds if the node is an exit-related CFG node. + * These nodes are excluded from the output because their ordering + * is non-deterministic across CodeQL CLI versions. + */ +private predicate isExitNode(ControlFlow::Node node) { + node.toString().matches("%Exit") +} + +/** + * Configuration for PrintCFG that outputs all CFG nodes and edges, + * excluding exit nodes for deterministic output. */ query predicate nodes(ControlFlow::Node node, string property, string value) { property = "semmle.label" and - value = node.toString() + value = node.toString() and + not isExitNode(node) } query predicate edges(ControlFlow::Node pred, ControlFlow::Node succ) { - pred.getASuccessor() = succ + pred.getASuccessor() = succ and + not isExitNode(pred) and + not isExitNode(succ) } diff --git a/server/ql/java/tools/test/PrintCFG/PrintCFG.expected b/server/ql/java/tools/test/PrintCFG/PrintCFG.expected index 1b494b3a..4692867a 100644 --- a/server/ql/java/tools/test/PrintCFG/PrintCFG.expected +++ b/server/ql/java/tools/test/PrintCFG/PrintCFG.expected @@ -3,7 +3,6 @@ Example1.java: #-----| -> super(...) # 3| super(...) -#-----| -> Normal Exit # 5| { ... } #-----| -> if (...) @@ -48,7 +47,6 @@ Example1.java: #-----| -> 1 # 20| return ... -#-----| -> Normal Exit # 23| { ... } #-----| -> ; @@ -60,19 +58,16 @@ Example1.java: #-----| -> 0 # 29| return ... -#-----| -> Normal Exit # 30| case ... #-----| -> 1 # 31| return ... -#-----| -> Normal Exit # 32| default #-----| -> value # 33| return ... -#-----| -> Normal Exit # 6| ... > ... #-----| -> { ... } @@ -110,7 +105,6 @@ Example1.java: # 12| ... < ... #-----| -> { ... } -#-----| -> Normal Exit # 12| ...++ #-----| -> i @@ -190,27 +184,3 @@ Example1.java: # 33| 2 #-----| -> ... * ... - -# 3| Exceptional Exit -#-----| -> Exit - -# 3| Normal Exit -#-----| -> Exit - -# 5| Exceptional Exit -#-----| -> Exit - -# 5| Normal Exit -#-----| -> Exit - -# 18| Exceptional Exit -#-----| -> Exit - -# 18| Normal Exit -#-----| -> Exit - -# 3| Exit - -# 5| Exit - -# 18| Exit