Skip to content

Commit bd114db

Browse files
committed
Java: Add cfg edges for instanceof-pattern.
1 parent 6041d52 commit bd114db

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

java/ql/src/semmle/code/java/ControlFlowGraph.qll

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ private module ControlFlowGraphImpl {
405405
* Expressions and statements with CFG edges in post-order AST traversal.
406406
*
407407
* This includes most expressions, except those that initiate or propagate branching control
408-
* flow (`LogicExpr`, `ConditionalExpr`), and parentheses, which aren't in the CFG.
408+
* flow (`LogicExpr`, `ConditionalExpr`).
409409
* Only a few statements are included; those with specific side-effects
410410
* occurring after the evaluation of their children, that is, `Call`, `ReturnStmt`,
411411
* and `ThrowStmt`. CFG nodes without child nodes in the CFG that may complete
@@ -429,9 +429,10 @@ private module ControlFlowGraphImpl {
429429
or
430430
this instanceof CastExpr
431431
or
432-
this instanceof InstanceOfExpr
432+
this instanceof InstanceOfExpr and not this.(InstanceOfExpr).isPattern()
433433
or
434-
this instanceof LocalVariableDeclExpr
434+
this instanceof LocalVariableDeclExpr and
435+
not this = any(InstanceOfExpr ioe).getLocalVariableDeclExpr()
435436
or
436437
this instanceof RValue
437438
or
@@ -573,6 +574,8 @@ private module ControlFlowGraphImpl {
573574
or
574575
result = first(n.(PostOrderNode).firstChild())
575576
or
577+
result = first(n.(InstanceOfExpr).getExpr())
578+
or
576579
result = first(n.(SynchronizedStmt).getExpr())
577580
or
578581
result = n and
@@ -707,6 +710,11 @@ private module ControlFlowGraphImpl {
707710
last(condexpr.getTrueExpr(), last, completion)
708711
)
709712
or
713+
exists(InstanceOfExpr ioe | ioe.isPattern() and ioe = n |
714+
last = n and completion = basicBooleanCompletion(false) or
715+
last = ioe.getLocalVariableDeclExpr() and completion = basicBooleanCompletion(true)
716+
)
717+
or
710718
// The last node of a node executed in post-order is the node itself.
711719
n.(PostOrderNode).mayCompleteNormally() and last = n and completion = NormalCompletion()
712720
or
@@ -916,6 +924,14 @@ private module ControlFlowGraphImpl {
916924
result = first(e.getFalseExpr())
917925
)
918926
or
927+
exists(InstanceOfExpr ioe | ioe.isPattern() |
928+
last(ioe.getExpr(), n, completion) and completion = NormalCompletion() and result = ioe
929+
or
930+
n = ioe and
931+
result = ioe.getLocalVariableDeclExpr() and
932+
completion = basicBooleanCompletion(true)
933+
)
934+
or
919935
// In other expressions control flows from left to right and ends in the node itself.
920936
exists(PostOrderNode p, int i |
921937
last(p.getChildNode(i), n, completion) and completion = NormalCompletion()

0 commit comments

Comments
 (0)